#------------------------------------------------------------------------------------#
# Include source files
#------------------------------------------------------------------------------------#

source /home/ventana/source/submenu/analog_input_list.tcl
source /home/ventana/source/submenu/analog_output_list.tcl

#------------------------------------------------------------------------------------#
# Initialize and set variable
#------------------------------------------------------------------------------------#

set cam .camera_popup
set cam_timer 0
set cam_string ""
set old_cam_string ""


#------------------------------------------------------------------------------------#
# Default channels and pid values when nothing are set
#------------------------------------------------------------------------------------#

set cam_shoulder_sine "Analog Input 15"
set cam_shoulder_cosine "Analog Input 16"
set cam_shoulder_offset 0
set cam_shoulder_command "Analog Input 7"
set cam_shoulder_master_value 0
set cam_shoulder_fb_value 0
set cam_shoulder_servo "Analog Output 8"
set cam_p_shoulder 1
set cam_i_shoulder 0
set cam_d_shoulder 0

set cam_pan_sine "Analog Input 11"
set cam_pan_cosine "Analog Input 12"
set cam_pan_offset 0
set cam_pan_command "Analog Input 5"
set cam_pan_master_value 0
set cam_pan_fb_value 0
set cam_pan_servo "Analog Output 6"
set cam_p_pan 1
set cam_i_pan 0
set cam_d_pan 0

set cam_tilt_sine "Analog Input 13"
set cam_tilt_cosine "Analog Input 14"
set cam_tilt_offset 0
set cam_tilt_command "Analog Input 6"
set cam_tilt_master_value 0
set cam_tilt_fb_value 0
set cam_tilt_servo "Analog Output 7"
set cam_p_tilt 1
set cam_i_tilt 0
set cam_d_tilt 0

set cam_time_constant [get_cam_time_constant]

#------------------------------------------------------------------------------------#
# This procedure create camera control display on the second screen
#------------------------------------------------------------------------------------#
	
