From 04e2e75d8017edf848b347bd5940c1f16e2cb1f2 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Fri, 31 Oct 2008 15:37:32 +1100 Subject: [PATCH] All Added "STARTING" message to the histmem command status. Can now make multiple script context positional motors Added table and table entry IDs for posit motor lookup tables. Fixed the runsics script so that the stop command sends an EndServer interrupt via the UDP port instead of killing SICS, this ensures that status is saved. Platypus Added chopper speed, phase and phase offsets for all choppers on hdb tree and in datafile Quokka Replace the sample/select command with the changer_position script context positional motor interface. Fixed upper limit on apx motor Added full sample changer and auto aperture positional motors r2727 | ffr | 2008-10-31 15:37:32 +1100 (Fri, 31 Oct 2008) | 14 lines --- .../config/commands/commands_common.tcl | 1 + .../config/motors/sct_positmotor_common.tcl | 137 +++++++++++------- .../instrument/hipd/config/INSTCFCOMMON.TXT | 1 + .../reflectometer/config/chopper/chopper.tcl | 19 ++- .../config/parameters/parameters.tcl | 4 + .../sans/config/commands/commands.tcl | 10 +- .../config/motors/motor_configuration.tcl | 6 +- .../motors/positmotor_configuration.tcl | 70 ++++++++- .../sans/config/parameters/parameters.tcl | 2 +- .../instrument/sans/quokka_configuration.tcl | 11 +- site_ansto/instrument/util/runsics | 58 +++++--- 11 files changed, 233 insertions(+), 86 deletions(-) diff --git a/site_ansto/instrument/config/commands/commands_common.tcl b/site_ansto/instrument/config/commands/commands_common.tcl index 28fb1bdb..9de84bb1 100644 --- a/site_ansto/instrument/config/commands/commands_common.tcl +++ b/site_ansto/instrument/config/commands/commands_common.tcl @@ -25,6 +25,7 @@ namespace eval ::histogram { ::histogram::histmem_cmd -set feedback status PAUSED } "start" { + ::histogram::histmem_cmd -set feedback status STARTING histmem mode $mode histmem preset $preset histmem freq $freq diff --git a/site_ansto/instrument/config/motors/sct_positmotor_common.tcl b/site_ansto/instrument/config/motors/sct_positmotor_common.tcl index 34bdeb4a..a1727579 100644 --- a/site_ansto/instrument/config/motors/sct_positmotor_common.tcl +++ b/site_ansto/instrument/config/motors/sct_positmotor_common.tcl @@ -3,27 +3,42 @@ namespace eval ::sobj::positmotor { variable posit_indices # TODO Add a script to edit the posit_table and attach it to indexed nodes with read and write actions. - proc abort_on_invalid_posindex {pos} { + proc abort_on_invalid_posindex {pos motor} { variable posit_indices - set pos0 [lindex $posit_indices 0] - set posend [lindex $posit_indices end] + set pos0 [lindex $posit_indices($motor) 0] + set posend [lindex $posit_indices($motor) end] if {$pos < $pos0 || $pos > $posend} { return -code error "ERROR: Indexed position must be between $pos0 and $posend" } } + proc isbetween {val l1 l2} { + if {($l1 <= $val && $val <= $l2) || ($l2 <= $val && $val <= $l1)} { + return true + } else { + return false + } + } + + proc iswithin {val pos prec} { + if {[expr $pos - $prec] <= $val && $val <= [expr $pos + $prec]} { + return true + } else { + return false + } + } ## # @brief Convert an indexed position to a physical motor position - proc pos2val {pos} { + proc pos2val {pos motor} { variable posit_table if [ catch { - abort_on_invalid_posindex $pos + abort_on_invalid_posindex $pos $motor set bot [expr int(floor($pos))] set top [expr int(ceil($pos))] set fract [expr fmod($pos,1)] - set val [expr $fract * ($posit_table($top) - $posit_table($bot)) + $posit_table($bot)] + set val [expr $fract * ($posit_table($motor,$top) - $posit_table($motor,$bot)) + $posit_table($motor,$bot)] } message ] { return -code error $message } else { @@ -33,31 +48,47 @@ namespace eval ::sobj::positmotor { ## # @brief Convert a physical motor position to and indexed position - proc val2pos {val precision} { + proc val2pos {val precision motor} { variable posit_table variable posit_indices set val [expr double($val)] - set pos0 [lindex $posit_indices 0] - set posend [lindex $posit_indices end] - if {$val < [expr $posit_table($pos0) - $precision]} {return -$pos0} - if {$val > [expr $posit_table($posend) + $precision]} {return -$posend} + set pos0 [lindex $posit_indices($motor) 0] + set posend [lindex $posit_indices($motor) end] + + if {$posit_table($motor,$pos0) < $posit_table($motor,$posend)} { + set fwd_table true + if {$val < [expr $posit_table($motor,$pos0) - $precision]} {return -$pos0} + if {$val > [expr $posit_table($motor,$posend) + $precision]} {return -$posend} + } else { + set fwd_table false + if {$val < [expr $posit_table($motor,$posend) - $precision]} {return -$posend} + if {$val > [expr $posit_table($motor,$pos0) + $precision]} {return -$pos0} + } + if [catch { set ibot $pos0 - set itop [lindex $posit_indices 1] - while {$val > [expr $posit_table($itop) + $precision]} { - incr ibot - incr itop + set itop [lindex $posit_indices($motor) 1] + if {$fwd_table} { + while {$val > [expr $posit_table($motor,$itop) + $precision]} { + incr ibot + incr itop + } + } else { + while {$val < [expr $posit_table($motor,$itop) - $precision]} { + incr ibot + incr itop + } } - set bot [expr $posit_table($ibot)] - set top [expr $posit_table($itop)] - if {[expr $bot - $precision] <= $val && $val <= [expr $bot + $precision]} { + set bot [expr $posit_table($motor,$ibot)] + set top [expr $posit_table($motor,$itop)] + if [iswithin $val $bot $precision] { set pos $ibot - } elseif {[expr $top - $precision] <= $val && $val <= [expr $top + $precision]} { + } elseif [iswithin $val $top $precision] { set pos $itop } else { # set pos [format "%.3f" [expr int(($val -$bot)/$precision)*$precision/($top - $bot) + $ibot]] - set pos [expr int(($val -$bot)/$precision)*$precision/($top - $bot) + $ibot] + set pos [expr abs(int(($val -$bot)/$precision)*$precision/($top - $bot)) + $ibot] } } errmsg] { return -code error $errmsg @@ -71,23 +102,23 @@ namespace eval ::sobj::positmotor { return state_reading_index } - proc state_reading_index {path par} { + proc state_reading_index {path par motor} { variable posit_table sct writestatus replyreceived - set rply [val2pos [sct result] [hval $path/motprecision]] + set rply [val2pos [sct result] [hval $path/motprecision] $motor] set data $rply # broadcast state_reading_index update parameter $par $data if {$data != [sct oldval] || [sct force_update] } { -# if {[status] == "status = Driving" && [hval $path/state] == "idle"} { -# hset $path/state busy +# if {[status] == "status = Driving" && [hval $path/status] == "IDLE"} { +# hset $path/status BUSY # } sct oldval $data sct update $data sct force_update False sct utime readtime } - if {[hval $path/state] == "stopping"} { - hset $path/state idle + if {[hval $path/status] == "STOPPING"} { + hset $path/status IDLE } return idle } @@ -98,8 +129,8 @@ namespace eval ::sobj::positmotor { # broadcast w_index if [ catch { - set val [pos2val [sct target] ] - hset $path/state busy + set val [pos2val [sct target] $motor] + hset $path/status BUSY run $motor $val $sct_controller poll $path 1 } errmsg ] { @@ -118,30 +149,37 @@ namespace eval ::sobj::positmotor { return OK } - proc setposindex {posindex val} { + proc setposindex {posindex val motor} { variable posit_table - set posit_table($posindex) $val + set posit_table($motor,$posindex) $val } - proc mk_sct_positmotor {sct_controller motname param axis posit_list} { + proc mk_sct_positmotor {sct_controller motor param table_ID posit_list} { variable posit_table variable posit_indices - array set posit_table $posit_list - set posit_indices [lsort [array names posit_table]] + set index 1 + foreach {label position} $posit_list { + lappend posit_indices($motor) $index + set posit_table($motor,$index) $position + set posit_label($index) $label + incr index + } +# set posit_indices [lsort -integer [array names posit_table]] + if [ catch { set ns ::sobj::positmotor - set parnode ${motname}_motor + set parnode ${motor}_motor MakeSICSObj $parnode SCT_MOTOR # Make setable position parameter and poll it. set posindex_node /sics/${parnode}/${param} hfactory $posindex_node plain spy float - hsetprop $posindex_node read ${ns}::rd_index $param $motname - hsetprop $posindex_node state_reading_index ${ns}::state_reading_index $posindex_node $param - hsetprop $posindex_node write ${ns}::w_index $sct_controller $posindex_node $param $motname + hsetprop $posindex_node read ${ns}::rd_index $param $motor + hsetprop $posindex_node state_reading_index ${ns}::state_reading_index $posindex_node $param $motor + hsetprop $posindex_node write ${ns}::w_index $sct_controller $posindex_node $param $motor hsetprop $posindex_node check ${ns}::check_motor hsetprop $posindex_node oldval UNKNOWN @@ -150,23 +188,25 @@ namespace eval ::sobj::positmotor { hfactory $posindex_node/motprecision script "getmotpar samx precision" "samx precision " float 1 hfactory $posindex_node/lookup_table plain spy none - hsetprop $posindex_node/lookup_table numpos [llength $posit_indices] - foreach posindex $posit_indices { - hfactory $posindex_node/lookup_table/$posindex script "${ns}::pos2val $posindex" "${ns}::setposindex $posindex " float 1 + hsetprop $posindex_node/lookup_table ID $table_ID + hsetprop $posindex_node/lookup_table numpos [llength $posit_indices($motor)] + foreach posindex $posit_indices($motor) { + hfactory $posindex_node/lookup_table/$posindex script "${ns}::pos2val $posindex $motor" "${ns}::setposindex $posindex $motor " float 1 + hsetprop $posindex_node/lookup_table/$posindex ID $posit_label($posindex) } - hfactory $posindex_node/state plain spy text - hset $posindex_node/state idle + hfactory $posindex_node/status plain spy text + hset $posindex_node/status IDLE - proc ${motname}_MOTEND {} [subst -nocommands { - if { [hval $posindex_node/state] == "busy"} { + proc ${motor}_MOTEND {} [subst -nocommands { + if { [hval $posindex_node/status] == "BUSY"} { $sct_controller poll $posindex_node 5 - hset $posindex_node/state stopping + hset $posindex_node/status STOPPING } }] - publish ${ns}::${motname}_MOTEND user + publish ${ns}::${motor}_MOTEND user - scriptcallback connect $motname MOTEND ${ns}::${motname}_MOTEND + scriptcallback connect $motor MOTEND ${ns}::${motor}_MOTEND $sct_controller poll $posindex_node $sct_controller write $posindex_node @@ -185,6 +225,5 @@ namespace import ::sobj::positmotor::* # # makesctcontroller /controllers/sct_mc1 std localhost:62034 # -# mk_sct_positmotor sct_mc1 phi phi_posindex A -# mk_sct_positmotor sct_mc1 chi B { 1 0 2 15 3 20 } +# mk_sct_positmotor sct_mc1 chi index { 1 0 2 15 3 20 } diff --git a/site_ansto/instrument/hipd/config/INSTCFCOMMON.TXT b/site_ansto/instrument/hipd/config/INSTCFCOMMON.TXT index b00f4dd6..1e43c217 100644 --- a/site_ansto/instrument/hipd/config/INSTCFCOMMON.TXT +++ b/site_ansto/instrument/hipd/config/INSTCFCOMMON.TXT @@ -12,4 +12,5 @@ config/hmm/anstohm_linked.xml config/scan/scan_common_1.hdd config/scan/scan_common_1.tcl config/nexus/nxscripts_common_1.tcl +config/commands/commands_common.tcl config/motors/sct_positmotor_common.tcl diff --git a/site_ansto/instrument/reflectometer/config/chopper/chopper.tcl b/site_ansto/instrument/reflectometer/config/chopper/chopper.tcl index 3aaabf5f..6a85751a 100644 --- a/site_ansto/instrument/reflectometer/config/chopper/chopper.tcl +++ b/site_ansto/instrument/reflectometer/config/chopper/chopper.tcl @@ -4,7 +4,12 @@ set CH1_MAXSPEED 1800 namespace eval ::chopper {} if {$sim_mode == "true"} { MakeChopper chopperController sim - ChopperAdapter chspeed chopperController speed 0 $CH1_MAXSPEED + ChopperAdapter ch1speed chopperController speed 0 $CH1_MAXSPEED + ChopperAdapter ch2speed chopperController speed 0 $CH1_MAXSPEED + ChopperAdapter ch3speed chopperController speed 0 $CH1_MAXSPEED + ChopperAdapter ch4speed chopperController speed 0 $CH1_MAXSPEED + + ChopperAdapter ch1phase chopperController phase 0 180 ChopperAdapter ch2phase chopperController phase 0 180 ChopperAdapter ch3phase chopperController phase 0 180 ChopperAdapter ch4phase chopperController phase 0 180 @@ -33,7 +38,11 @@ if {$sim_mode == "true"} { user $chopper_controller(user) \ password $chopper_controller(password) \ ] - ChopperAdapter chspeed chopperController speed_1 0 $CH1_MAXSPEED + ChopperAdapter ch1speed chopperController speed_1 0 $CH1_MAXSPEED + ChopperAdapter ch2speed chopperController speed_2 0 $CH1_MAXSPEED + ChopperAdapter ch3speed chopperController speed_3 0 $CH1_MAXSPEED + ChopperAdapter ch4speed chopperController speed_4 0 $CH1_MAXSPEED + ChopperAdapter ch1phase chopperController phase_1 0 180 ChopperAdapter ch2phase chopperController phase_2 0 180 ChopperAdapter ch3phase chopperController phase_3 0 180 ChopperAdapter ch4phase chopperController phase_4 0 180 @@ -63,7 +72,11 @@ if {$sim_mode == "true"} { } } -sicslist setatt chspeed units "rpm" +sicslist setatt ch1speed units "rpm" +sicslist setatt ch2speed units "rpm" +sicslist setatt ch3speed units "rpm" +sicslist setatt ch4speed units "rpm" +sicslist setatt ch1phase units "degrees" sicslist setatt ch2phase units "degrees" sicslist setatt ch3phase units "degrees" sicslist setatt ch4phase units "degrees" diff --git a/site_ansto/instrument/reflectometer/config/parameters/parameters.tcl b/site_ansto/instrument/reflectometer/config/parameters/parameters.tcl index cc0ab497..1e494c98 100644 --- a/site_ansto/instrument/reflectometer/config/parameters/parameters.tcl +++ b/site_ansto/instrument/reflectometer/config/parameters/parameters.tcl @@ -25,6 +25,10 @@ foreach vn { chopper2_base chopper1_distance chopper1_base + chopper1_phase_offset + chopper2_phase_offset + chopper3_phase_offset + chopper4_phase_offset slit1_distance slit1_base omega diff --git a/site_ansto/instrument/sans/config/commands/commands.tcl b/site_ansto/instrument/sans/config/commands/commands.tcl index fc688cb1..86de63a5 100644 --- a/site_ansto/instrument/sans/config/commands/commands.tcl +++ b/site_ansto/instrument/sans/config/commands/commands.tcl @@ -5,11 +5,11 @@ namespace eval motor { variable is_homing_list "" } -namespace eval sample { - command select {int=0:8 sampid} { - SampleNum $sampid - } -} +#namespace eval sample { +# command select {int=0:8 sampid} { +# SampleNum $sampid +# } +#} namespace eval optics { VarMake ::optics::select::section text user diff --git a/site_ansto/instrument/sans/config/motors/motor_configuration.tcl b/site_ansto/instrument/sans/config/motors/motor_configuration.tcl index b98b0825..cd3024af 100644 --- a/site_ansto/instrument/sans/config/motors/motor_configuration.tcl +++ b/site_ansto/instrument/sans/config/motors/motor_configuration.tcl @@ -1,5 +1,5 @@ -# $Revision: 1.24 $ -# $Date: 2008-08-19 05:11:55 $ +# $Revision: 1.25 $ +# $Date: 2008-10-31 04:37:31 $ # Author: Ferdi Franceschini (ffr@ansto.gov.au) # Last revision by: $Author: ffr $ @@ -753,7 +753,7 @@ Motor apx $motor_driver_type [params \ axis E\ units mm\ hardlowerlim -10\ - hardupperlim 10\ + hardupperlim 360\ maxSpeed 1\ maxAccel 1\ maxDecel 1\ diff --git a/site_ansto/instrument/sans/config/motors/positmotor_configuration.tcl b/site_ansto/instrument/sans/config/motors/positmotor_configuration.tcl index ad54b08f..532df1ce 100644 --- a/site_ansto/instrument/sans/config/motors/positmotor_configuration.tcl +++ b/site_ansto/instrument/sans/config/motors/positmotor_configuration.tcl @@ -1,12 +1,70 @@ source $cfPath(motors)/sct_positmotor_common.tcl -set port [::utility::get_portnum pmc1-quokka] -makesctcontroller sct_mc1 std localhost:$port +set port1 [::utility::get_portnum pmc1-quokka] +set port2 [::utility::get_portnum pmc2-quokka] +set port3 [::utility::get_portnum pmc3-quokka] +set port4 [::utility::get_portnum pmc4-quokka] +makesctcontroller sct_mc1 std mc1:$port1 +makesctcontroller sct_mc2 std mc2:$port2 +makesctcontroller sct_mc3 std mc3:$port3 +makesctcontroller sct_mc4 std mc4:$port4 -mk_sct_positmotor sct_mc1 samx samplenum C { -1 0 -2 15 -3 20 +# label pos +set 20sample_table { + 1 453.7 + 2 411.7 + 3 369.7 + 4 327.7 + 5 285.7 + 6 203.7 + 7 161.7 + 8 119.7 + 9 77.7 + 10 35.7 + 11 -46.3 + 12 -88.3 + 13 -130.3 + 14 -172.3 + 15 -214.3 + 16 -296.3 + 17 -338.3 + 18 -380.3 + 19 -422.3 + 20 -464.3 } +mk_sct_positmotor sct_mc1 samx samplenum 20SAMPLES $20sample_table + +set auto_ap_table { + 2.5 0 + 5.0 23 + 7.5 47 + 10.0 72 + 12.5 98 + 15.0 125 + 17.5 153 + 20.0 183 + 25.0 215 + 30.0 250 +} +mk_sct_positmotor sct_mc3 apx aperture auto_ap $auto_ap_table + + + + + + + + + + + + + + + + + + + diff --git a/site_ansto/instrument/sans/config/parameters/parameters.tcl b/site_ansto/instrument/sans/config/parameters/parameters.tcl index decf4c1d..018fe4cf 100644 --- a/site_ansto/instrument/sans/config/parameters/parameters.tcl +++ b/site_ansto/instrument/sans/config/parameters/parameters.tcl @@ -41,7 +41,7 @@ foreach {var lname nxname units klass} { } } -::utility::mkVar SampleNum int readonly changer_position true parameter true true +# ::utility::mkVar SampleNum int readonly changer_position true parameter true true ## # @brief Parameter SicsVariables diff --git a/site_ansto/instrument/sans/quokka_configuration.tcl b/site_ansto/instrument/sans/quokka_configuration.tcl index 3412d663..698c73c5 100644 --- a/site_ansto/instrument/sans/quokka_configuration.tcl +++ b/site_ansto/instrument/sans/quokka_configuration.tcl @@ -1,5 +1,5 @@ -# $Revision: 1.15 $ -# $Date: 2008-10-27 04:55:47 $ +# $Revision: 1.16 $ +# $Date: 2008-10-31 04:37:31 $ # Author: Ferdi Franceschini (ffr@ansto.gov.au) # Last revision by: $Author: ffr $ @@ -55,3 +55,10 @@ server_init hsetprop /instrument/parameters/derived_parameters/$pname/feedback/status data false hsetprop /instrument/parameters/derived_parameters/$pname/feedback/status nxsave false } + hsetprop /sct_mc1 control false + hsetprop /sct_mc2 control false + hsetprop /sct_mc3 control false + hsetprop /sct_mc4 control false + + hfactory /instrument/parameters/changer_position link samx_motor + hfactory /instrument/parameters/autoSampleAp link apx_motor diff --git a/site_ansto/instrument/util/runsics b/site_ansto/instrument/util/runsics index 5d997939..e63cc194 100755 --- a/site_ansto/instrument/util/runsics +++ b/site_ansto/instrument/util/runsics @@ -1,17 +1,24 @@ #!/bin/sh +ulimit -c unlimited # We should really have an init script calling this or something like it. INSTRUMENT=${HOSTNAME#ics1-} +intserverport=60002 +serverport=60003 + +intvalport=60012 +valport=60013 + # Start SICS startsics() { - if netstat -ltp 2> /dev/null|grep -q "server-${INSTRUMENT}.*SICServer"; then + if netstat -nltp 2> /dev/null|grep -q "${serverport}.*SICServer"; then echo SICS is already running return 1 fi echo Starting SICS cd /usr/local/sics/server nohup $PWD/SICServer ${INSTRUMENT}_configuration.tcl - if netstat -ltp 2> /dev/null|grep -q "server-${INSTRUMENT}.*SICServer"; then + if netstat -nltp 2> /dev/null|grep -q "${serverport}.*SICServer"; then echo SUCCESS return 1 else @@ -22,7 +29,7 @@ startsics() { # Start script validator startscriptvalidator() { - if netstat -ltp 2> /dev/null|grep -q "server-val-${INSTRUMENT}.*SICServer"; then + if netstat -nltp 2> /dev/null|grep -q "${valport}.*SICServer"; then echo SICS script validator is already running return 1 fi @@ -30,7 +37,7 @@ startscriptvalidator() { cd /usr/local/sics/server/ SICS_SIMULATION=script_validator nohup $PWD/SICServer ${INSTRUMENT}_configuration.tcl - if netstat -ltp 2> /dev/null|grep -q "server-val-${INSTRUMENT}.*SICServer"; then + if netstat -nltp 2> /dev/null|grep -q "${valport}.*SICServer"; then echo SUCCESS return 1 else @@ -39,6 +46,28 @@ startscriptvalidator() { fi } +stopsics() { + if netstat -nltp 2> /dev/null|grep -q "${serverport}.*SICServer"; then + echo "SICSINT 6" |socat STDIN UDP4:localhost:${intserverport},crlf + fi + if netstat -nltp 2> /dev/null|grep -q "${serverport}.*SICServer"; then + echo FAILED to stop SICServer + else + echo SICServer stopped + fi +} + +stopscriptvalidator() { + if netstat -nltp 2> /dev/null|grep -q "${valport}.*SICServer"; then + echo "SICSINT 6" |socat STDIN UDP4:localhost:${intvalport},crlf + fi + if netstat -nltp 2> /dev/null|grep -q "${valport}.*SICServer"; then + echo FAILED to stop SICS script validator + else + echo SICS script validator stopped + fi +} + usage() { progname=`basename $0` echo Usage: $progname start @@ -63,29 +92,24 @@ then echo elif [ $1 = "stop" ] then - if killall SICServer; then - echo Terminating all SICS servers + if netstat -nltp 2> /dev/null|grep -q "${serverport}.*SICServer"; then + stopsics else - echo No SICS servers are running + echo SICServer NOT running fi - if netstat -ltp 2> /dev/null|grep -q "server-${INSTRUMENT}.*SICServer"; then - echo FAILED to stop SICServer + if netstat -nltp 2> /dev/null|grep -q "${valport}.*SICServer"; then + stopscriptvalidator else - echo SICServer stopped - fi - if netstat -ltp 2> /dev/null|grep -q "server-val-${INSTRUMENT}.*SICServer"; then - echo FAILED to stop SICS script validator - else - echo SICS script validator stopped + echo SICS script validator NOT running fi elif [ $1 = "status" ] then - if netstat -ltp 2> /dev/null|grep -q "server-${INSTRUMENT}.*SICServer"; then + if netstat -nltp 2> /dev/null|grep -q "${serverport}.*SICServer"; then echo SICServer running else echo SICServer NOT running fi - if netstat -ltp 2> /dev/null|grep -q "server-val-${INSTRUMENT}.*SICServer"; then + if netstat -nltp 2> /dev/null|grep -q "${valport}.*SICServer"; then echo SICS script validator running else echo SICS script validator NOT running