SICS-771 Save name of selected sample aperture and improve nguide command.
This commit is contained in:
@@ -60,10 +60,11 @@ sapmot position_names D2.5 D5 D7.5 D10 D12.5 D15 D17.5 D20 D30 D40
|
|||||||
sapmot precision 0.001
|
sapmot precision 0.001
|
||||||
# TODO implement target
|
# TODO implement target
|
||||||
::utility::macro::getset text sample_aperture { {target "NONE"} } {
|
::utility::macro::getset text sample_aperture { {target "NONE"} } {
|
||||||
return "sample_aperture = [posname sapmot]"
|
return "sample_aperture = [SplitReply [posname sapmot]]"
|
||||||
}
|
}
|
||||||
sicslist setatt sample_aperture klass sample
|
sicslist setatt sample_aperture klass sample
|
||||||
sicslist setatt sample_aperture long_name sample_aperture
|
sicslist setatt sample_aperture long_name sample_aperture
|
||||||
|
sicslist setatt sample_aperture mutable false
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -99,30 +100,74 @@ proc posname {pmot} {
|
|||||||
set first_pos [lindex $positions 0]
|
set first_pos [lindex $positions 0]
|
||||||
set last_pos [lindex $positions end]
|
set last_pos [lindex $positions end]
|
||||||
|
|
||||||
if {[expr abs($pos - $first_pos)] < $tol} {
|
if { [llength $pnames] != [llength $positions] } {
|
||||||
return [lindex $pnames 0]
|
error "[info level 0]: Name list and position list are not the same size"
|
||||||
} elseif {$pos < $first_pos} {
|
} else {
|
||||||
return "before_[lindex $pnames 0]"
|
if { [llength $pnames] < 1} {
|
||||||
|
error "[info level 0]: Motor $pmot does not have a list of positions"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if { [expr abs($pos - $first_pos)] < $tol } {
|
||||||
|
set named_pos [lindex $pnames 0]
|
||||||
|
} elseif {$pos < $first_pos} {
|
||||||
|
set named_pos "before_[lindex $pnames 0]"
|
||||||
}
|
}
|
||||||
|
|
||||||
if {[expr abs($pos - $last_pos)] < $tol} {
|
if {[expr abs($pos - $last_pos)] < $tol} {
|
||||||
return [lindex $pnames end]
|
set named_pos [lindex $pnames end]
|
||||||
} elseif {$pos > $last_pos} {
|
} elseif {$pos > $last_pos} {
|
||||||
return "after_[lindex $pnames end]"
|
set named_pos "after_[lindex $pnames end]"
|
||||||
}
|
}
|
||||||
|
|
||||||
set next_index 1
|
set next_index 1
|
||||||
foreach name [lrange $pnames 0 end-1] posit [lrange $positions 0 end-1] {
|
foreach name [lrange $pnames 0 end-1] posit [lrange $positions 0 end-1] {
|
||||||
if {[expr abs($pos - $posit)] <= $tol} {
|
if {[expr abs($pos - $posit)] <= $tol} {
|
||||||
return $name
|
set named_pos $name
|
||||||
|
break
|
||||||
} elseif {$pos > [expr {$posit + $tol}] && $pos < [expr {[lindex $positions $next_index] - $tol}]} {
|
} elseif {$pos > [expr {$posit + $tol}] && $pos < [expr {[lindex $positions $next_index] - $tol}]} {
|
||||||
return "between_${name}_[lindex $pnames $next_index]"
|
set named_pos "between_${name}_[lindex $pnames $next_index]"
|
||||||
|
break
|
||||||
}
|
}
|
||||||
incr next_index
|
incr next_index
|
||||||
}
|
}
|
||||||
|
return "$pmot = $named_pos"
|
||||||
}
|
}
|
||||||
publish posname user
|
publish posname user
|
||||||
|
|
||||||
|
# \brief Is a motor in a named position
|
||||||
|
# \param pmot: motor name
|
||||||
|
# \param named_pos: Check if motor is at the named position. OPTIONAL
|
||||||
|
#
|
||||||
|
# If named_pos is empty then return true if the motor is in any named position
|
||||||
|
proc inpos {pmot {named_pos "_NONE_"}} {
|
||||||
|
set pos [ SplitReply [$pmot] ]
|
||||||
|
set tol [ SplitReply [$pmot precision] ]
|
||||||
|
set pnames [SplitReply [$pmot position_names]]
|
||||||
|
set positions [SplitReply [$pmot positions]]
|
||||||
|
|
||||||
|
if { [llength $pnames] != [llength $positions] } {
|
||||||
|
error "[info level 0]: Name list and position list are not the same size"
|
||||||
|
} else {
|
||||||
|
if { [llength $pnames] < 1} {
|
||||||
|
error "[info level 0]: Motor $pmot does not have a list of positions"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if {$named_pos == "_NONE_"} {
|
||||||
|
foreach posit [lrange $positions 0 end] {
|
||||||
|
if {[expr abs($pos - $posit)] <= $tol} {
|
||||||
|
return "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "false"
|
||||||
|
} else {
|
||||||
|
if {$named_pos == [SplitReply [posname $pmot]]} {
|
||||||
|
return "true"
|
||||||
|
} else {
|
||||||
|
return "false"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Length of a guide
|
# Length of a guide
|
||||||
::utility::mkVar lenguide float user lenguide true instrument true true
|
::utility::mkVar lenguide float user lenguide true instrument true true
|
||||||
# Space between guides
|
# Space between guides
|
||||||
@@ -143,8 +188,6 @@ publish posname user
|
|||||||
# \return The number of selected guides or an error message
|
# \return The number of selected guides or an error message
|
||||||
proc nguide { {num "REPORTNUM"} {sel_ap_name "NONE"} {aprest_name "NONE"}} {
|
proc nguide { {num "REPORTNUM"} {sel_ap_name "NONE"} {aprest_name "NONE"}} {
|
||||||
set catch_status [ catch {
|
set catch_status [ catch {
|
||||||
set FINDFIRST 1
|
|
||||||
set COUNT 2
|
|
||||||
set CheckDrive false
|
set CheckDrive false
|
||||||
set ap_names { D10 D20 D40 S40 R100 }
|
set ap_names { D10 D20 D40 S40 R100 }
|
||||||
array set EMSG {
|
array set EMSG {
|
||||||
@@ -154,16 +197,14 @@ proc nguide { {num "REPORTNUM"} {sel_ap_name "NONE"} {aprest_name "NONE"}} {
|
|||||||
misaligned "Misalignment. At least one guide is not in the aperture or guide position"
|
misaligned "Misalignment. At least one guide is not in the aperture or guide position"
|
||||||
apfailed "Failed to set apertures"
|
apfailed "Failed to set apertures"
|
||||||
}
|
}
|
||||||
set guideposit 1
|
set GUIDEPOSIT 1
|
||||||
set apposit 2
|
set APPOSIT 2
|
||||||
set tol 0.1
|
set MISCONFIGURED false
|
||||||
set ng 0
|
|
||||||
set state $FINDFIRST
|
|
||||||
set apdrvlist {}
|
set apdrvlist {}
|
||||||
set pcdrvlist {}
|
set pcdrvlist {}
|
||||||
set ap_target_list {}
|
set ap_target_list {}
|
||||||
if {$num != "REPORTNUM"} {
|
if {$num != "REPORTNUM"} {
|
||||||
if {$num >= 0 && $num < 8} {
|
if {$num >= 0 && $num < 7} {
|
||||||
if { $sel_ap_name == "NONE" || $aprest_name == "NONE" } {
|
if { $sel_ap_name == "NONE" || $aprest_name == "NONE" } {
|
||||||
error "$EMSG(invalidarg): You must provide two aperture arguments"
|
error "$EMSG(invalidarg): You must provide two aperture arguments"
|
||||||
} elseif { [lsearch -nocase $ap_names $sel_ap_name] == -1 } {
|
} elseif { [lsearch -nocase $ap_names $sel_ap_name] == -1 } {
|
||||||
@@ -172,88 +213,123 @@ proc nguide { {num "REPORTNUM"} {sel_ap_name "NONE"} {aprest_name "NONE"}} {
|
|||||||
error "$EMSG(invalidarg): $aprest_name should be one of $ap_names"
|
error "$EMSG(invalidarg): $aprest_name should be one of $ap_names"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if {$num == 7} {
|
||||||
|
if { $sel_ap_name == "NONE"} {
|
||||||
|
error "$EMSG(invalidarg): You must provide one aperture argument"
|
||||||
|
} elseif { [lsearch -nocase $ap_names $sel_ap_name] == -1 } {
|
||||||
|
error "$EMSG(invalidarg): $sel_ap_name should be one of $ap_names"
|
||||||
|
}
|
||||||
|
}
|
||||||
if {$num >= 0 && $num <= 8} {
|
if {$num >= 0 && $num <= 8} {
|
||||||
set CheckDrive true
|
set CheckDrive true
|
||||||
set last 8
|
|
||||||
for {set n 1} {$n <= $num} {incr n } {
|
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
|
|
||||||
lappend apdrvlist ap$last 1
|
|
||||||
}
|
|
||||||
incr last -1
|
|
||||||
}
|
|
||||||
for {set n [expr 8 - $num]} {$n >= 1} {incr n -1} {
|
|
||||||
set currpos [SplitReply [pc$n]]
|
set currpos [SplitReply [pc$n]]
|
||||||
set table_guideunit [SplitReply [pc$n posit2unit $apposit]]
|
set table_guideunit [SplitReply [pc$n posit2unit $GUIDEPOSIT]]
|
||||||
|
set tol [SplitReply [pc$n precision]]
|
||||||
if {[expr {abs($currpos - $table_guideunit)}] > $tol} {
|
if {[expr {abs($currpos - $table_guideunit)}] > $tol} {
|
||||||
lappend pcdrvlist c$n $apposit
|
lappend pcdrvlist pc$n $table_guideunit
|
||||||
|
lappend apdrvlist ap$n 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for {set n [expr $num + 1]} {$n <= 8} {incr n} {
|
||||||
|
set currpos [SplitReply [pc$n]]
|
||||||
|
set table_appunit [SplitReply [pc$n posit2unit $APPOSIT]]
|
||||||
|
set tol [SplitReply [pc$n precision]]
|
||||||
|
if {[expr {abs($currpos - $table_appunit)}] > $tol} {
|
||||||
|
lappend pcdrvlist pc$n $table_appunit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if {[llength $pcdrvlist] > 0 && [llength $apdrvlist] > 0} {
|
if {[llength $pcdrvlist] > 0 && [llength $apdrvlist] > 0} {
|
||||||
clientput "drive $apdrvlist"
|
clientput "drive $apdrvlist"
|
||||||
eval "drive $apdrvlist"
|
drive {*}$apdrvlist
|
||||||
}
|
}
|
||||||
if {[llength $pcdrvlist] > 0} {
|
if {[llength $pcdrvlist] > 0} {
|
||||||
clientput "drive $pcdrvlist"
|
clientput "drive $pcdrvlist"
|
||||||
eval "drive $pcdrvlist"
|
drive {*}$pcdrvlist
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error "$EMSG(invalidarg)"
|
error "$EMSG(invalidarg)"
|
||||||
}
|
}
|
||||||
# Select Apertures
|
# Select Apertures
|
||||||
if {$num >= 0 && $num < 8} {
|
if {$num >= 0 && $num < 8} {
|
||||||
set sel_ap_pos [SplitReply [ ap$last ]]
|
set sel_ap ap[expr $num + 1]
|
||||||
set req_sel_ap_pos [ SplitReply [ ap$last posit2unit $sel_ap_name ] ]
|
set sel_ap_pos [SplitReply [ $sel_ap ]]
|
||||||
set sel_ap_prec [ SplitReply [ap$last precision] ]
|
set req_sel_ap_pos [ SplitReply [ $sel_ap posit2unit $sel_ap_name ] ]
|
||||||
|
set sel_ap_prec [ SplitReply [$sel_ap precision] ]
|
||||||
if { [expr abs($req_sel_ap_pos - $sel_ap_pos)] > $sel_ap_prec } {
|
if { [expr abs($req_sel_ap_pos - $sel_ap_pos)] > $sel_ap_prec } {
|
||||||
lappend ap_target_list ap$last $sel_ap_name
|
lappend ap_target_list $sel_ap $req_sel_ap_pos
|
||||||
}
|
}
|
||||||
for {set n [expr $last - 1]} {$n > 0} {incr n -1} {
|
for {set n [expr $num + 2]} {$n <= 8} {incr n} {
|
||||||
set sel_pos [SplitReply [ ap$n ]]
|
set sel_pos [SplitReply [ ap$n ]]
|
||||||
set req_pos [ SplitReply [ ap$n posit2unit $aprest_name ] ]
|
set req_pos [ SplitReply [ ap$n posit2unit $aprest_name ] ]
|
||||||
set prec [ SplitReply [ap$n precision] ]
|
set prec [ SplitReply [ap$n precision] ]
|
||||||
if { [expr abs($req_pos - $sel_pos)] > $prec } {
|
if { [expr abs($req_pos - $sel_pos)] > $prec } {
|
||||||
lappend ap_target_list ap$n $aprest_name
|
lappend ap_target_list ap$n $req_pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if {[llength $ap_target_list] > 0} {
|
if {[llength $ap_target_list] > 0} {
|
||||||
pdrive {*}$ap_target_list
|
clientput "drive $ap_target_list"
|
||||||
|
drive {*}$ap_target_list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check guide alignment
|
# Check guide alignment
|
||||||
set ap_posname_list {}
|
set ap_posname_list {}
|
||||||
|
set table_posname_list {}
|
||||||
|
set ng 0
|
||||||
|
# COUNT number of tables in guide position
|
||||||
for {set n 1} {$n <= 8} {incr n} {
|
for {set n 1} {$n <= 8} {incr n} {
|
||||||
set currpos [SplitReply [pc$n]]
|
set currpos [SplitReply [pc$n]]
|
||||||
set table_guideunit [SplitReply [pc$n posit2unit $guideposit]]
|
set table_guideunit [SplitReply [pc$n posit2unit $GUIDEPOSIT]]
|
||||||
set table_appunit [SplitReply [pc$n posit2unit $apposit]]
|
set table_appunit [SplitReply [pc$n posit2unit $APPOSIT]]
|
||||||
|
set tol [SplitReply [pc$n precision]]
|
||||||
|
if {[expr {abs($currpos - $table_guideunit)}] <= $tol} {
|
||||||
|
incr ng
|
||||||
|
} elseif {[expr {abs($currpos - $table_appunit)}] <= $tol} {
|
||||||
|
# Table in aperture position
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
set MISCONFIGURED true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if {$ng < 8} {
|
||||||
|
# Check first aperture selected after guides
|
||||||
|
set n [ expr $ng + 1]
|
||||||
|
set currpos [SplitReply [pc$n]]
|
||||||
|
set table_appunit [SplitReply [pc$n posit2unit $APPOSIT]]
|
||||||
|
set tol [SplitReply [pc$n precision]]
|
||||||
|
if {[expr {abs($currpos - $table_appunit)}] <= $tol} {
|
||||||
|
if {[inpos ap$n] == "false"} {
|
||||||
|
set MISCONFIGURED true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
set MISCONFIGURED true
|
||||||
|
}
|
||||||
|
if {$ng < 7} {
|
||||||
|
# Check that the rest of the apertures are all the same
|
||||||
|
set apn "ap[expr $ng + 2]"
|
||||||
|
if [inpos $apn] {
|
||||||
|
set pname [SplitReply [posname $apn]]
|
||||||
|
for {set n [expr $ng + 3]} {$n <= 8} {incr n} {
|
||||||
|
if { $pname != [SplitReply [posname ap$n]] } {
|
||||||
|
set MISCONFIGURED true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
set MISCONFIGURED true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch $state [subst {
|
for {set n 1} {$n <= 8} {incr n} {
|
||||||
$FINDFIRST {
|
lappend table_posname_list [posname pc$n]
|
||||||
if {[expr {abs($currpos - $table_appunit)}] <= $tol} {
|
lappend ap_posname_list [posname ap$n]
|
||||||
set ap_posname_list {[linsert $ap_posname_list 0 ap${n}=[posname ap$n]]}
|
}
|
||||||
continue
|
if {$MISCONFIGURED} {
|
||||||
} elseif {[expr {abs($currpos - $table_guideunit)}] <= $tol} {
|
return "nguide = MISCONFIGURED: $ng guides $table_posname_list apertures $ap_posname_list"
|
||||||
incr ng
|
|
||||||
set state $COUNT
|
|
||||||
} else {
|
|
||||||
return "$EMSG(misaligned)"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$COUNT {
|
|
||||||
if {[expr {abs($currpos - $table_guideunit)}] <= $tol} {
|
|
||||||
incr ng
|
|
||||||
} else {
|
|
||||||
# ERROR There shouldn't be any gaps in the selection
|
|
||||||
return "$EMSG(gaps)"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if {$CheckDrive} {
|
if {$CheckDrive} {
|
||||||
@@ -262,10 +338,9 @@ proc nguide { {num "REPORTNUM"} {sel_ap_name "NONE"} {aprest_name "NONE"}} {
|
|||||||
set drive_ok false
|
set drive_ok false
|
||||||
clientput "$EMSG(drivefailed): Failed to select guides"
|
clientput "$EMSG(drivefailed): Failed to select guides"
|
||||||
}
|
}
|
||||||
foreach {ap_mot ap_name} $ap_target_list {
|
foreach {ap_mot target} $ap_target_list {
|
||||||
set pos [SplitReply [$ap_mot]]
|
set pos [SplitReply [$ap_mot]]
|
||||||
set tol [SplitReply [$ap_mot precision]]
|
set tol [SplitReply [$ap_mot precision]]
|
||||||
set target [SplitReply [$ap_mot posit2unit $ap_name]]
|
|
||||||
if {[expr {abs($pos - $target)}] > $tol} {
|
if {[expr {abs($pos - $target)}] > $tol} {
|
||||||
set drive_ok false
|
set drive_ok false
|
||||||
clientput "$EMSG(drivefailed): Apertures off target"
|
clientput "$EMSG(drivefailed): Apertures off target"
|
||||||
@@ -278,7 +353,7 @@ proc nguide { {num "REPORTNUM"} {sel_ap_name "NONE"} {aprest_name "NONE"}} {
|
|||||||
clientput "nguide finished with errors"
|
clientput "nguide finished with errors"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "[lindex [info level 0] 0] = $ng $ap_posname_list"
|
return "[lindex [info level 0] 0] = $ng [lrange $ap_posname_list $ng 8]"
|
||||||
} message ]
|
} message ]
|
||||||
handle_exception $catch_status $message
|
handle_exception $catch_status $message
|
||||||
}
|
}
|
||||||
@@ -292,7 +367,7 @@ sicslist setatt gs_nguide klass instrument
|
|||||||
sicslist setatt gs_nguide long_name nguide
|
sicslist setatt gs_nguide long_name nguide
|
||||||
|
|
||||||
proc L1 {} {
|
proc L1 {} {
|
||||||
set ng [SplitReply [nguide]]
|
set ng [lrange [nguide] 2 2]
|
||||||
set lg [SplitReply [lenguide]]
|
set lg [SplitReply [lenguide]]
|
||||||
set sg [SplitReply [spaceguide]]
|
set sg [SplitReply [spaceguide]]
|
||||||
set sy [SplitReply [samy]]
|
set sy [SplitReply [samy]]
|
||||||
@@ -430,7 +505,7 @@ proc Ltof {det} {
|
|||||||
}
|
}
|
||||||
set L1 [SplitReply [L1]]
|
set L1 [SplitReply [L1]]
|
||||||
set lg [SplitReply [lenguide]]
|
set lg [SplitReply [lenguide]]
|
||||||
set ng [SplitReply [nguide]]
|
set ng [lrange [nguide] 2 2]
|
||||||
set sg [SplitReply [spaceguide]]
|
set sg [SplitReply [spaceguide]]
|
||||||
set lch4_pc1 [SplitReply [lch4_pc1]]
|
set lch4_pc1 [SplitReply [lch4_pc1]]
|
||||||
set Lt0 [SplitReply [Lt0]]
|
set Lt0 [SplitReply [Lt0]]
|
||||||
|
|||||||
Reference in New Issue
Block a user