proc camera_popup { } {

    global cam
    global cam_timer

    if [winfo exists $cam] {
destroy $cam
}

    global env
    set env(DISPLAY) :0
    toplevel $cam -width 32c -height 15c
    wm title $cam "Camera Control"

    label $cam.labcamtitle \
        -foreground #0000b0 -height 0 -relief ridge -text {Cam Control} \
        -width 511
    button $cam.butok -width 5 -height 3 \
        -command {set cam_timer 0; send_down_camera; destroy $cam} -text OK 
    label $cam.labshoulder \
        -text Shoulder
    label $cam.labpan \
        -text Pan
    label $cam.labtilt \
        -text Tilt

    #------------------------------------------------------------------------------------#
    # SHOULDER
    #------------------------------------------------------------------------------------#
    
    frame $cam.shoulder_frame \
        -borderwidth 2 -height 95 -relief groove -width 680
    label $cam.shoulder_frame.labsine \
        -text Sine
    label $cam.shoulder_frame.labcosine \
        -text Cosine
    label $cam.shoulder_frame.laboffset \
        -text Offset
    entry $cam.shoulder_frame.entsine \
        -background white -textvariable cam_shoulder_sine -width 13 -state disabled
    entry $cam.shoulder_frame.entcosine \
        -background white -textvariable cam_shoulder_cosine -width 13 -state disabled
    entry $cam.shoulder_frame.entoffset \
        -background white -textvariable cam_shoulder_offset -width 13

    

    label $cam.shoulder_frame.labcommand \
        -text Command
    label $cam.shoulder_frame.labmaster \
        -text Master
    label $cam.shoulder_frame.labfeedback \
        -text FeedBack
    entry $cam.shoulder_frame.entcommand \
        -background white -textvariable cam_shoulder_command -width 13 -state disabled
    entry $cam.shoulder_frame.entmaster \
        -background #d9d9d9 -textvariable cam_shoulder_master_value -width 13
    entry $cam.shoulder_frame.entfeedback \
        -background #d9d9d9 -textvariable cam_shoulder_fb_value -width 13

    label $cam.shoulder_frame.labservo \
        -text Servo
    entry $cam.shoulder_frame.entservo \
        -background white -textvariable cam_shoulder_servo -width 14 -state disabled
    label $cam.shoulder_frame.labtimeconst \
        -text "Time Const"
    label $cam.shoulder_frame.labtimeconstunits \
        -text "X 20mSec"
    entry $cam.shoulder_frame.enttimeconst \
        -background white -textvariable cam_time_constant -width 10

    label $cam.shoulder_frame.plabel \
        -text P
    label $cam.shoulder_frame.ilabel \
        -text I
    label $cam.shoulder_frame.dlabel \
        -text D
    entry $cam.shoulder_frame.entp \
        -background white -textvariable cam_p_shoulder -width 5
    entry $cam.shoulder_frame.enti \
        -background white -textvariable cam_i_shoulder -width 5
    entry $cam.shoulder_frame.entd \
        -background white -textvariable cam_d_shoulder -width 5

    
    button $cam.shoulder_frame.butsine \
        -command { analog_input_list $cam.shoulder_frame.entsine } \
        -height 21 -text v -width 27
    button $cam.shoulder_frame.butcosine \
        -command { analog_input_list $cam.shoulder_frame.entcosine } \
        -height 21 -text v -width 27
    button $cam.shoulder_frame.butcommand \
        -command { surf_analog_input_list $cam.shoulder_frame.entcommand } \
        -height 21 -text v -width 27
    button $cam.shoulder_frame.butservo \
        -command { analog_output_list $cam.shoulder_frame.entservo } \
        -height 21 -text v -width 27

    #------------------------------------------------------------------------------------#
    # PAN
    #------------------------------------------------------------------------------------#

    frame $cam.pan_frame \
        -borderwidth 2 -height 95 -relief groove -width 680
    label $cam.pan_frame.labsine \
        -text Sine
    label $cam.pan_frame.labcosine \
        -text Cosine
    label $cam.pan_frame.laboffset \
        -text Offset
    entry $cam.pan_frame.entsine \
        -background white -textvariable cam_pan_sine -width 13 -state disabled
    entry $cam.pan_frame.entcosine \
        -background white -textvariable cam_pan_cosine -width 13 -state disabled
    entry $cam.pan_frame.entoffset \
        -background white -textvariable cam_pan_offset -width 13

    
    label $cam.pan_frame.labcommand \
        -text Command
    label $cam.pan_frame.labmaster \
        -text Master
    label $cam.pan_frame.labfeedback \
        -text Feedback
    entry $cam.pan_frame.entcommand \
        -background white -textvariable cam_pan_command -width 13 -state disabled
    entry $cam.pan_frame.entmaster \
        -background #d9d9d9 -textvariable cam_pan_master_value -width 13
    entry $cam.pan_frame.entfeedback \
        -background #d9d9d9 -textvariable cam_pan_fb_value -width 13

    label $cam.pan_frame.labservo \
        -text Servo
    entry $cam.pan_frame.entservo \
        -background white -textvariable cam_pan_servo -width 14 -state disabled

    label $cam.pan_frame.plabel \
        -text P
    label $cam.pan_frame.ilabel \
        -text I
    label $cam.pan_frame.dlabel \
        -text D
    entry $cam.pan_frame.entp \
        -background white -textvariable cam_p_pan -width 5
    entry $cam.pan_frame.enti \
        -background white -textvariable cam_i_pan -width 5
    entry $cam.pan_frame.entd \
        -background white -textvariable cam_d_pan -width 5


    button $cam.pan_frame.butsine \
        -command { analog_input_list $cam.pan_frame.entsine } \
        -height 21 -text v -width 27
    button $cam.pan_frame.butcosine \
        -command { analog_input_list $cam.pan_frame.entcosine } \
        -height 21 -text v -width 27
    button $cam.pan_frame.butcommand \
        -command { surf_analog_input_list $cam.pan_frame.entcommand } \
        -height 21 -text v -width 27
    button $cam.pan_frame.butservo \
        -command { analog_output_list $cam.pan_frame.entservo } \
        -height 21 -text v -width 27

    #------------------------------------------------------------------------------------#
    # TILT
    #------------------------------------------------------------------------------------#

    frame $cam.tilt_frame \
        -borderwidth 2 -height 95 -relief groove -width 680
    label $cam.tilt_frame.labsine \
        -text Sine
    label $cam.tilt_frame.labcosine \
        -text Cosine
    label $cam.tilt_frame.laboffset \
        -text Offset
    entry $cam.tilt_frame.entsine \
        -background white -textvariable cam_tilt_sine -width 13 -state disabled
    entry $cam.tilt_frame.entcosine \
        -background white -textvariable cam_tilt_cosine -width 13 -state disabled
    entry $cam.tilt_frame.entoffset \
        -background white -textvariable cam_tilt_offset -width 13

    
    label $cam.tilt_frame.labcommand \
        -text Command
    label $cam.tilt_frame.labmaster \
         -text Master
    label $cam.tilt_frame.labfeedback \
         -text Feedback
    entry $cam.tilt_frame.entcommand \
        -background white -textvariable cam_tilt_command -width 13 -state disabled
    entry $cam.tilt_frame.entmaster \
        -background #d9d9d9 -textvariable cam_tilt_master_value -width 13
    entry $cam.tilt_frame.entfeedback \
        -background #d9d9d9 -textvariable cam_tilt_fb_value -width 13

    label $cam.tilt_frame.labservo \
        -text Servo
    entry $cam.tilt_frame.entservo \
        -background white -textvariable cam_tilt_servo -width 14 -state disabled

    label $cam.tilt_frame.plabel \
        -text P
    label $cam.tilt_frame.ilabel \
        -text I
    label $cam.tilt_frame.dlabel \
        -text D
    entry $cam.tilt_frame.entp \
        -background white -textvariable cam_p_tilt -width 5
    entry $cam.tilt_frame.enti \
        -background white -textvariable cam_i_tilt -width 5
    entry $cam.tilt_frame.entd \
        -background white -textvariable cam_d_tilt -width 5


    button $cam.tilt_frame.butsine \
        -command { analog_input_list $cam.tilt_frame.entsine } \
        -height 21 -text v -width 27
    button $cam.tilt_frame.butcosine \
        -command { analog_input_list $cam.tilt_frame.entcosine } \
        -height 21 -text v -width 27
    button $cam.tilt_frame.butcommand \
        -command { surf_analog_input_list $cam.tilt_frame.entcommand } \
        -height 21 -text v -width 27
    button $cam.tilt_frame.butservo \
        -command { analog_output_list $cam.tilt_frame.entservo } \
        -height 21 -text v -width 27

 
	#------------------------------------------------------------------------------------#
	# SETTING GEOMETRY
	#------------------------------------------------------------------------------------#

    	place $cam.labcamtitle -x 10 -y 10 -width 760 -height 20 
	place $cam.shoulder_frame -x 80 -y 60 
	place $cam.pan_frame -x 80 -y 160
	place $cam.tilt_frame -x 80 -y 260
	place $cam.labshoulder -x 5 -y 80
	place $cam.labpan -x 5 -y 180 
	place $cam.labtilt -x 5 -y 280 


    #------------------------------------------------------------------------------------#
    # SHOULDER
    #------------------------------------------------------------------------------------#

    #------------------------------------------------------------------------------------#
    # Shoulder COLUMN 1
    #------------------------------------------------------------------------------------#

    place $cam.shoulder_frame.labsine \
        -x 15 -y 10 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.labcosine \
        -x 5 -y 35 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.laboffset \
        -x 5 -y 60 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.entsine \
        -x 55 -y 10 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.entcosine \
        -x 55 -y 35 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.entoffset \
        -x 55 -y 60 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.butsine \
        -x 155 -y 10 -width 27 -height 21 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.butcosine \
        -x 155 -y 35 -width 27 -height 21 -anchor nw -bordermode ignore

    #------------------------------------------------------------------------------------#
    # Shoulder COLUMN 2
    #------------------------------------------------------------------------------------#

    place $cam.shoulder_frame.labcommand \
        -x 190 -y 10 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.entcommand \
        -x 255 -y 10 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.labmaster \
        -x 200 -y 35 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.entmaster \
        -x 255 -y 35 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.labfeedback \
        -x 190 -y 60 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.entfeedback \
        -x 255 -y 60 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.butcommand \
        -x 355 -y 10 -width 27 -height 21 -anchor nw -bordermode ignore

    #------------------------------------------------------------------------------------#
    # Shoulder COLUMN 3
    #------------------------------------------------------------------------------------#

    place $cam.shoulder_frame.labservo \
        -x 400 -y 10 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.entservo \
        -x 445 -y 10 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.butservo \
        -x 545 -y 10 -width 27 -height 21 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.labtimeconst \
        -x 370 -y 60 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.labtimeconstunits \
        -x 520 -y 60 -anchor nw -bordermode ignore
    place $cam.shoulder_frame.enttimeconst \
        -x 445 -y 60 -anchor nw -bordermode ignore

    #------------------------------------------------------------------------------------#
    # Shoulder COLUMN 4
    #------------------------------------------------------------------------------------#

    place $cam.shoulder_frame.plabel \
        -x 600 -y 10
    place $cam.shoulder_frame.ilabel \
        -x 600 -y 35
    place $cam.shoulder_frame.dlabel \
        -x 600 -y 60
    place $cam.shoulder_frame.entp \
        -x 620 -y 10
    place $cam.shoulder_frame.enti \
        -x 620 -y 35
    place $cam.shoulder_frame.entd \
        -x 620 -y 60


    #------------------------------------------------------------------------------------#
    # PAN
    #------------------------------------------------------------------------------------#

     #------------------------------------------------------------------------------------#
    # Pan COLUMN 1
    #------------------------------------------------------------------------------------#

    place $cam.pan_frame.labsine \
        -x 15 -y 10 -anchor nw -bordermode ignore
    place $cam.pan_frame.labcosine \
        -x 5 -y 35 -anchor nw -bordermode ignore
    place $cam.pan_frame.laboffset \
        -x 5 -y 60 -anchor nw -bordermode ignore
    place $cam.pan_frame.entsine \
        -x 55 -y 10 -anchor nw -bordermode ignore
    place $cam.pan_frame.entcosine \
        -x 55 -y 35 -anchor nw -bordermode ignore
    place $cam.pan_frame.entoffset \
        -x 55 -y 60 -anchor nw -bordermode ignore
    place $cam.pan_frame.butsine \
        -x 155 -y 10 -width 27 -height 21 -anchor nw -bordermode ignore
    place $cam.pan_frame.butcosine \
        -x 155 -y 35 -width 27 -height 21 -anchor nw -bordermode ignore

    #------------------------------------------------------------------------------------#
    # Pan COLUMN 2
    #------------------------------------------------------------------------------------#

    place $cam.pan_frame.labcommand \
        -x 190 -y 10 -anchor nw -bordermode ignore
    place $cam.pan_frame.entcommand \
        -x 255 -y 10 -anchor nw -bordermode ignore
    place $cam.pan_frame.labmaster \
        -x 200 -y 35 -anchor nw -bordermode ignore
    place $cam.pan_frame.entmaster \
        -x 255 -y 35 -anchor nw -bordermode ignore
    place $cam.pan_frame.labfeedback \
        -x 190 -y 60 -anchor nw -bordermode ignore
    place $cam.pan_frame.entfeedback \
        -x 255 -y 60 -anchor nw -bordermode ignore
    place $cam.pan_frame.butcommand \
        -x 355 -y 10 -width 27 -height 21 -anchor nw -bordermode ignore

    #------------------------------------------------------------------------------------#
    # Pan COLUMN 3
    #------------------------------------------------------------------------------------#

    place $cam.pan_frame.labservo \
        -x 400 -y 10 -anchor nw -bordermode ignore
    place $cam.pan_frame.entservo \
        -x 445 -y 10 -anchor nw -bordermode ignore
    place $cam.pan_frame.butservo \
        -x 545 -y 10 -width 27 -height 21 -anchor nw -bordermode ignore

    #------------------------------------------------------------------------------------#
    # Pan COLUMN 4
    #------------------------------------------------------------------------------------#

    place $cam.pan_frame.plabel \
        -x 600 -y 10
    place $cam.pan_frame.ilabel \
        -x 600 -y 35
    place $cam.pan_frame.dlabel \
        -x 600 -y 60
    place $cam.pan_frame.entp \
        -x 620 -y 10
    place $cam.pan_frame.enti \
        -x 620 -y 35
    place $cam.pan_frame.entd \
        -x 620 -y 60


    #------------------------------------------------------------------------------------#    # TILT
    #------------------------------------------------------------------------------------#

    #------------------------------------------------------------------------------------#
    # Tilt COLUMN 1
    #------------------------------------------------------------------------------------#

    place $cam.tilt_frame.labsine \
        -x 15 -y 10 -anchor nw -bordermode ignore
    place $cam.tilt_frame.labcosine \
        -x 5 -y 35 -anchor nw -bordermode ignore
    place $cam.tilt_frame.laboffset \
        -x 5 -y 60 -anchor nw -bordermode ignore
    place $cam.tilt_frame.entsine \
        -x 55 -y 10 -anchor nw -bordermode ignore
    place $cam.tilt_frame.entcosine \
        -x 55 -y 35 -anchor nw -bordermode ignore
    place $cam.tilt_frame.entoffset \
        -x 55 -y 60 -anchor nw -bordermode ignore
    place $cam.tilt_frame.butsine \
        -x 155 -y 10 -width 27 -height 21 -anchor nw -bordermode ignore
    place $cam.tilt_frame.butcosine \
        -x 155 -y 35 -width 27 -height 21 -anchor nw -bordermode ignore

    #------------------------------------------------------------------------------------#
    # Tilt COLUMN 2
    #------------------------------------------------------------------------------------#

    place $cam.tilt_frame.labcommand \
        -x 190 -y 10 -anchor nw -bordermode ignore
    place $cam.tilt_frame.entcommand \
        -x 255 -y 10 -anchor nw -bordermode ignore
    place $cam.tilt_frame.labmaster \
        -x 200 -y 35 -anchor nw -bordermode ignore
    place $cam.tilt_frame.entmaster \
        -x 255 -y 35 -anchor nw -bordermode ignore
    place $cam.tilt_frame.labfeedback \
        -x 190 -y 60 -anchor nw -bordermode ignore
    place $cam.tilt_frame.entfeedback \
        -x 255 -y 60 -anchor nw -bordermode ignore
    place $cam.tilt_frame.butcommand \
        -x 355 -y 10 -width 27 -height 21 -anchor nw -bordermode ignore

    #------------------------------------------------------------------------------------#
    # Tilt COLUMN 3
    #------------------------------------------------------------------------------------#

    place $cam.tilt_frame.labservo \
        -x 400 -y 10 -anchor nw -bordermode ignore
    place $cam.tilt_frame.entservo \
        -x 445 -y 10 -anchor nw -bordermode ignore
    place $cam.tilt_frame.butservo \
        -x 545 -y 10 -width 27 -height 21 -anchor nw -bordermode ignore

    #------------------------------------------------------------------------------------#
    # Tilt COLUMN 4
    #------------------------------------------------------------------------------------#

    place $cam.tilt_frame.plabel \
        -x 600 -y 10
    place $cam.tilt_frame.ilabel \
        -x 600 -y 35
    place $cam.tilt_frame.dlabel \
        -x 600 -y 60
    place $cam.tilt_frame.entp \
        -x 620 -y 10
    place $cam.tilt_frame.enti \
        -x 620 -y 35
    place $cam.tilt_frame.entd \
        -x 620 -y 60
    place $cam.butok -x 350 -y 370 


	#------------------------------------------------------------------------------------#
	# BINDING
	#------------------------------------------------------------------------------------#
	
	#------------------------------------------------------------------------------------#
	# Shoulder
	#------------------------------------------------------------------------------------#
	
	bind $cam.shoulder_frame.entp <Return> {send_down_camera}
	bind $cam.shoulder_frame.enti <Return> {send_down_camera}
	bind $cam.shoulder_frame.entd <Return> {send_down_camera}
	bind $cam.shoulder_frame.entoffset <Return> { send_down_camera }
	bind $cam.shoulder_frame.enttimeconst <Return> { send_down_camera }
	
	#------------------------------------------------------------------------------------#
	# Pan
	#------------------------------------------------------------------------------------#
	
	
	bind $cam.pan_frame.entp <Return> {send_down_camera}
	bind $cam.pan_frame.enti <Return> {send_down_camera}
	bind $cam.pan_frame.entd <Return> {send_down_camera}
	bind $cam.pan_frame.entoffset <Return> { send_down_camera }
	
	#------------------------------------------------------------------------------------#
	# Tilt
	#------------------------------------------------------------------------------------#
	
	bind $cam.tilt_frame.entp <Return> {send_down_camera}
	bind $cam.tilt_frame.enti <Return> {send_down_camera}
	bind $cam.tilt_frame.entd <Return> {send_down_camera}
	bind $cam.tilt_frame.entoffset <Return> { send_down_camera }
	
	#------------------------------------------------------------------------------------#
	# Loop to update master and feedback value
	#------------------------------------------------------------------------------------#
	
	set cam_timer 1
	loop_master_feedback_cam

	


# end of proc "cam_control_popup"
}




