#! /bin/tcsh -f # # operate the X-Y picomotor backstop stage # # moves are in the "lab" frame: +x=left +y=up # 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 # scale measurements # v -0.24mm in 30000 cts # v 0.18mm in -30000 cts # h -0.59mm in 30000 cts # h 0.63mm in -30000 cts set vscale = -143000 set hscale = -50000 if("$beamline" == 1231) then set hscale = 1 set vscale = 1 endif # on detector (at 600mm) # +0.05h -> set pmac = pmac2 if("$beamline" != 831) set pmac = bl${beamline} set control = bl${beamline}c set tempfile = /tmp/beamstop_temp$$ # default to a relative move set relative # interpret command line first foreach arg ( $* ) if("$arg" == "by") then set relative continue endif if("$arg" == "to") then unset relative continue endif if(! $?dX) then set dX = `echo $arg | awk '$1+0>-20 && $1+0<20{print $1+0}'` continue endif if(! $?dY) then set dY = `echo $arg | awk '$1+0>-20 && $1+0<20{print $1+0}'` continue endif end #if(! $?dX) set dX = 0 if(! $?dY && $?relative) set dY = 0 if($?dX && $?dY) set move onintr report get_position: # survey the backstop motors from the deltatau set info = `echo -n "#9p\r#10p\r" | sock_exchange.tcl $pmac 14001 2 "\006" |& awk '{gsub("[\006\r]"," ",$0); print}'` # save current motor positions (in mm?) set pos = `echo "$info $hscale $vscale" | awk 'NF==4{print $1/$3, $2/$4}'` if($?debug) echo "GOTHERE pos = $pos" # see if deltatau responded amicably if($#pos == 4) then if($?move) goto move goto finish endif # didn't work, try XOS set pos = "" # use XOS: pretend to be a gui, get motor state, and then disconnect echo -n "" |\ xos3_exchange.tcl 1 "set_motor_dependency" 1 >! ${tempfile} set x = `awk '/^stog_configure_real_motor beamstop_horiz /{print $5}' ${tempfile}` set y = `awk '/^stog_configure_real_motor beamstop_vert /{print $5}' ${tempfile}` rm -f ${tempfile} >& /dev/null # save motor positions (in mm) set pos = ( $x $y ) if($?debug) echo "GOTHERE1 pos = $pos" # see if DCSS responded amicably if($#pos == 2) then if($?move) goto move goto finish endif # didn't work, try Labview directly set xpos = `pxmotor.com Beam Stop X |& awk '$NF!~/[^0-9\.-]/{print $NF}' | tail -1` set ypos = `pxmotor.com Beam Stop Y |& awk '$NF!~/[^0-9\.-]/{print $NF}' | tail -1` set pos = ( $xpos $ypos ) if($#pos == 2) then if($?move) goto move goto finish endif # didn't work, try BLAK-ICE echo -n "" |\ xos_exchange.tcl $control 1 "over out" 1 >! ${tempfile} set x = `awk '/^stog_configure_real_motor beamstop_horiz /{print $5}' ${tempfile}` set y = `awk '/^stog_configure_real_motor beamstop_vert /{print $5}' ${tempfile}` rm -f ${tempfile} >& /dev/null # save motor positions (in mm) set pos = ( $x $y ) if($?debug) echo "GOTHERE1 pos = $pos" # see if XOS responded amicably if($#pos == 2) then if($?move) goto move goto finish endif # didn't work, try something else? set pos = "" # jump ahead if we are out of ideas if(! $?move) goto finish move: if(! $?dX) set dX = 0 if(! $?dY) set dY = 0 # compute relative motor moves in mm set delta = ( $dX $dY ) # add the delta move to the current position set mmgoal = `echo $delta $pos | awk '{print $1+$3,$2+$4}'` if(! $?relative) then # use the absolute coordinates specified on the command line set mmgoal = ( $dX $dY ) endif # convert mm motor positions into encoder steps set goal = `echo $mmgoal $hscale $vscale | awk '{print $1*$3, $2*$4}'` # command the motors to move! try_again: if($?debug) echo "GOTHERE #9j=$goal[1] #10j=$goal[2] " echo -n "#9j=$goal[1]\r#10j=$goal[2]\r" | sock_exchange.tcl $pmac 14001 2 "\006" >& /dev/null if($status) goto XOS_move set speed = 1 usleep 300000 while ("$speed" != "0") # now check and see where they are set info = `echo -n "#9p\r#10p\r#9v\r#10v\r" | sock_exchange.tcl $pmac 14001 4 "\006" | awk '{gsub("[\006\r]"," ",$0); print}'` if($#info != 7) then echo "problem with network : $info" #echo "mcf\n8\n" | sock_exchange.tcl $pmac 9999 > /dev/null sleep 2 continue endif set x_reached = "$info[1]" set y_reached = "$info[2]" set speed = `echo "$info" | awk '{print sqrt($3*$3+$4*$4)}'` if($?debug) echo -n "GOTHERE " if($?debug) echo "$info $speed" echo "$info $speed" | awk '{printf "%.3f %.3f\n", $1,$2}' if("$speed" != "0") usleep 200000 end #echo "" # see if we made it set delta = `echo "$goal $info" | awk '{printf "%d", sqrt(($1-$3)^2+($2-$4)^2)}'` if(($delta > 100)&&($?RETRY)) then # finite number of retries if("$RETRY" =~ *[0-9]) set RETRY = `echo $RETRY | awk '{printf "%d", $1-1}'` if("$RETRY" == "0") set RETRY = "" if("$RETRY" == "") unset RETRY set delta = `echo "$goal $info" | awk '{print $1-$3, $2-$4}'` echo "backstop is $delta counts off the mark" set BAD endif unset move goto get_position XOS_move: # convert goal position to mm set goal = `echo $mmgoal | awk '{print $1, $2}'` # pretend to be a gui, set motor states, and then disconnect echo "gtos_become_master force\ngtos_start_motor_move beamstop_horiz $goal[1]\ngtos_start_motor_move beamstop_vert $goal[2]" |\ xos3_exchange.tcl 2 "stog_motor_move_completed beamstop" 2 > /dev/null if(! $status) then unset move goto get_position endif # that didn't work... try Labview directly pxmotor.com Beam Stop X $goal[1] >& /dev/null pxmotor.com Beam Stop Y $goal[2] >& /dev/null if(! $status) then unset move goto get_position endif # try BLAK-ICE: convert goal position to microns set goal = `echo $mmgoal | awk '{print 1000*$1, 1000*$2, 1000*$3}'` # pretend to be a gui, set motor states, and then disconnect echo "gtos_become_master force\ngtos_start_motor_move beamstop_horiz $goal[1]\ngtos_start_motor_move beamstop_vert $goal[2]" |\ xos_exchange.tcl $control 2 "stog_motor_move_completed beamstop" 2 > /dev/null if(! $status) then unset move goto get_position endif report: finish: if(! $?pos) set pos if($#pos >= 2) then set pos = `echo $pos | awk '{printf "%.3f %.3f", $1,$2}'` else set pos = "unknown" set BAD endif echo "backstop motors are now $pos" if ($?BAD) exit 9 exit