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
This commit is contained in:
Ferdi Franceschini
2008-10-31 15:37:32 +11:00
committed by Douglas Clowes
parent b9e1b19252
commit 04e2e75d80
11 changed files with 233 additions and 86 deletions

View File

@@ -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 }