Merge Platypus changes into RELEASE-3_1

This commit is contained in:
Douglas Clowes
2014-10-22 12:15:04 +11:00
3 changed files with 38 additions and 86 deletions

View File

@ -1,6 +1,10 @@
# Author: Ferdi Franceschini (ffr@ansto.gov.au)
# TODO Handle sequencing when simultaneously moving multiple axes
# TODO Handle functional dependencies (just write your own tcl script)
# or get the generic acscript to call a user proc
# FIXME The anticollider module does not report the error messages from the
# anticollision script, we currently get around this by using broadcast.
AntiCollisionInstall
namespace eval anticollider {
@ -9,54 +13,19 @@ namespace eval anticollider {
array unset ::anticollider::veto_region
array set ::anticollider::veto_region ""
# Don't show 'acscript' call on error. This is done by the anticollider
# module.
proc handle_acscript_exception {status message args} {
switch $status {
0 {
# TCL_OK, This is raised when you just drop out of the
# bottom of a 'catch' command.
return -code ok
}
1 {
# TCL_ERROR
return -code error "$message: $args"
}
2 {
# TCL_RETURN
return -code return "$message"
}
3 {
# TCL_BREAK
return -code break
}
4 {
# TCL_CONTINUE
return -code continue
}
default {
# Propogate user defined return codes with message
return -code $status "$message"
}
}
}
##
# @brief Load an anticollider script
proc ::anticollider::loadscript {args} {
variable veto_rules
variable prog
set prog ""
catch {
set fh [open $::cfPath(anticollider)/[lindex $args 0] RDONLY ]
while {[gets $fh line] >= 0} {
# Skip empty lines and comments
if [regexp {^\s*$|^ *#} $line] {
continue
}
lappend veto_rules $line
set fh [open $::cfPath(anticollider)/[lindex $args 0] RDONLY ]
while {[gets $fh line] >= 0} {
# Skip empty lines and comments
if [regexp {^\s*$|^ *#} $line] {
continue
}
}
catch {
close $fh
lappend prog $line
}
}
@ -64,7 +33,7 @@ proc ::anticollider::loadscript {args} {
# @brief Compile compile an anticollider declaration into a veto region table
# for the anticollider script.
#
# @param veto_rules, an anticollider declaration as a list of quote enclosed lines.
# @param vprog, an anticollider declaration as a list of quote enclosed lines.
# @return Generates the ::anticollider::veto_region lookup table.
#
# Example\n
@ -75,16 +44,14 @@ proc ::anticollider::loadscript {args} {
# for sphi forbid { {0 5} {10 15} } when schi in { {5 10} {15 20} }\n
# forbid {-inf 5} when mtth in {0 10} for sphi\n
# forbid {0 10} for samx whenall { samrot in {0 5} samy in {0 15} }\n
proc ::anticollider::genveto {veto_rules} {
proc ::anticollider::genveto {vprog} {
variable veto_region
array unset veto_region
set lnum 1
foreach line $veto_rules {
foreach line $vprog {
array unset vp
array set vp $line
clientput "::anticollider::veto_rule: $line"
if [info exists vp(whenall)] {
foreach {mot in range} $vp(whenall) {
# if {[llength [join $range]] != 2} {
@ -121,14 +88,16 @@ proc ::anticollider::enable {args} {
#
# The ::anticollider::veto_region is a hash indexed by the names of the motors
# which have been registered with the anticollision module.
proc ::anticollider::veto_region_acscript {args} {
proc ::anticollider::acscript {args} {
variable veto_region
set catch_status [ catch {
foreach {regmot target} $args {
if { ! [info exists veto_region($regmot)] } {
continue
if {[::anticollider::enable $args] == "false"} {
foreach {regmot target} $args {
anticollision add 0 $regmot $target
}
return
}
foreach {regmot target} $args {
foreach row $veto_region($regmot) {
if { [lindex $row 1] == "@and"} {
set forbid [lindex $row 0]
@ -147,6 +116,7 @@ proc ::anticollider::veto_region_acscript {args} {
} else {
foreach {min max} $forbid {}
if {$min <= $target && $target <= $max} {
broadcast "ERROR:The range ($forbid) is forbidden for $regmot when [lindex $row 2]"
error "ERROR:The range ($forbid) is forbidden for $regmot when [lindex $row 2]"
}
}
@ -156,14 +126,17 @@ proc ::anticollider::veto_region_acscript {args} {
if {$obstrange == "@all"} {
foreach {min max} [join $forbidden_range] {
if {$min <= $target && $target <= $max} {
broadcast "ERROR: $regmot target ($target) is in the forbidden region ($forbidden_range)"
error "ERROR: $regmot target ($target) is in the forbidden region ($forbidden_range)"
}
}
} else {
broadcast "ERROR: veto table must use @all with @any"
error "ERROR: veto table must use @all with @any"
}
} else {
if {$obstrange == "@all"} {
broadcast "ERROR: veto table must use @any with @all"
error "ERROR: veto table must use @any with @all"
} else {
foreach {lower upper} [join $obstrange] {
@ -171,6 +144,7 @@ proc ::anticollider::veto_region_acscript {args} {
if {$lower <= $pos && $pos <= $upper} {
foreach {min max} [join $forbidden_range] {
if {$min <= $target && $target <= $max} {
broadcast "ERROR:The range $min to $max is forbidden for $regmot when $obstmot is in this region ($obstrange)"
error "ERROR:The range $min to $max is forbidden for $regmot when $obstmot is in this region ($obstrange)"
}
@ -182,9 +156,8 @@ proc ::anticollider::veto_region_acscript {args} {
}
}
}
anticollision add 0 $regmot $target
}
} message ]
handle_exception $catch_status $message
}
##
@ -193,37 +166,16 @@ proc ::anticollider::init {} {
variable evp
variable veto_region
set catch_status [ catch {
if { ![info exists ::anticollider::veto_rules] } {
return
}
clientput Load anticollider rules:
if { [info procs ::anticollider::load_acrules] == "::anticollider::load_acrules" } {
::anticollider::load_acrules
}
::anticollider::genveto $::anticollider::veto_rules
if [ catch {
::anticollider::genveto $::anticollider::prog
foreach motor [array names veto_region] {
anticollision register $motor
}
} message ]
handle_exception $catch_status $message
}
lappend ::anticollider::scripts ::anticollider::veto_region_acscript
proc ::anticollider::acscript {args} {
set catch_status [ catch {
if {[::anticollider::enable $args] == "false"} {
return
} else {
foreach {regmot target} $args {
anticollision add 0 $regmot $target
}
}
foreach script $::anticollider::scripts {
$script {*}$args
}
} message ]
handle_acscript_exception $catch_status $message
} message ] {
clientput [info level 0] ERROR: $message
if {$::errorCode=="NONE"} {return $message}
return -code error $message
}
}
publish ::anticollider::acscript user

View File

@ -33,7 +33,7 @@ proc ::scobj::bruker::mkDriver { sct_controller name device_class simulation_fla
set catch_status [ catch {
# mkWrapper hook code starts
add_bruker_BEC1 $name $ip_address $tcp_port $tol
add_bruker_bec1 $name $ip_address $tcp_port $tol
# mkWrapper hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message}

View File

@ -455,7 +455,7 @@ debug_log "Registering node $nodeName for write callback"
hsetprop $scobj_hpath device "$dev"
set deviceCommand {\
Display Position 1 0 1 1 0 text internal {LQP} {rdValue} {} {} {}\
Display Position 1 0 1 1 0 int internal {LQP} {rdValue} {} {} {}\
Display Angle 1 0 1 1 0 text internal {LQA} {rdValue} {} {} {}\
Display Hertz 1 0 1 1 0 text internal {LQF} {rdValue} {} {} {}\
Display Finished 1 0 1 1 0 text internal {F} {rdValue} {} {} {}\
@ -465,7 +465,7 @@ debug_log "Registering node $nodeName for write callback"
Display Device 1 0 1 1 0 text internal {E3} {rdValue} {} {} {}\
Display Encoder 1 0 1 1 0 text internal {E4} {rdValue} {} {} {}\
Control Direction 0 1 1 1 0 text user {} {} {} {setDirn} {}\
Control SetPoint 0 1 1 1 1 text user {} {} {} {setPoint} {}\
Control SetPoint 0 1 1 1 1 int user {} {} {} {setPoint} {}\
Control Command 0 1 1 1 0 text user {} {} {} {setCmnd.chkWrite} {}\
}