Better checks and state machine for Knauer pump

This commit is contained in:
Douglas Clowes
2014-10-07 14:59:21 +11:00
parent 91b7c0b6eb
commit b0e4c3a85b
2 changed files with 175 additions and 24 deletions

View File

@@ -39,6 +39,7 @@ driver knauer_pump = {
readable = 1;
read_command = ' ';
fetch_function = volume_fetch;
read_function = volume_read;
property 'units' = 'mL';
}
var setp = {
@@ -46,6 +47,7 @@ driver knauer_pump = {
writeable = 1;
write_command = ' ';
write_function = volume_write;
check_function = volume_check;
driveable = pump/volume/pval;
checkstatus_function = volume_checkstatus;
halt_function = volume_halt;
@@ -53,6 +55,7 @@ driver knauer_pump = {
readable = 1;
read_command = ' ';
fetch_function = volume_fsm;
read_function = volume_store;
property 'units' = 'mL';
property this_state = 0;
}
@@ -90,7 +93,7 @@ driver knauer_pump = {
# Ensure the pump starts up in REMOTE mode
#
code mkDriver = {%%
hset ${scobj_hpath}/pump/remote 1
#hset ${scobj_hpath}/pump/remote 1
%%}
#
# These functions handle the real_data returned by the pump for the GLP? command
@@ -194,9 +197,21 @@ driver knauer_pump = {
sct geterror "${setpoint} has [llength ${rlist}] components, needs 4"
error [sct geterror]
}
set sum [expr [lindex ${rlist} 0] + [lindex ${rlist} 1] + [lindex ${rlist} 2] + [lindex ${rlist} 3]]
set sum 0
for {set i 0} {$i < 4} {incr i} {
set cmp [lindex ${rlist} ${i}]
if { ![string is integer -strict ${cmp}] } {
sct geterror "component [expr {${i} + 1}] is not integer: \"${cmp}\""
error [sct geterror]
}
if { !(${cmp} >= 0 && ${cmp} <= 100) } {
sct geterror "component [expr {${i} + 1}] is not between 0 and 100: \"${cmp}\""
error [sct geterror]
}
set sum [expr {${sum} + ${cmp}}]
}
if { ${sum} != 100 } {
sct geterror "sum is ${sum}, must be 100"
sct geterror "sum of components is ${sum}, must be 100"
error [sct geterror]
}
%%}
@@ -262,7 +277,6 @@ driver knauer_pump = {
%%}
code volume_write = {%%
hsetprop ${tc_root}/[sct driveable] base_volume [hgetpropval ${tc_root}/[sct driveable] raw_volume]
hset ${tc_root}/[sct driveable] 0.0
set cmd "REMOTE"
sct this_state 1
@@ -283,20 +297,25 @@ driver knauer_pump = {
set time_tgt [expr {int(60000.0 * 1000.0 * [sct target] / ${flow_tgt})}]
set time_1 [expr {${time_tgt} - 500}]
set time_2 [expr {${time_tgt} + 500}]
set nextState noResponse
set saveState ${nextState}
set nextState "noResponse"
if { [sct this_state] == 1 } {
set cmd "TT_LOAD:1"
set cmd "GLP?"
set nextState ${saveState}
sct this_state [expr {[sct this_state] + 1}]
} elseif { [sct this_state] == 2 } {
set cmd "TT_SET:0,0,${flow_tgt},${ratio_tgt},0,0,0,0,0,0,0,0"
set cmd "TT_LOAD:1"
sct this_state [expr {[sct this_state] + 1}]
} elseif { [sct this_state] == 3 } {
set cmd "TT_SET:1,${time_1},${flow_tgt},${ratio_tgt},0,0,0,0,0,0,0,0"
set cmd "TT_SET:0,0,${flow_tgt},${ratio_tgt},0,0,0,0,0,0,0,0"
sct this_state [expr {[sct this_state] + 1}]
} elseif { [sct this_state] == 4 } {
set cmd "TT_SET:2,${time_2},0,${ratio_tgt},0,0,0,0,0,0,0,0"
set cmd "TT_SET:1,${time_1},${flow_tgt},${ratio_tgt},0,0,0,0,0,0,0,0"
sct this_state [expr {[sct this_state] + 1}]
} elseif { [sct this_state] == 5 } {
set cmd "TT_SET:2,${time_2},0,${ratio_tgt},0,0,0,0,0,0,0,0"
sct this_state [expr {[sct this_state] + 1}]
} elseif { [sct this_state] == 6 } {
set cmd "START:1,0"
sct this_state 0
} elseif { [sct this_state] == 91 } {
@@ -304,6 +323,13 @@ driver knauer_pump = {
sct this_state 92
} elseif { [sct this_state] == 92 } {
set cmd "STOP:0,0"
sct this_state 93
} elseif { [sct this_state] == 93 } {
if { !([hpropexists ${tc_root}/pump/remote target] && [hgetpropval ${tc_root}/pump/remote target] == 1) } {
set cmd "LOCAL"
} else {
set cmd "@@NOSEND@@"
}
sct this_state 0
} else {
sct this_state 0
@@ -331,6 +357,25 @@ driver knauer_pump = {
}
%%}
code volume_store = {%%
if { [sct this_state] == 2 } {
set ns [namespace current]
# store the GLP result
hsetprop ${tc_root}/dummy/glp result "${data}"
sct with ${tc_root}/dummy/glp "${ns}::read_glp ${tc_root}"
# extract the volume
sct with ${tc_root}/[sct driveable] "${ns}::volume_fetch ${tc_root} ${nextState} @@NOSEND@@"
sct with ${tc_root}/[sct driveable] "${ns}::volume_read ${tc_root}"
# copy it to base_volume
hsetprop ${tc_root}/[sct driveable] base_volume [hgetpropval ${tc_root}/[sct driveable] raw_volume]
}
if { [hpropexists [sct] target] } {
set data [sct target]
} else {
set data 0.0
}
%%}
code volume_halt = {%%
set cmd "STOP:0,0"
sct this_state 91