#------------------------------------------------------------------------------------#
# Loop to update master and feedback value
#------------------------------------------------------------------------------------#
	
proc loop_master_feedback_cam { } {

	global cam cam_timer
	global cam_shoulder_master_value cam_shoulder_fb_value
	global cam_pan_master_value cam_pan_fb_value
	global cam_tilt_master_value cam_tilt_fb_value
	set temp 0
	
	if { ![winfo exists $cam] || $cam_timer == 0} {return}
	
	#puts "camera_popup.tcl: updating camera master and feedback "
	
	set mf [ret_camera_string]
	#puts "camera_popup.tcl : mf is $mf"
	set mf_list [ split $mf | ]
	

	set cam_shoulder_master_value [expr ([lindex $mf_list 0] - 180) ]
	set cam_shoulder_fb_value [lindex $mf_list 1]
	set cam_pan_master_value [expr ([lindex $mf_list 2] - 180) ]
 	set cam_pan_fb_value [lindex $mf_list 3]
 	set cam_tilt_master_value [expr ([lindex $mf_list 4] - 180) ]
	set cam_tilt_fb_value [lindex $mf_list 5]
	
	
	
	after 500 [list loop_master_feedback_cam]
}


#------------------------------------------------------------------------------------#
# This procedure will set the new variables and send them down to the sub
#------------------------------------------------------------------------------------#

