Initial commit
r2845 | ffr | 2009-12-11 13:09:56 +1100 (Fri, 11 Dec 2009) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
3abd3effa2
commit
35d1930d1b
@@ -0,0 +1,193 @@
|
||||
# $Revision: 1.2 $
|
||||
# $Date: 2009-12-11 02:09:56 $
|
||||
# Author: Ferdi Franceschini (ffr@ansto.gov.au)
|
||||
# Last revision by: $Author: ffr $
|
||||
|
||||
##
|
||||
# @file Platypus Beam Attenuator control and status.
|
||||
namespace eval ::scobj::galil {
|
||||
variable sim_mode
|
||||
variable bat_state
|
||||
array set bat_state [list OUT -1 IN 0 OSC 1]
|
||||
|
||||
set NS ::scobj::galil
|
||||
set batObjName scbat
|
||||
set batpath /sics/$batObjName
|
||||
|
||||
set sim_mode [SplitReply [motor_simulation]]
|
||||
# set sim_mode "false"
|
||||
|
||||
if {$sim_mode == "false"} {
|
||||
makesctcontroller sct_mc1 galil mc1-platypus:1034
|
||||
}
|
||||
MakeSICSObj $batObjName SCT_OBJECT
|
||||
|
||||
##
|
||||
# @brief Send a command which returns a value
|
||||
# @param nextState, State which handles the reply
|
||||
# @param cmd, Galil command
|
||||
# @return The next state
|
||||
proc getValue {nextState cmd} {
|
||||
sct send $cmd
|
||||
return $nextState
|
||||
}
|
||||
|
||||
##
|
||||
# @brief Check that a command has been acknowledged
|
||||
proc ackCmd {} {
|
||||
set reply [sct result]
|
||||
switch -glob -- $reply {
|
||||
"ASCERR:*" {
|
||||
sct geterror $reply
|
||||
}
|
||||
"OK" {
|
||||
return idle
|
||||
}
|
||||
default {
|
||||
sct geterror "Unhandled reply: $reply"
|
||||
}
|
||||
}
|
||||
return idle
|
||||
}
|
||||
|
||||
##
|
||||
# @brief Simply reports a reply to the user by setting the hipadaba node
|
||||
# which this proc is associated with.
|
||||
proc rdValue {} {
|
||||
set data [sct result]
|
||||
switch -glob -- $data {
|
||||
"ASCERR:*" {
|
||||
sct geterror $data
|
||||
}
|
||||
default {
|
||||
if {$data != [sct oldval]} {
|
||||
sct oldval $data
|
||||
sct update $data
|
||||
sct utime readtime
|
||||
}
|
||||
}
|
||||
}
|
||||
return idle
|
||||
}
|
||||
|
||||
##
|
||||
# @brief Translates BAT state to English and reports it via the hdb node.
|
||||
proc rdBatAction {} {
|
||||
variable bat_state
|
||||
set oscd [expr int([sct result])]
|
||||
switch -- $oscd [subst {
|
||||
$bat_state(OUT) {set msg "out"}
|
||||
$bat_state(IN) {set msg "in"}
|
||||
$bat_state(OSC) {set msg "osc"}
|
||||
default {
|
||||
sct geterror "Illegal value $oscd for beam attenuator state"
|
||||
return idle
|
||||
}
|
||||
} ]
|
||||
if {$msg != [sct oldval]} {
|
||||
sct oldval $msg
|
||||
sct update $msg
|
||||
sct utime readtime
|
||||
}
|
||||
return idle
|
||||
}
|
||||
|
||||
##
|
||||
# @brief Sets the BAT to the state set in the target property
|
||||
# of the hdb node.
|
||||
# @param nextState, The script context state which handles the galil reply.
|
||||
proc setBatAction {nextState} {
|
||||
variable bat_state
|
||||
set par [sct target]
|
||||
switch $par {
|
||||
"out" {sct send "OSCD=$bat_state(OUT)"}
|
||||
"in" {sct send "OSCD=$bat_state(IN)"}
|
||||
"osc" {sct send "OSCD=$bat_state(OSC)"}
|
||||
default {
|
||||
error "ERROR: illegal action $par for beam attenuator, try 'in', 'out' or 'osc'"
|
||||
}
|
||||
}
|
||||
return $nextState
|
||||
}
|
||||
|
||||
##
|
||||
# @brief Send a status request to the Galil
|
||||
#
|
||||
# NOTE: If you change the status command you must also
|
||||
# update the rdStatus procedure
|
||||
proc getStatus {} {
|
||||
sct send "MG OSCD,POS,_TPA,DBAND"
|
||||
return rdStatus
|
||||
}
|
||||
|
||||
##
|
||||
# @brief Parse the status reply from the Galil and set
|
||||
# the abstract status.
|
||||
proc rdStatus {} {
|
||||
variable bat_state
|
||||
|
||||
set data [sct result]
|
||||
switch -glob -- $data {
|
||||
"ASCERR:*" {
|
||||
sct geterror $data
|
||||
}
|
||||
default {
|
||||
if {$data != [sct oldval]} {
|
||||
sct oldval $data
|
||||
foreach {OSCD POS TPA DBAND} $data {}
|
||||
if [expr $OSCD == $bat_state(OSC)] {
|
||||
set newStatus "busy"
|
||||
} elseif [expr abs($TPA - $POS) < $DBAND] {
|
||||
set newStatus "idle"
|
||||
} else {
|
||||
set newStatus "busy"
|
||||
}
|
||||
if {[sct oldStatus] != $newStatus} {
|
||||
sct oldStatus $newStatus
|
||||
sct update $newStatus
|
||||
sct utime readtime
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return idle
|
||||
}
|
||||
|
||||
# Read and set the BAT state, ie in, out, oscillating
|
||||
hfactory $batpath/action plain user text
|
||||
hsetprop $batpath/action read ${NS}::getValue rdBatAction "MG OSCD"
|
||||
hsetprop $batpath/action rdBatAction ${NS}::rdBatAction
|
||||
hsetprop $batpath/action write ${NS}::setBatAction ${NS}::ackCmd
|
||||
hsetprop $batpath/action ackCmd ${NS}::ackCmd
|
||||
hsetprop $batpath/action oldval UNKNOWN
|
||||
|
||||
# Report the abstract status to GumTree
|
||||
hfactory $batpath/status plain user text
|
||||
hsetprop $batpath/status read ${NS}::getStatus
|
||||
hsetprop $batpath/status rdStatus ${NS}::rdStatus
|
||||
hsetprop $batpath/status values busy,idle
|
||||
hsetprop $batpath/status oldval UNKNOWN
|
||||
hsetprop $batpath/status oldStatus UNKNOWN
|
||||
hset $batpath/status idle
|
||||
|
||||
# Report the current position in encoder counts
|
||||
# Useful as an activity monitor and troubleshooting.
|
||||
hfactory $batpath/pos plain user int
|
||||
hsetprop $batpath/pos read ${NS}::getValue rdValue "TPA"
|
||||
hsetprop $batpath/pos rdValue ${NS}::rdValue
|
||||
hsetprop $batpath/pos oldval UNKNOWN
|
||||
|
||||
if {$sim_mode == "false"} {
|
||||
sct_mc1 poll $batpath/pos
|
||||
sct_mc1 poll $batpath/action
|
||||
sct_mc1 poll $batpath/status
|
||||
sct_mc1 write $batpath/action
|
||||
}
|
||||
|
||||
# Set hipadaba properties for GumTree interface
|
||||
# and NeXus data file.
|
||||
hsetprop $batpath klass NXaperture
|
||||
::scobj::hinitprops $batObjName
|
||||
hsetprop $batpath/action mutable "false"
|
||||
::scobj::hinitprops $batObjName action
|
||||
}
|
||||
Reference in New Issue
Block a user