Added phase motors for fermi master and slave choppers.

This commit is contained in:
Ferdi Franceschini
2013-05-07 18:51:03 +10:00
parent da0b00c938
commit c50d73740b

View File

@@ -281,10 +281,16 @@ namespace eval ::chopper {
return $speeds
}
proc get_refSpeedRPM {hpath node addr name} {
proc get_setrefSpeedRPM {hpath node addr name {target ""}} {
if {$target == ""} {
set ref_period_50ns [ hval $hpath/$node/ref_period ]
set ref_speed_rpm [ expr { 60.0 / ($ref_period_50ns * 50e-9) } ]
return $ref_speed_rpm
} else {
set ref_period_50ns [expr {60.0 / ($target * 50e-9)} ]
hset $hpath/$node/control/set_ref_period $ref_period_50ns
return $target
}
}
##
# Return nearest allowed speed to target speed
@@ -312,13 +318,13 @@ namespace eval ::chopper {
if {$target >= 0} {
if {$currdir != $CW && $currspeed != 0} {
clientput "ERROR: Tried to change direction when speed != 0. Set motor to idle first."
return -code error
return $SCode(HWFault)
}
set dir $CW
} else {
if {$currdir != $CCW && $currspeed != 0} {
clientput "ERROR: Tried to change direction when speed != 0. Set motor to idle first."
return -code error
return $SCode(HWFault)
}
set dir $CCW
}
@@ -340,6 +346,17 @@ namespace eval ::chopper {
return $SCode(OKOK)
}
proc get_setPeriod {hpath node addr name {target ""}} {
global SCode
if {$target == ""} {
set refPeriod [hval $hpath/$node/ref_period]
return $refPeriod
} else {
hset $hpath/$node/control/set_ref_period $target
return $target
}
}
proc get_setMode {hpath node addr name {target ""}} {
global SCode
if {$target == ""} {
@@ -390,6 +407,9 @@ namespace eval ::chopper {
proc imot_SRun {hpath node addr name target} {
global SCode
set catch_status [ catch {
# imot_status clears the abort flag, but this only happens if imot_status
# is being checked because of a "run" or "drive" when a stop is sent.
hsetprop $hpath/$node abort 0
setSpeed $hpath $node $addr $name $target
hset $hpath/$node/control/start 1
hsetprop $hpath/$node/control timecheck -1
@@ -400,12 +420,13 @@ namespace eval ::chopper {
handle_exception $catch_status $message
}
proc imot_SStatus {hpath node addr name} {
proc imot_Status {hpath node addr name} {
global SCode
set catch_status [ catch {
if [hgetpropval $hpath/$node abort] {
hsetprop $hpath/$node abort 0
error "User requested stop. Aborting operation"
clientput "User requested stop. Aborting operation" ""
return $SCode(HWFault)
}
set readtime [hgetpropval $hpath read_time]
set lastupdate [hgetpropval $hpath lastupdate]
@@ -441,7 +462,7 @@ namespace eval ::chopper {
handle_exception $catch_status $message
}
proc imot_SHalt {hpath node addr name} {
proc imot_Halt {hpath node addr name} {
global SCode
# Don't halt the choppers just because someone tried to interrupt a scan.
if { [GetInt] == "continue" } {
@@ -451,7 +472,7 @@ namespace eval ::chopper {
return $SCode(OKOK)
}
proc imot_SGetError {hpath node addr name} {
proc imot_GetError {hpath node addr name} {
global SCode
return [hgetpropval $hpath/$node errmsg]
}
@@ -463,67 +484,46 @@ namespace eval ::chopper {
}
# Implementation of phase motor interface
proc imot_PhGetPos {hpath node addr name} {
global SCode
set phacc [hval $hpath/$node/phase_acc]
return $phacc
set delay [hval $hpath/$node/ref_delay]
return $delay
}
proc imot_PhRun {hpath node addr name target} {
global SCode
hset $hpath/$node/control/set_ref_delay $target
hset $hpath/$node/control/start 1
hsetprop $hpath/$node/control timecheck -1
set readtime [hgetpropval $hpath read_time]
hsetprop $hpath lastupdate $readtime
return $SCode(OKOK)
}
proc imot_PhStatus {hpath node addr name} {
global SCode
if [hgetpropval $hpath/$node abort] {
hsetprop $hpath/$node abort 0
error "User requested stop. Aborting operation"
}
set readtime [hgetpropval $hpath read_time]
set lastupdate [hgetpropval $hpath lastupdate]
if {$readtime <= $lastupdate} {
return $SCode(HWBusy)
}
hsetprop $hpath lastupdate $readtime
set phase_locked [hval $hpath/$node/system_status/phase_locked]
set timecheck [hgetpropval $hpath/$node/control timecheck]
set timeout [hgetpropval $hpath/$node settletime]
if {$phase_locked} {
if {$timecheck == -1} {
hsetprop $hpath/$node/control timecheck $readtime
return $SCode(HWBusy)
} elseif {[expr $readtime - $timecheck] > $timeout} {
return $SCode(HWIdle)
}
} else {
if {$timecheck != -1} {
hsetprop $hpath/$node/control timecheck $readtime
}
return $SCode(HWBusy)
}
}
proc imot_PhHalt {hpath node addr name} {
global SCode
hsetprop $hpath/$node abort 1
return $SCode(OKOK)
}
proc imot_PhGetError {hpath node addr name} {
global SCode
return "[info level 0]: TODO error message"
}
proc imot_PhFixit {hpath node addr name icode fVal} {
global SCode
return $SCode(MOTOK)
return $SCode(MOTFAIL)
}
proc get_phase_acc {ch} {
variable chPath
set phase_acc [hval $chPath/$ch/phase_acc]
return $phase_acc
}
proc get_phase_rep {ch} {
variable chPath
set phase_rep [hval $chPath/$ch/phase_rep]
return $phase_rep
}
proc get_phase_ok {ch} {
variable chPath
set phase_ok [hval $chPath/$ch/phase_ok]
return $phase_ok
}
##
@@ -552,7 +552,7 @@ namespace eval ::chopper {
}
# Speed motor stop
proc Sstop {hpath node addr name} {
proc stop {hpath node addr name} {
global SCode
hset $hpath/$node/control/stop 1
hsetprop $hpath/$node abort 1
@@ -578,18 +578,19 @@ proc mkFSpeedMot {fmot hdbroot chnode addr lowlim uplim} {
Motor $fmot tclmot [subst {\
getpos "::chopper::imot_SGetpos $hdbroot $chnode $addr"\
run "::chopper::imot_SRun $hdbroot $chnode $addr"\
status "::chopper::imot_SStatus $hdbroot $chnode $addr"\
halt "::chopper::imot_SHalt $hdbroot $chnode $addr"\
geterror "::chopper::imot_SGetError $hdbroot $chnode $addr"\
status "::chopper::imot_Status $hdbroot $chnode $addr"\
halt "::chopper::imot_Halt $hdbroot $chnode $addr"\
geterror "::chopper::imot_GetError $hdbroot $chnode $addr"\
fixit "::chopper::imot_SFixit $hdbroot $chnode $addr"\
refspeed "::chopper::get_refSpeedRPM $hdbroot $chnode $addr"\
refspeed "::chopper::get_setrefSpeedRPM $hdbroot $chnode $addr"\
refperiod "::chopper::get_setPeriod $hdbroot $chnode $addr"\
mode "::chopper::get_setMode $hdbroot $chnode $addr"\
refdelay "::chopper::get_setRefDelay $hdbroot $chnode $addr"\
settle "::chopper::get_setSettleTime $hdbroot $chnode $addr"\
setspeed "::chopper::setSpeed $hdbroot $chnode $addr"\
permspd "::chopper::permSpd $hdbroot $chnode $addr"\
start "::chopper::start $hdbroot $chnode $addr"\
stop "::chopper::Sstop $hdbroot $chnode $addr"\
stop "::chopper::stop $hdbroot $chnode $addr"\
idle "::chopper::idle $hdbroot $chnode $addr"\
}]
hsetprop $hdbroot/$chnode abort 0
@@ -609,16 +610,32 @@ proc mkFPhaseMot {fmot hdbroot chnode addr lowlim uplim} {
Motor $fmot tclmot [subst {\
getpos "::chopper::imot_PhGetPos $hdbroot $chnode $addr"\
run "::chopper::imot_PhRun $hdbroot $chnode $addr"\
status "::chopper::imot_PhStatus $hdbroot $chnode $addr"\
halt "::chopper::imot_PhHalt $hdbroot $chnode $addr"\
geterror "::chopper::imot_PhGetError $hdbroot $chnode $addr"\
status "::chopper::imot_Status $hdbroot $chnode $addr"\
halt "::chopper::imot_Halt $hdbroot $chnode $addr"\
geterror "::chopper::imot_GetError $hdbroot $chnode $addr"\
fixit "::chopper::imot_PhFixit $hdbroot $chnode $addr"\
refspeed "::chopper::get_setrefSpeedRPM $hdbroot $chnode $addr"\
refperiod "::chopper::get_setPeriod $hdbroot $chnode $addr"\
mode "::chopper::get_setMode $hdbroot $chnode $addr"\
refdelay "::chopper::get_setRefDelay $hdbroot $chnode $addr"\
settle "::chopper::get_setSettleTime $hdbroot $chnode $addr"\
setspeed "::chopper::setSpeed $hdbroot $chnode $addr"\
phase_acc "::chopper::get_phase_acc $hdbroot $chnode $addr"\
phase_rep "::chopper::get_phase_rep $hdbroot $chnode $addr"\
phase_ok "::chopper::get_phase_ok $hdbroot $chnode $addr"\
start "::chopper::start $hdbroot $chnode $addr"\
stop "::chopper::stop $hdbroot $chnode $addr"\
idle "::chopper::idle $hdbroot $chnode $addr"\
}]
hsetprop $hdbroot/$chnode abort 0
$fmot movecount 5000
$fmot hardlowerlim $lowlim
$fmot hardupperlim $uplim
$fmot softlowerlim $lowlim
$fmot softupperlim $uplim
sicslist setatt $fmot units degrees
$fmot settle 30
$fmot precision 1
sicslist setatt $fmot units ns
sicslist setatt $fmot klass fermi_chopper
sicslist setatt $fmot long_name $fmot
}
@@ -635,17 +652,22 @@ proc mkFPhaseMot {fmot hdbroot chnode addr lowlim uplim} {
# @param slave, Slave chopper hdb node name
# @param saddr, Slave chopper modbus address
#proc mkFermiMotors {mSpdmot sSpdmot master maddr slave saddr} {
proc mkFermiMotors { mSpdmot master maddr {sSpdmot "EMPTY"} {sPhmot "EMPTY"} {slave "EMPTY"} {saddr "EMPTY"} } {
if {$sSpdmot == "schs"} {
proc mkFermiMotors { master maddr {slave "EMPTY"} {saddr "EMPTY"} } {
set mSpdmot ${master}s
set mPhmot ${master}p
set sSpdmot ${slave}s
set sPhmot ${slave}p
if {$slave != "EMPTY"} {
# Make master and slave choppers
set hdbPath [mkChoppers " $master $maddr $slave $saddr"]
mkFSpeedMot $sSpdmot $hdbPath $slave $saddr -24000 24000
mkFPhaseMot $sPhmot $hdbPath $slave $saddr 0 180
mkFPhaseMot $sPhmot $hdbPath $slave $saddr 0 166.6667e6
} else {
set hdbPath [mkChoppers " $master $maddr"]
}
# Create Master Chopper Speed motor object
mkFSpeedMot $mSpdmot $hdbPath $master $maddr -24000 24000
mkFPhaseMot $mPhmot $hdbPath $master $maddr 0 166.6667e6
}
mkFermiMotors mchs mch 2 schs schp sch 3
mkFermiMotors mch 2 sch 3