proc send_down_camera { } {

	global cam cam_string old_cam_string cam_timer
	global cam_shoulder_sine cam_shoulder_cosine cam_shoulder_offset cam_shoulder_command cam_shoulder_master_value cam_shoulder_fb_value cam_shoulder_servo cam_p_shoulder cam_i_shoulder cam_d_shoulder
	global cam_pan_sine cam_pan_cosine cam_pan_offset cam_pan_command cam_pan_master_value cam_pan_fb_value cam_pan_servo cam_p_pan cam_i_pan cam_d_pan
	global cam_tilt_sine cam_tilt_cosine cam_tilt_offset cam_tilt_command cam_tilt_master_value cam_tilt_fb_value cam_tilt_servo cam_p_tilt cam_i_tilt cam_d_tilt
	global cam_time_constant
	
	set cam_shoulder_master_value 0
	set cam_shoulder_fb_value 0
	set cam_pan_master_value 0
	set cam_pan_fb_value 0
	set cam_tilt_master_value 0
	set cam_tilt_fb_value 0
	
	set a1 [lindex $cam_shoulder_sine 2]
	set a2 [lindex $cam_shoulder_cosine 2]
	set a3 [lindex $cam_shoulder_command 2]
	set a4 [lindex $cam_shoulder_servo 2]
	
	set b1 [lindex $cam_pan_sine 2]
	set b2 [lindex $cam_pan_cosine 2]
	set b3 [lindex $cam_pan_command 2]
	set b4 [lindex $cam_pan_servo 2]

	set c1 [lindex $cam_tilt_sine 2]
	set c2 [lindex $cam_tilt_cosine 2]
	set c3 [lindex $cam_tilt_command 2]
	set c4 [lindex $cam_tilt_servo 2]
	
	if { $a1 == "" || $a2 == "" || $a3 == "" || $a4 == ""  || $b1 == ""  || $b2 == "" || $b3 == "" \
  	|| $b4 == "" || $c1 == ""  || $c2 == "" ||  $c3 == "" ||  $c4 == "" } {
        		
   		set status [tk_dialog  .cam_warning { } {Some of the fields are empty.  Close the Camera Control window anyway ?} warning 0 {Yes } { No} ]
       		switch $status {   0 {set cam_timer 0; destroy $cam; return }
       				1 {return} }
        		
        		
        	}
        	
        	
   	set cam_string "$a1|$a2|$cam_shoulder_offset|$a3|$cam_shoulder_master_value|$cam_shoulder_fb_value|$a4|$cam_p_shoulder|$cam_i_shoulder|$cam_d_shoulder|$b1|$b2|$cam_pan_offset|$b3|$cam_pan_master_value|$cam_pan_fb_value|$b4|$cam_p_pan|$cam_i_pan|$cam_d_pan|$c1|$c2|$cam_tilt_offset|$c3|$cam_tilt_master_value|$cam_tilt_fb_value|$c4|$cam_p_tilt|$cam_i_tilt|$cam_d_tilt"
	
   	        	
	set old_cam_string  $cam_string
	
	
	#------------------------------------------------------------------------------------#
	# Save the new values needed to be send down in database and to the sub
	#------------------------------------------------------------------------------------#
	
	set_camera  $a1 $a2 $cam_shoulder_offset $a3 $cam_shoulder_master_value $cam_shoulder_fb_value $a4 $cam_p_shoulder $cam_i_shoulder $cam_d_shoulder $b1 $b2 $cam_pan_offset $b3 $cam_pan_master_value $cam_pan_fb_value $b4 $cam_p_pan $cam_i_pan $cam_d_pan $c1 $c2 $cam_tilt_offset $c3 $cam_tilt_master_value $cam_tilt_fb_value $c4 $cam_p_tilt $cam_i_tilt $cam_d_tilt
	send_cam_time_constant $cam_time_constant
	
	#------------------------------------------------------------------------------------#
        # save all the information as a single string so it's easier when we want to 
        # write it to configuration file
        #------------------------------------------------------------------------------------#
	
	saving_cam_string $cam_string
	
	
	
	

	
}		
