Add tank position and set vessel_y SICS variable for Ltof calculation.

This commit is contained in:
Ferdi Franceschini
2014-06-10 19:24:57 +10:00
parent ea7f7b8b9d
commit 1baf4faa90
2 changed files with 108 additions and 4 deletions

View File

@ -81,6 +81,53 @@ proc ::scobj::tank::noResponse {tc_root} {
handle_exception ${catch_status} ${catch_message}
}
# function to parse the read of a parameter on a device
proc ::scobj::tank::read_pos {tc_root} {
set catch_status [ catch {
debug_log ${tc_root} 1 "read_pos tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
set data [sct result]
set nextState "idle"
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
# the protocol driver has reported an error
sct geterror "${data}"
error "[sct geterror]"
}
# read_pos hook code starts
global tank_absenchome tank_cnts_per_x tank_home
if { [string equal -nocase -length 1 "${data}" "?"] } {
sct geterror "Galil error in: '${data}'"
} else {
set data_list [split [string trim "${data}"]]
if { [llength ${data_list}] > 1 && [lindex ${data_list} end] == ":" } {
set data_list [lrange ${data_list} 0 0]
}
if { [llength ${data_list}] == 1 } {
set absenc [unpad [lindex ${data_list} 0]]
set data [expr {($absenc - $tank_absenchome) / $tank_cnts_per_x + $tank_home}]
vessel_y $data
} else {
sct geterror "Syntax error in: '${data}'=>'${data_list}'"
}
}
# read_pos hook code ends
if { [hpropexists [sct] geterror] } {
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log ${tc_root} 1 "[sct] changed to new:${data}, from old:[sct oldval]"
sct oldval ${data}
sct update ${data}
sct utime readtime
}
return ${nextState}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
# function to parse the read of a parameter on a device
proc ::scobj::tank::read_switch {tc_root} {
set catch_status [ catch {
@ -166,6 +213,24 @@ proc ::scobj::tank::mkDriver { sct_controller name } {
set scobj_hpath /sics/${name}
hfactory ${scobj_hpath}/pos plain spy float
hsetprop ${scobj_hpath}/pos read ${ns}::getValue ${scobj_hpath} read_pos {MG _TPH}
hsetprop ${scobj_hpath}/pos read_pos ${ns}::read_pos ${scobj_hpath}
hsetprop ${scobj_hpath}/pos control true
hsetprop ${scobj_hpath}/pos data true
hsetprop ${scobj_hpath}/pos mutable true
hsetprop ${scobj_hpath}/pos nxsave true
hsetprop ${scobj_hpath}/pos oldval 0.0
hsetprop ${scobj_hpath}/pos sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/pos type "part"
hsetprop ${scobj_hpath}/pos nxalias "${name}_pos"
if {[string equal -nocase [SplitReply [motor_simulation]] "false"]} {
${sct_controller} poll ${scobj_hpath}/pos 1
} else {
::scobj::tank::sics_log 9 "[motor_simulation] => No poll/write for tank"
}
hfactory ${scobj_hpath}/limits plain spy none
hfactory ${scobj_hpath}/limits/forward plain user text
@ -192,9 +257,11 @@ proc ::scobj::tank::mkDriver { sct_controller name } {
hsetprop ${scobj_hpath}/limits/reverse type "part"
hsetprop ${scobj_hpath}/limits/reverse nxalias "${name}_limits_reverse"
if {[SplitReply [motor_simulation]]=="false"} {
if {[string equal -nocase [SplitReply [motor_simulation]] "false"]} {
${sct_controller} poll ${scobj_hpath}/limits/forward 1
${sct_controller} poll ${scobj_hpath}/limits/reverse 1
} else {
::scobj::tank::sics_log 9 "[motor_simulation] => No poll/write for tank"
}
hfactory ${scobj_hpath}/switches plain spy none
@ -223,13 +290,16 @@ proc ::scobj::tank::mkDriver { sct_controller name } {
hsetprop ${scobj_hpath}/switches/reverse type "part"
hsetprop ${scobj_hpath}/switches/reverse nxalias "${name}_switches_reverse"
if {[SplitReply [motor_simulation]]=="false"} {
if {[string equal -nocase [SplitReply [motor_simulation]] "false"]} {
${sct_controller} poll ${scobj_hpath}/switches/forward 1
${sct_controller} poll ${scobj_hpath}/switches/reverse 1
} else {
::scobj::tank::sics_log 9 "[motor_simulation] => No poll/write for tank"
}
hsetprop ${scobj_hpath} klass instrument
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code starts
::utility::mkVar vessel_y float user vessel_y true instrument true true
# mkDriver hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message}
@ -245,7 +315,7 @@ namespace eval ::scobj::tank {
proc add_tank {name IP port} {
set catch_status [ catch {
::scobj::tank::sics_log 9 "add_tank ${name} ${IP} ${port}"
if {[SplitReply [motor_simulation]]=="false"} {
if {[string equal -nocase [SplitReply [motor_simulation]] "false"]} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
::scobj::tank::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
@ -253,6 +323,8 @@ proc add_tank {name IP port} {
::scobj::tank::sics_log 9 "makesctcontroller sct_${name} dmc2280 ${IP}:${port}"
makesctcontroller sct_${name} dmc2280 ${IP}:${port}
}
} else {
::scobj::tank::sics_log 9 "[motor_simulation] => No sctcontroller for tank"
}
::scobj::tank::sics_log 1 "::scobj::tank::mkDriver sct_${name} ${name}"
::scobj::tank::mkDriver sct_${name} ${name}
@ -271,7 +343,10 @@ proc ::scobj::tank::read_config {} {
if { [dict get $v "driver"] == "tank" } {
if { [dict get $v enabled] } {
set name [dict get $v name]
if { [dict exists $v "asyncqueue"] } {
if { ![string equal -nocase [SplitReply [motor_simulation]] "false"] } {
set asyncqueue "null"
${ns}::sics_log 9 "[motor_simulation] => using null asyncqueue"
} elseif { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {

View File

@ -12,6 +12,16 @@ driver tank = {
#
# The named group is at the device level, variables below that
#
group = {
var pos = {
type = float;
priv = spy;
mutable = true;
readable = 1;
read_function = read_pos;
read_command = 'MG _TPH';
}
}
group switches = {
type = text;
priv = user;
@ -61,9 +71,28 @@ driver tank = {
@ }
@ }
}
code read_function read_pos = {
@ global tank_absenchome tank_cnts_per_x tank_home
@ if { [string equal -nocase -length 1 "${data}" "?"] } {
@ sct geterror "Galil error in: '${data}'"
@ } else {
@ set data_list [split [string trim "${data}"]]
@ if { [llength ${data_list}] > 1 && [lindex ${data_list} end] == ":" } {
@ set data_list [lrange ${data_list} 0 0]
@ }
@ if { [llength ${data_list}] == 1 } {
@ set absenc [unpad [lindex ${data_list} 0]]
@ set data [expr {($absenc - $tank_absenchome) / $tank_cnts_per_x + $tank_home}]
@ vessel_y $data
@ } else {
@ sct geterror "Syntax error in: '${data}'=>'${data_list}'"
@ }
@ }
}
#
# This code is after database creation
#
code mkDriver = {
@ ::utility::mkVar vessel_y float user vessel_y true instrument true true
}
};