diff --git a/exebuf.c b/exebuf.c index 7ee47eb7..45d9dee7 100644 --- a/exebuf.c +++ b/exebuf.c @@ -224,6 +224,7 @@ int exeBufProcess(pExeBuf self, SicsInterp *pSics, DeleteDynString(command); if(SCGetInterrupt(pCon) >= eAbortBatch){ SCWrite(pCon,"ERROR: batch processing interrupted",eError); + InvokeCallBack(pCall,BATCHEND,self->name); SetStatus(eEager); return 0; } else { diff --git a/site_ansto/instrument/TEST_SICS/fakeDMC/dmc2280Server.tcl b/site_ansto/instrument/TEST_SICS/fakeDMC/dmc2280Server.tcl index ea4fdc0a..7f15b780 100644 --- a/site_ansto/instrument/TEST_SICS/fakeDMC/dmc2280Server.tcl +++ b/site_ansto/instrument/TEST_SICS/fakeDMC/dmc2280Server.tcl @@ -1,5 +1,5 @@ -# $Revision: 1.3 $ -# $Date: 2007-10-31 06:10:30 $ +# $Revision: 1.4 $ +# $Date: 2009-01-23 05:06:03 $ # Author: Ferdi Franceschini (ffr@ansto.gov.au) # Last revision by: $Author: ffr $ @@ -25,34 +25,36 @@ proc readLine {who channel} { } else { puts "RECEIVED: $line" - switch -glob $line { - "" {puts -nonewline $channel ":"} - "kill" {exit} - "SH*" - "BG*" - "PA*" - "DP*" - "AT*" - "MO*" - "ST*" - "SP*" - "AC*" - "DC*" { - eval [parse $line] - puts -nonewline $channel ":" - } - "TP*" - "TD*" - "TI*" - "XQ*" { - set output [eval [parse $line]] - puts $channel " $output"; puts -nonewline $channel ":" - } - "LV" { - set output [eval [parse $line]] - puts $channel "$output"; puts -nonewline $channel ":" - } - "TS*" { - set output [eval [parse $line]] - puts $channel " $output"; puts -nonewline $channel ":" - } - "TC 1" { - puts $channel " DMC2280 ERROR"; puts -nonewline $channel ":" - } - "MG *" { - set output [eval [parse $line]] - puts $channel " $output"; puts -nonewline $channel ":" + foreach cmd [split $line ";"] { + switch -glob $cmd { + "" {puts -nonewline $channel ":"} + "kill" {exit} + "SH*" - "BG*" - "PA*" - "PR*" - "JG*" - "DP*" - "AT*" - "MO*" - "ST*" - "SP*" - "AC*" - "DC*" { + eval [parse $cmd] + puts -nonewline $channel ":" + } + "TP*" - "TD*" - "TI*" - "XQ*" { + set output [eval [parse $cmd]] + puts $channel " $output"; puts -nonewline $channel ":" + } + "LV" { + set output [eval [parse $cmd]] + puts $channel "$output"; puts -nonewline $channel ":" + } + "TS*" { + set output [eval [parse $cmd]] + puts $channel " $output"; puts -nonewline $channel ":" + } + "TC 1" { + puts $channel " DMC2280 ERROR"; puts -nonewline $channel ":" + } + "MG *" { + set output [eval [parse $cmd]] + puts $channel " $output"; puts -nonewline $channel ":" + } } + flush $channel; } - flush $channel; set didRead 1 } return; diff --git a/site_ansto/instrument/TEST_SICS/fakeDMC/mkSimAxes.tcl b/site_ansto/instrument/TEST_SICS/fakeDMC/mkSimAxes.tcl index 2d87fe0e..b7fb38ed 100755 --- a/site_ansto/instrument/TEST_SICS/fakeDMC/mkSimAxes.tcl +++ b/site_ansto/instrument/TEST_SICS/fakeDMC/mkSimAxes.tcl @@ -1,9 +1,9 @@ #!/usr/bin/tclsh -# $Revision: 1.8 $ -# $Date: 2008-05-12 01:08:15 $ +# $Revision: 1.9 $ +# $Date: 2009-01-23 05:06:03 $ # Author: Ferdi Franceschini (ffr@ansto.gov.au) -# Last revision by: $Author: dcl $ +# Last revision by: $Author: ffr $ # Creates fake DMC configuration files based on the instrument # configuration file. @@ -63,14 +63,17 @@ proc mkSimAxes {instrument} { set speed [expr $motor(stepsperx) * $motor(maxspeed)] set acc [expr $motor(stepsperx) * $motor(maxaccel)] set dec [expr $motor(stepsperx) * $motor(maxdecel)] + set lolim $motor(hardlowerlim) + set uplim $motor(hardupperlim) if [ info exists motor(absenc) ] { set enPos $motor(absenchome); set enCnts $motor(cntsperx); } else { set enPos 0; - set enCnts 0; + set enCnts $motor(stepsperx); } - puts $simFile($IPtoContName($motor(asyncqueue)-$instrument)) "array set $nm \[\list SC 1 TD 0 TP $enPos BG 0 ST 0 SP $speed AC $acc DC $dec cntsperx $enCnts stepsperx $motor(stepsperx) PA 0 TS 44 \]"; + # MVTYPE = PA (move to target),PR (relative move), JG (move until limswitch or stop cmd) + puts $simFile($IPtoContName($motor(asyncqueue)-$instrument)) "array set $nm \[\list SC 1 TD 0 TP $enPos BG 0 ST 0 SP $speed AC $acc DC $dec cntsperx $enCnts stepsperx $motor(stepsperx) PA 0 TS 44 MVTYPE unknown LOLIM $lolim UPLIM $uplim ABSHOME $enPos ATLIM false\]"; # eval "lappend $IPtoContName($motor(host))_motors $m"; } diff --git a/site_ansto/instrument/TEST_SICS/fakeDMC/simAxis.tcl b/site_ansto/instrument/TEST_SICS/fakeDMC/simAxis.tcl index b4e72093..0f8825a6 100644 --- a/site_ansto/instrument/TEST_SICS/fakeDMC/simAxis.tcl +++ b/site_ansto/instrument/TEST_SICS/fakeDMC/simAxis.tcl @@ -1,8 +1,14 @@ -# $Revision: 1.8 $ -# $Date: 2008-05-30 00:26:54 $ +# $Revision: 1.9 $ +# $Date: 2009-01-23 05:06:03 $ # Author: Ferdi Franceschini (ffr@ansto.gov.au) # Last revision by: $Author: ffr $ +proc sleep {mstime} { + set x 0 + after $mstime {set x 1} + vwait x +} + # Requires a configuration array for each axis that you want to simulate. # eg #array set B [list AC 25000 TP 7827107 TD 25000 PA 25000 stepsperx 25000 cntsperx 8192 DC 25000 SP 25000] @@ -30,10 +36,23 @@ proc dmset {cmd axis args} { } else { set val [evaluate $args] } - if {[string first $cmd "PA SP AC DC"] != -1} { - uplevel #0 set ${axis}($cmd) $val; - } else { - uplevel #0 $cmd $axis $val; + set inst [string range $cmd 0 1] + switch $inst { + "PA" - "PR" { + uplevel #0 set ${axis}(MVTYPE) $inst + uplevel #0 set ${axis}($cmd) $val; + } + "JG" { + uplevel #0 set ${axis}(MVTYPE) $inst + uplevel #0 set ${axis}($cmd) $val; +# uplevel #0 set ${axis}(SP) $val; + } + "SP" - "AC" - "DC" { + uplevel #0 set ${axis}($cmd) $val; + } + default { + uplevel #0 $cmd $axis $val; + } } } @@ -51,8 +70,12 @@ proc DP {axis val} { proc TS {axis} { uplevel #0 eval set ${axis}(TS) } -proc ST {axis} { - uplevel #0 eval set ${axis}(ST) 1 +proc ST {_axis} { + upvar #0 $_axis axis; + set axis(ST) 1 + while {$axis(BG) == 1} { + sleep 1000 + } } proc SH {args} {} @@ -67,15 +90,24 @@ proc BG {_axis} { set axis(BG) 1; # motor is moving set axis(SC) 0; # motor is running set timeStep 0.1; # seconds - set target $axis(PA); - set diff [expr $target - $axis(TD)]; - set sign [expr ($axis(PA) - $axis(TD)) < 0 ? -1 : 1]; - set step [expr $sign * $timeStep * $axis(SP) ]; - if {[expr abs($diff) < abs($step)]} { - set step $diff; - set timeStep [expr abs($step / $axis(SP))]; + set axis(ST) 0 + switch $axis(MVTYPE) { + "PA" { + set target $axis(PA); + set diff [expr $target - $axis(TD)]; + set sign [expr ($axis(PA) - $axis(TD)) < 0 ? -1 : 1]; + set step [expr $sign * $timeStep * $axis(SP) ]; + if {[expr abs($diff) < abs($step)]} { + set step $diff; + set timeStep [expr abs($step / $axis(SP))]; + } + every [expr round($timeStep * 1000)] "nextstep $_axis $step target $_axis $target $step" + } + "JG" { + set step [expr $timeStep * $axis(JG) ]; + every [expr round($timeStep * 1000)] "nextstep $_axis $step jogit" + } } - every [expr round($timeStep * 1000)] "nextstep $_axis $step $target" # set diff [expr $target - $axis(TD)]; # set mult [expr $axis(cntsperx).0/$axis(stepsperx)]; @@ -107,29 +139,66 @@ proc every {ms body} { return; } -proc nextstep {paxis step target} { +proc nextstep {paxis step args} { upvar #0 $paxis axis; + set finished false + if {($axis(ATLIM) == "upper") && ($step > 0)} { + return 0 + } elseif {($axis(ATLIM) == "lower") && ($step < 0)} { + return 0 + } set mult [expr double($axis(cntsperx))/$axis(stepsperx)]; set axis(TP) [expr int($step * $mult + $axis(TP))]; set TD_POS [expr int($axis(TD) + $step)]; set axis(TD) [expr int($TD_POS)]; + set currPos [expr ($axis(TP) - $axis(ABSHOME))/abs(double($axis(cntsperx)))] if {$axis(ST) == 1} { set axis(TS) 44; # Stopped, limit switches open set axis(BG) 0; # motor has stopped set axis(ST) 0; # make sure stop flag is unset set axis(SC) 4; # motor stopped by stop command (ST) - return 0; - } elseif {[expr abs($target - $axis(TD)) < abs($step)]} { - set diff [expr $target - $axis(TD)]; - set axis(TP) [expr int(round($diff*$mult + $axis(TP)))]; - set axis(TD) [expr int($target)]; + set axis(ATLIM) false + set finished true + } elseif {$currPos >= $axis(UPLIM)} { + set axis(TS) 36; # Stopped on forward limit switch + set axis(BG) 0; # motor has stopped + set axis(ST) 0; # make sure stop flag is unset + set axis(SC) 2; # motor stopped by limit switch + set axis(ATLIM) upper + set finished true + } elseif {$currPos <= $axis(LOLIM)} { + set axis(TS) 40; # Stopped on reverse limit switch + set axis(BG) 0; # motor has stopped + set axis(ST) 0; # make sure stop flag is unset + set axis(SC) 3; # motor stopped by limit switch + set axis(ATLIM) lower + set finished true + } elseif {[eval $args]} { + # Stop if condition specified in "args" is met +# set diff [expr $target - $axis(TD)]; +# set axis(TP) [expr int(round($diff*$mult + $axis(TP)))]; +# set axis(TD) [expr int($target)]; set axis(TS) 44; # Stopped, limit switches open set axis(BG) 0; # motor has stopped set axis(ST) 0; # make sure stop flag is unset set axis(SC) 1; # motor stopped at commanded position - return 0; + set axis(ATLIM) false + set finished true } else { - return 1; + set finished false + } + if {$finished} { + set axis(MVTYPE) "unknown" + return 0 + } else { + return 1 } } +proc target {paxis target step} { + upvar #0 $paxis axis; + return [expr abs($target - $axis(TD)) < abs($step)] +} +proc jogit {} { + return false +} diff --git a/site_ansto/instrument/config/motors/sct_jogmotor_common.tcl b/site_ansto/instrument/config/motors/sct_jogmotor_common.tcl index f724466a..2b61ddb9 100644 --- a/site_ansto/instrument/config/motors/sct_jogmotor_common.tcl +++ b/site_ansto/instrument/config/motors/sct_jogmotor_common.tcl @@ -58,16 +58,18 @@ namespace eval ::scobj::jogmotor { set cmd DOWN set dirn -1 } + "stop" { + $sct_controller send "ST${axis}" + return getACK + } default { set cmd UNKNOWN } }] if {$cmd != "UNKNOWN"} { - set jogspeed [expr $dirn * [hval [hsibPath "speed"] ]] - - $sct_controller send "JG${axis}=$jogspeed" - $sct_controller send "SH${axis}" - sct send "BG${axis}" +# set jogspeed [expr $dirn * [hval [hsibPath "speed"] ]] + set jogspeed [expr $dirn * [sct jogspeed]] + $sct_controller send "ST${axis};JG${axis}=$jogspeed;SH${axis};BG${axis}" return getACK } else { return idle @@ -125,7 +127,7 @@ proc updatestatus {} { # middle n2 "inbetween" # lower n3 "down" #} - proc mk_sct_jogmotor {sct_controller axis jogmotor {initcmd_table {UP "up" DOWN "down"}}} { + proc mk_sct_jogmotor {sct_controller axis jogmotor jogspeed {initcmd_table {UP "up" DOWN "down"}}} { variable cmd_table foreach {cmd name} $initcmd_table { set cmd_table($cmd) [string tolower $name] @@ -145,6 +147,7 @@ proc updatestatus {} { hfactory $jog_hpath/command plain user text hsetprop $jog_hpath/command write ${ns}::jogCmd $sct_controller $axis hsetprop $jog_hpath/command getACK ${ns}::getACK $sct_controller + hsetprop $jog_hpath/command jogspeed $jogspeed hfactory $jog_hpath/status plain spy text hsetprop $jog_hpath/status read ${ns}::status $axis diff --git a/site_ansto/instrument/hipd/config/commands/commands.tcl b/site_ansto/instrument/hipd/config/commands/commands.tcl index f8f2cb32..9beeb7ee 100644 --- a/site_ansto/instrument/hipd/config/commands/commands.tcl +++ b/site_ansto/instrument/hipd/config/commands/commands.tcl @@ -5,6 +5,116 @@ namespace eval motor { variable is_homing_list "" } +namespace eval ajscmds { +# SetRadColl +command SetRadColl { +float time +float range +} { + + set spd [expr 2.0*$range / $time] + oct softlowerlim [expr -abs($range/2.0) - 0.5] + oct softupperlim [expr abs($range/2.0) + 0.5] + oct maxretry 5 + oct accel 0.25 + oct speed 0.25 + drive oct [expr abs($range/2.0)] + oct speed $spd + oct accel $spd + oct maxretry 0 +} +# SimpleRun +command SimpleRun { +float=0:inf steptime +int=1:inf numsteps +} { + + RadCollOff + histmem mode time + histmem preset $steptime + newfile HISTOGRAM_XY + for {set i 0} {$i < $numsteps} {incr i} { + histmem start block + save $i + } +} +# SimpleScan +command SimpleScan { +text=drivable motor +float start +float step +int=1:inf numsteps +float=0:inf steptime +} { + + RadCollOff + histmem mode time + histmem preset $steptime + newfile HISTOGRAM_XY + for {set i 0} {$i < $numsteps} {incr i} { + drive $motor [expr $i*$step+$start] + histmem start block + save $i + } +} +# RadCollRun +command RadCollRun { +int=1:inf oscno +int=1:inf reps +} { + + RadCollOn $oscno + histmem mode unlimited + newfile HISTOGRAM_XY + for {set i 0} {$i < $reps} {incr i} { + histmem start block + save $i + } + RadCollOff +} +# RadCollTimed +command RadCollTimed { +int=1:inf oscno +float=0:inf time +} { + + RadCollOn $oscno + set tim1 [clock seconds] + histmem mode unlimited + newfile HISTOGRAM_XY + set bool 0 + set i 0 + set timsecs [expr $time*60] + while {$bool == 0} { + histmem start block + save $i + incr i + set tim2 [expr [clock seconds] - $tim1] + if {$tim2 > $timsecs} {set bool 1} + } + RadCollOff +} +# RadCollScan +command RadCollScan { +text=drivable motor +float start +float step +int=1:inf numsteps +int=1:inf oscno +} { + + RadCollOn $oscno + histmem mode unlimited + newfile HISTOGRAM_XY + for {set i 0} {$i < $numsteps} {incr i} { + drive $motor [expr $i*$step+$start] + histmem start block + save $i + } + RadCollOff +} +} + proc ::commands::isc_initialize {} { ::commands::ic_initialize }