sct_fermichopper.tcl

Refactored to enable creation master and slave chopper objects and added
a mkChoppers command.

r3749 | ffr | 2012-09-26 10:02:12 +1000 (Wed, 26 Sep 2012) | 4 lines
This commit is contained in:
Ferdi Franceschini
2012-09-26 10:02:12 +10:00
committed by Douglas Clowes
parent b887636684
commit 99c3c397d3

View File

@@ -6,7 +6,7 @@ namespace eval ::scobj::chopper {
# sicslist setatt disk_chopper long_name disk_chopper
proc sndMBquery {rdScript cmd nextReq} {
set chN [sct chopper]
set chN [ lindex [sct P_chAddress] [sct P_chIndex] ]
sct nextSndReq $nextReq
sct send "$chN:$cmd"
return $rdScript
@@ -20,16 +20,17 @@ proc sndMBset {root cmd} {
return RDSETREPLY
}
proc rdStatus {root statnode fields} {
set currCh [sct chopper]
set chPath $root/ch$currCh/$statnode
set oldval [hgetpropval $chPath oldval]
set currCh [ lindex [sct P_name] [sct P_chIndex] ]
set chPath $root/$currCh/$statnode
set oldval [hgetpropval $chPath P_oldval]
set val [sct result]
if {[string match "ASCERR:*" $val]} {
sct geterror $val
return idle
}
if {$val != $oldval} {
hsetprop $chPath oldval $val
sct update 1
hsetprop $chPath P_oldval $val
binary scan [binary format c $val] B* binNum
set bitfield [split $binNum ""]
foreach n $fields b $bitfield {
@@ -38,60 +39,27 @@ proc rdStatus {root statnode fields} {
}
return [sct nextSndReq]
}
proc rdSysStatus {root nodes} {
# Read status byte and set nodes for each bit
set currCh [sct chopper]
set chPath $root/ch$currCh/system_status
set oldval [hgetpropval $chPath oldval]
proc rdCoil {root node coil} {
set chIndex [sct P_chIndex]
set currCh [ lindex [sct P_name] $chIndex ]
set val [sct result]
if {[string match "ASCERR:*" $val]} {
sct geterror $val
return idle
}
set cAddr [expr $coil - 1]
set coilPath $root/$currCh/$node
set oldval [hgetpropval $coilPath P_oldval]
if {$val != $oldval} {
hsetprop $chPath oldval $val
binary scan [binary format c $val] B* binNum
set bitfield [split $binNum ""]
binary scan [binary format c $oldval] B* oldbinNum
set oldbitfield [split $oldbinNum ""]
foreach n $nodes b $bitfield ob $oldbitfield {
if {$b != $ob} {
hset $chPath/$n $b
}
}
}
return [sct nextSndReq]
}
proc rdIntLkStatus {root nodes} {
# Read status byte and set nodes for each bit
set currCh [sct chopper]
set chPath $root/ch$currCh/intlck_status
set oldval [hgetpropval $chPath oldval]
set val [sct result]
if {[string match "ASCERR:*" $val]} {
sct geterror $val
return idle
}
if {$val != $oldval} {
hsetprop $chPath oldval $val
binary scan [binary format c $val] B* binNum
set bitfield [split $binNum ""]
binary scan [binary format c $oldval] B* oldbinNum
set oldbitfield [split $oldbinNum ""]
foreach n $nodes b $bitfield ob $oldbitfield {
if {$b != $ob} {
hset $chPath/$n $b
}
}
hsetprop $coilPath P_oldval $val
}
return [sct nextSndReq]
}
##
# Reads a list of values in the result and assigns them to the nodes in the args list
proc rdVal {root nodes} {
set currCh [sct chopper]
set chIndex [sct P_chIndex]
set currCh [ lindex [sct P_name] $chIndex ]
set values [sct result]
set chPath $root/ch$currCh
set chPath $root/$currCh
if {[string match "ASCERR:*" $values]} {
sct geterror $values
hset $chPath/device_error $values
@@ -102,23 +70,17 @@ proc rdVal {root nodes} {
}
foreach n $nodes v $values {
set oldval [hval $chPath/$n]
# if {$n == "speed_setpt"} {
# broadcast rdVal,$n $chPath/$n: oldval=$oldval, v=$v
# }
if {$v != $oldval} {
# if {$n == "speed_setpt"} {
# broadcast rdVal,$n: hset $chPath/$n $v
# }
hset $chPath/$n $v
}
}
set nextReq [sct nextSndReq]
if {$nextReq == "NXTCHOPPER"} {
if {$currCh < [sct chMax] } {
incr currCh
sct chopper $currCh
incr chIndex
if {$chIndex < [sct P_numChops] } {
sct P_chIndex $chIndex
} else {
sct chopper 1
sct P_chIndex 0
return idle
}
}
@@ -138,49 +100,66 @@ proc rdSetCmdReply {root chPath} {
sct_fermi queue $root progress read
return idle
}
# Create chopper control
##
# @brief Make fermi chopper driver
#
# @param nm_addr_list, list of chopper names and modbus addresses eg mkChoppers {mch 1 sch 2}
proc mkChoppers {nm_addr_list} {
set scobjNS ::scobj::chopper
set sim_mode false
set pollrate 5
MakeSICSObj fermi_chopper SCT_OBJECT user int
foreach {n a} $nm_addr_list {
lappend chopperName $n
lappend chAddress $a
}
set numChops [llength $chAddress]
MakeSICSObj fermi_chopper SCT_OBJECT
sicslist setatt fermi_chopper klass NXfermi_chopper
variable fermiPath
set fermiPath /sics/fermi_chopper
::scobj::hinitprops fermi_chopper
set sim_mode false
if {$sim_mode == "false"} {
makesctcontroller sct_fermi tcpmodbus 137.157.202.213:502
}
hsetprop $fermiPath chopper 1
hsetprop $fermiPath P_chIndex 0
set intlck_fields {test_mode cc_shutdown_req dsp_summ_shtdwn cooling_loss spd_sensor_loss ref_sig_loss over_temp vac_fail overspeed_or_breakfail cc_wd_fail ext_fault ups_fail emerg_stop pos_alarm osc_fail dsp_wd_fail}
set intlck_fields {test_mode cc_shutdown_req dsp_summ_shtdwn cooling_loss spd_sensor_loss ref_sig_loss over_temp vac_fail overspeed_or_brakefail cc_wd_fail ext_fault ups_fail emerg_stop pos_alarm osc_fail dsp_wd_fail}
set chMax 1
hsetprop $fermiPath chMax $chMax
for {set chN 1} {$chN <= $chMax} {incr chN} {
set chname ch$chN
hsetprop $fermiPath P_numChops $numChops
hsetprop $fermiPath P_chAddress $chAddress
hsetprop $fermiPath P_name $chopperName
variable fermiPath
foreach {chname chN} $nm_addr_list {
# set chname [lindex $chopperName [expr $chN - 1]]
sicslist setatt fermi_chopper klass NXfermi_chopper
sicslist setatt fermi_chopper long_name fermi_chopper
hfactory $fermiPath/$chname plain user float
hfactory $fermiPath/$chname plain user none
set chPath $fermiPath/$chname
hfactory $chPath/device_error plain user text
foreach field {
system_status intlck_status rotation_speed
phase_veto_count phase_nonveto_count phase_acc
phase_rep phase_ok vetowin100ns
vetowin50ns mode speed_setpt
prop_gain int_gain phase_gain
ref_delay ref_period sync_srce motdir idle_toggle
rotation_speed phase_veto_count phase_nonveto_count phase_acc phase_rep
phase_ok vetowin100ns vetowin50ns mode speed_setpt
prop_gain int_gain phase_gain ref_delay ref_period
sync_srce motdir
} {
hfactory $fermiPath/$chname/$field plain user float
}
hsetprop $chPath/system_status oldval "UNKNOWN"
hsetprop $chPath/intlck_status oldval "UNKNOWN"
hfactory $fermiPath/$chname/idle_toggle plain user int
hsetprop $chPath/idle_toggle P_oldval "UNKNOWN"
hfactory $fermiPath/$chname/system_status plain user none
hsetprop $chPath/system_status P_oldval "UNKNOWN"
foreach field {
avc_on motdir phase_locked lev_complete alarm run up_to_speed ok
} {
hfactory $fermiPath/$chname/system_status/$field plain user int
}
hfactory $fermiPath/$chname/intlck_status plain user none
hsetprop $chPath/intlck_status P_oldval "UNKNOWN"
foreach field $intlck_fields {
hfactory $fermiPath/$chname/intlck_status/$field plain user int
}
@@ -213,37 +192,45 @@ set chname ch$chN
}
}
}
# Each Req chains to a rdVal proc which chains to the next req
# Add a next state property
#TODO Read idle_toggle status
hsetprop $fermiPath nextSndReq "UNKNOWN"
hsetprop $fermiPath read ${scobjNS}::sndMBquery "RDSYSSTAT" "3:10:1:U16" "INTLKREQ"
hsetprop $fermiPath "NXTCHOPPER" ${scobjNS}::sndMBquery "RDSYSSTAT" "3:10:1:U16" "INTLKREQ"
hsetprop $fermiPath "INTLKREQ" ${scobjNS}::sndMBquery "RDINTLKSTAT" "3:12:1:U16" "ROTSPDREQ"
hsetprop $fermiPath "ROTSPDREQ" ${scobjNS}::sndMBquery "RDROTSPD" "3:14:1:U16" "VETOINF"
hsetprop $fermiPath "INTLKREQ" ${scobjNS}::sndMBquery "RDINTLKSTAT" "3:12:1:U16" "IDLETOGGLE"
hsetprop $fermiPath "IDLETOGGLE" ${scobjNS}::sndMBquery "RDIDLE" "1:3:1" "VETOINF"
hsetprop $fermiPath "VETOINF" ${scobjNS}::sndMBquery "RDVETOINF" "3:18:2:U32" "PHASEINF"
hsetprop $fermiPath "PHASEINF" ${scobjNS}::sndMBquery "RDPHASEINF" "3:24:3:F32" "VETO"
hsetprop $fermiPath "VETO" ${scobjNS}::sndMBquery "RDVETO" "3:30:3:U32" "ROTSPSET"
hsetprop $fermiPath "ROTSPSET" ${scobjNS}::sndMBquery "RDROTSPSET" "3:1000:1:U32" "GAINPHASE"
hsetprop $fermiPath "GAINPHASE" ${scobjNS}::sndMBquery "RDGAINPHASE" "3:1004:3:F32" "SYNMOTDIR"
hsetprop $fermiPath "SYNMOTDIR" ${scobjNS}::sndMBquery "RDSYNMOTDIR" "3:1010:4:U32" "IDLETOGGLE"
hsetprop $fermiPath "IDLETOGGLE" ${scobjNS}::sndMBquery "RDIDLE" "1:3:1" "NXTCHOPPER"
hsetprop $fermiPath "SYNMOTDIR" ${scobjNS}::sndMBquery "RDSYNMOTDIR" "3:1010:4:U32" "ROTSPDREQ"
hsetprop $fermiPath "ROTSPDREQ" ${scobjNS}::sndMBquery "RDROTSPD" "3:14:1:U16" "NXTCHOPPER"
hsetprop $fermiPath "RDSYSSTAT" ${scobjNS}::rdStatus $fermiPath system_status {avc_on motdir phase_locked lev_complete alarm run up_to_speed ok}
hsetprop $fermiPath "RDINTLKSTAT" ${scobjNS}::rdStatus $fermiPath intlck_status $intlck_fields
hsetprop $fermiPath "RDROTSPD" ${scobjNS}::rdVal $fermiPath rotation_speed
hsetprop $fermiPath "RDVETOINF" ${scobjNS}::rdVal $fermiPath {phase_veto_count phase_nonveto_count}
hsetprop $fermiPath "RDIDLE" ${scobjNS}::rdCoil $fermiPath idle_toggle 3
hsetprop $fermiPath "RDPHASEINF" ${scobjNS}::rdVal $fermiPath {phase_acc phase_rep phase_ok}
hsetprop $fermiPath "RDVETO" ${scobjNS}::rdVal $fermiPath {vetowin100ns vetowin50ns mode}
hsetprop $fermiPath "RDROTSPSET" ${scobjNS}::rdVal $fermiPath speed_setpt
hsetprop $fermiPath "RDGAINPHASE" ${scobjNS}::rdVal $fermiPath {prop_gain int_gain phase_gain}
hsetprop $fermiPath "RDSYNMOTDIR" ${scobjNS}::rdVal $fermiPath {ref_delay ref_period sync_srce motdir}
hsetprop $fermiPath "RDIDLE" ${scobjNS}::rdVal $fermiPath idle_toggle
hsetprop $fermiPath "RDVETOINF" ${scobjNS}::rdVal $fermiPath {phase_veto_count phase_nonveto_count}
if {$sim_mode == "false"} {
sct_fermi poll $fermiPath $pollrate
sct_fermi queue $fermiPath progress read
}
return $fermiPath
}
namespace export mkChoppers
}
namespace import ::scobj::chopper::*
# mkChoppers { mch 1 sch 2 }