#! /bin/tcsh -f # # enable/disable video centroid feedback system # # goto Setup Help: cat << EOF-help usage $0 [start|stop] EOF-help exit 9 Return_from_Setup: set tempfile = /tmp/feedback_tmp$$ if(("$1" == "stay")||("$1" == "keep")) then shutter.com close sleep 2 set Hcen = `blmotor.com Horizontal Centroid | awk '{print $NF}'` set Vcen = `blmotor.com Vertical Centroid | awk '{print $NF}'` set gotbeam = `echo $Hcen $Vcen | awk '{print ($1 != -1 && $2 != -1 )}'` if ( ! $gotbeam ) then echo "cannot see beam on shutter" exit 9 endif echo "enabling feedback system" shutter.com open sleep 1 echo "checking for false beam spots." set samples = 60 while ( $samples > 0 ) @ samples = ( $samples - 1 ) if( $samples % 20 == 0) echo "$samples" blmotor.com Horizontal Centroid | awk '{print " "$NF+0}' | egrep -v ' -1$' if (! $status) break blmotor.com Vertical Centroid | awk '{print " "$NF+0}' | egrep -v ' -1$' if (! $status) break echo -n "." usleep 50000 end echo "" if ( $samples != 0 ) then echo "ERROR: a centroid is visible with shutter open! " exit 9 endif shutter.com close sleep 3 set Hcen = `blmotor.com Horizontal Centroid | awk '{print $NF}'` set Vcen = `blmotor.com Vertical Centroid | awk '{print $NF}'` set gotbeam = `echo $Hcen $Vcen | awk '{print ($1 != -1 && $2 != -1 )}'` if ( ! $gotbeam ) then echo "cannot see beam on shutter" exit 9 else echo "beam is at $Hcen $Vcen" endif #echo "moveto Horizontal Video Control 0\r\nmoveto Vertical Video Control 0\r" | sock_exchange.tcl b${beamline}b 10001 2 echo "keeppos\r" | sock_exchange.tcl $blhost 10001 1 usleep 500000 change.com feedback on $Hcen $Vcen endif if(("$1" == "start")||("$1" == "on")) then #echo "moveto Horizontal Video Control 0\r\nmoveto Vertical Video Control 0\r" | sock_exchange.tcl b${beamline}b 10001 2 echo "feedon\r" | sock_exchange.tcl $blhost 10001 1 change.com feedback on endif if(("$1" == "stop")||("$1" == "off")) then #echo "stop Horizontal Video Control\r\nstop Vertical Video Control\r" | sock_exchange.tcl $blhost 10001 2 echo "feedoff\r" | sock_exchange.tcl $blhost 10001 1 change.com feedback off endif # see what state the feedback is in... set state = `echo "getstat Horizontal Video Control\r\ngetstat Vertical Video Control\r" | sock_exchange.tcl $blhost 10001 2` set state = `echo "feedstat\r" | sock_exchange.tcl $blhost 10001 1` if("$state" =~ *Local*) then set state = "in unknown state" else set state = `echo "$state" | awk '$1+0==1{print "on"} $1+0==0{print "off"}'` endif echo "feedback system is $state" exit Setup: ############################################################# # platform-specific issues set test = `echo "123asdf" | awk '{print $1+0}'` if("$test" != "123") then alias awk nawk set test = `echo "123asdf" | awk '{print $1+0}'` if("$test" != "123") alias awk gawk set test = `echo "123asdf" | awk '{print $1+0}'` if("$test" != "123") then echo "ERROR: awk no good" exit 9 endif endif set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) then alias echo /bin/echo set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) alias echo '/bin/echo -e' set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) alias echo /usr/bin/echo set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) alias echo '/bin/echo \!* | awk '\''/^-n/{printf "%s", substr($0,4) ; exit} {print}'\' set test = `echo -n "\r" |& od -c | wc -w` if("$test" != 3) then echo "ERROR: echo command is broken" exit 9 endif endif set test = `echo "string is digit 1" | /usr/bin/tclsh |& wc -l` if($test != 0) then set test = `echo "string is digit 1" | tclsh |& wc -l` if($test != 0) alias tclsh tclsh8.2 set test = `echo "string is digit 1" | tclsh |& wc -l` if($test != 0) alias tclsh tclsh8.3 set test = `echo "string is digit 1" | tclsh |& wc -l` if($test != 0) then setenv LD_LIBRARY_PATH ~jamesh alias tclsh ~jamesh/tclsh8.2 echo "" | tclsh >& /dev/null if("$status") then echo "ERROR: tclsh not available" exit 9 endif endif alias sock_exchange.tcl "tclsh `which sock_exchange.tcl` \!*" endif ###################################################################### if(! $?beamline) then # default to beamline this computer belongs to setenv beamline `beamline.com` if($status) then echo "ERROR: $beamline" exit 9 endif endif #if(! $?beamline) setenv beamline 831 set blhost = beamline if("$beamline" =~ 82*) set blhost = bl${beamline}b #if("$1" == "") goto Help goto Return_from_Setup