Implement the Ltof_<det> time of flight length calculations and the nguide selection command.

This commit is contained in:
Ferdi Franceschini
2014-06-17 12:08:29 +10:00
parent 2996889ea5
commit e0edfb8d0a

View File

@ -21,3 +21,294 @@ sicslist setatt att_pos klass instrument
# make gap/offset motors for the slits
make_gap_motors ss1hg gap ss1ho offset ss1r ss1l mm first/horizontal
make_gap_motors ss1vg gap ss1vo offset ss1u ss1d mm first/vertical
## Time of flight calculation
# Length of a guide
::utility::mkVar lenguide float user lenguide true instrument true true
# Space between guides
::utility::mkVar spaceguide float user spaceguide true instrument true true
# Distance from chopper 4 to pc1 the first guide translation table.
::utility::mkVar lch4_pc1 float user lch4_pc1 true instrument true true
# \fn float nguide [num]
# \brief Macro which reports and sets the number of selected guides.
#
# When called without arguments it counts the number of consecutively selected
# guides starting from guide number eight (sample end).
# When called with num it will select num guides starting from guided eight and
# drive the other guides to the aperture position with all the aperture arms
# raised.
# \param num (optional) Number of guides to be selected.
# \return The number of selected guides or an error message
::utility::macro::getset float nguide { {num "REPORTNUM"} } {
set catch_status [ catch {
set FINDFIRST 1
set COUNT 2
set CheckDrive 0
array set EMSG {
invalidarg "Invalid argument"
gaps "There are gaps in the sequence of selected guides"
drivefailed "Drive failed."
misaligned "Misalignment. At least one guide is not in the aperture or guide position"
}
set guideposit 1
set apposit 2
set tol 0.1
set ng 0
set state $FINDFIRST
set apdrvlist {ap1 1 ap2 1 ap3 1 ap4 1 ap5 1 ap6 1 ap7 1 ap8 1}
set pcdrvlist {}
if {$num != "REPORTNUM"} {
if {$num >= 0 && $num <= 8} {
set CheckDrive true
set last 8
for {set n 1} {$n <= $num} {incr n } {
set currpos [SplitReply [pc$last]]
set table_guideunit [SplitReply [pc$last posit2unit $guideposit]]
if {[expr {abs($currpos - $table_guideunit)}] > $tol} {
lappend pcdrvlist c$last $guideposit
}
incr last -1
}
for {set n [expr 8 - $num]} {$n >= 1} {incr n -1} {
set currpos [SplitReply [pc$n]]
set table_guideunit [SplitReply [pc$n posit2unit $apposit]]
if {[expr {abs($currpos - $table_guideunit)}] > $tol} {
lappend pcdrvlist c$n $apposit
}
}
if {[llength $apdrvlist] > 0} {
eval "drive $apdrvlist"
}
if {[llength $pcdrvlist] > 0} {
eval "drive $pcdrvlist"
}
} else {
error "$EMSG(invalidarg)"
}
}
for {set n 1} {$n <= 8} {incr n} {
set currpos [SplitReply [pc$n]]
set table_guideunit [SplitReply [pc$n posit2unit $guideposit]]
set table_appunit [SplitReply [pc$n posit2unit $apposit]]
switch $state [subst {
$FINDFIRST {
if {[expr {abs($currpos - $table_appunit)}] <= $tol} {
continue
} elseif {[expr {abs($currpos - $table_guideunit)}] <= $tol} {
incr ng
set state $COUNT
} else {
error "$EMSG(misaligned)"
}
}
$COUNT {
if {[expr {abs($currpos - $table_guideunit)}] <= $tol} {
incr ng
} else {
# ERROR There shouldn't be any gaps in the selection
error "$EMSG(gaps)"
}
}
}]
}
if {$CheckDrive} {
if {$ng != $num} {
error "$EMSG(drivefailed)"
}
}
return "[lindex [info level 0] 0] = $ng"
} message ]
handle_exception $catch_status $message
}
sicslist setatt nguide klass instrument
sicslist setatt nguide long_name nguide
::utility::macro::getset float L1 {} {
set catch_status [ catch {
set lg [SplitReply [lenguide]]
set sg [SplitReply [spaceguide]]
set ng [SplitReply [nguide]]
set sy [SplitReply [samy]]
set retval [expr {$lg * (8.0 - $ng) + $sg * ($ng - 1) + 612.5 + $sy}]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt L1 klass instrument
sicslist setatt L1 long_name L1
proc L2 {det} {
set catch_status [ catch {
set vy [SplitReply [vessel_y]]
set sy [SplitReply [samy]]
set cd [SplitReply [curtaindet]]
switch $det {
"maindet" {
set detpos [SplitReply [det]]
}
"curtainl" {
set detpos [expr {$::curtainl_yoffset + $cd}]
}
"curtainr" {
set detpos [expr {$::curtainr_yoffset + $cd}]
}
"curtainu" {
set detpos [expr {$::curtainu_yoffset + $cd}]
}
"curtaind" {
set detpos [expr {$::curtaind_yoffset + $cd}]
}
default {
error "Argument should be maindet, curtainl, curtainr, curtainu, or curtaind not $det"
}
}
return [expr {$detpos + $vy - $sy}]
} message ]
handle_exception $catch_status $message
}
## L2
::utility::macro::getset float L2_det {} {
set catch_status [ catch {
set retval [L2 maindet]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt L2_det klass instrument
sicslist setatt L2_det long_name L2_det
::utility::macro::getset float L2_curtainl {} {
set catch_status [ catch {
set retval [L2 curtainl]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt L2_curtainl klass instrument
sicslist setatt L2_curtainl long_name L2_curtainl
::utility::macro::getset float L2_curtainr {} {
set catch_status [ catch {
set retval [L2 curtainr]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt L2_curtainr klass instrument
sicslist setatt L2_curtainr long_name L2_curtainr
::utility::macro::getset float L2_curtainu {} {
set catch_status [ catch {
set retval [L2 curtainu]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt L2_curtainu klass instrument
sicslist setatt L2_curtainu long_name L2_curtainu
::utility::macro::getset float L2_curtaind {} {
set catch_status [ catch {
set retval [L2 curtaind]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt L2_curtaind klass instrument
sicslist setatt L2_curtaind long_name L2_curtaind
## Lt0
::utility::macro::getset float Lt0 {} {
set catch_status [ catch {
set t0_id [SplitReply [t0_chopper_id]]
switch $t0_id {
"1" { set retval 0.0}
"2" { set retval 1100.0}
"3" { set retval 3300.0}
"4" { set retval 7700.0}
}
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt Lt0 klass instrument
sicslist setatt Lt0 long_name Lt0
## Ltof
proc Ltof {det} {
set catch_status [ catch {
switch $det {
"maindet" - "curtainl" - "curtainr" - "curtainu" - "curtaind" {
set L2det [SplitReply [L2 $det]]
}
default {
error "Argument should be maindet, curtainl, curtainr, curtainu, or curtaind not $det"
}
}
set L1 [SplitReply [L1]]
set lg [SplitReply [lenguide]]
set ng [SplitReply [nguide]]
set sg [SplitReply [spaceguide]]
set lch4_pc1 [SplitReply [lch4_pc1]]
set Lt0 [SplitReply [Lt0]]
return [expr {$L2det + $L1 + $lg * $ng + $sg * ($ng -1) + $lch4_pc1 + $Lt0}]
} message ]
handle_exception $catch_status $message
}
::utility::macro::getset float Ltof_det {} {
set catch_status [ catch {
set retval [Ltof maindet]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt Ltof_det klass instrument
sicslist setatt Ltof_det long_name Ltof_det
::utility::macro::getset float Ltof_curtainl {} {
set catch_status [ catch {
set retval [Ltof curtainl]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt Ltof_curtainl klass instrument
sicslist setatt Ltof_curtainl long_name Ltof_curtainl
::utility::macro::getset float Ltof_curtainr {} {
set catch_status [ catch {
set retval [Ltof curtainr]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt Ltof_curtainr klass instrument
sicslist setatt Ltof_curtainr long_name Ltof_curtainr
::utility::macro::getset float Ltof_curtainu {} {
set catch_status [ catch {
set retval [Ltof curtainu]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt Ltof_curtainu klass instrument
sicslist setatt Ltof_curtainu long_name Ltof_curtainu
::utility::macro::getset float Ltof_curtaind {} {
set catch_status [ catch {
set retval [Ltof curtaind]
return "[lindex [info level 0] 0] = $retval"
} message ]
handle_exception $catch_status $message
}
sicslist setatt Ltof_curtaind klass instrument
sicslist setatt Ltof_curtaind long_name Ltof_curtaind
lenguide 2000
spaceguide 2
lch4_pc1 1107