Check scan variable limits before starting a scan.

Added reset_position option to hmm_scan_finish to drive motors back to their start position at the end of a scan.

r2119 | ffr | 2007-08-16 16:03:14 +1000 (Thu, 16 Aug 2007) | 3 lines
This commit is contained in:
Ferdi Franceschini
2007-08-16 16:03:14 +10:00
committed by Douglas Clowes
parent 530436b257
commit 6ce90065d3

View File

@@ -1,4 +1,9 @@
#TODO Define bmon and hmm scan commands in separate namespaces
## \file Scan functionality and common high level commands are defined here.
#
# namespace variables\n
# ::scan::save_filetype data/scratch, controls if data will be saved to a scratch file.
# ::scan::reset_position true/false, drive motor back to start position at end of scan
#TODO Get rid of duplication in bmonscan and hmscan code
MakeScanCommand hmscan bm $cfPath(scan)/scan_common_1.hdd recover.bin
MakeScanCommand bmonscan bm $cfPath(scan)/scan_common_1.hdd recover.bin
MakeScanCommand scan2 bm $cfPath(scan)/scan_common_1.hdd recover.bin
@@ -8,6 +13,10 @@ namespace eval scan {
# List of counts
variable bmoncounts_array
variable bmoncounts_axis
variable save_filetype
variable reset_position
set save_filetype "data"
set reset_position "false"
variable bmonscanvar_axis_hpath
# hpath to values from bmoncounts_array
@@ -17,9 +26,53 @@ variable scanVariable scan_var scanVarStart 0 scanVarStep 1
proc scan_collect {sobj uobj point} {
}
## \brief Aborts scan if a scan variable target position exeeds the limits.
proc check_limit {scan_variable limit_name target} {
switch $limit_name {
"hardlowerlim" - "softlowerlim" {
set limit [SplitReply [$scan_variable $limit_name]]
if { $target < $limit} {
return -code error "ERROR Scan aborted. Final position of $target violates $limit_name $limit for $scan_variable"
}
}
"hardupperlim" - "softupperlim" {
set limit [SplitReply [$scan_variable $limit_name]]
if { $target > $limit} {
return -code error "ERROR Scan aborted. Final position of $target violates $limit_name $limit for $scan_variable"
}
}
default {
error_msg "Invalid limit name $limit_name"
}
}
}
## \brief check final position against scan variable limits
#
# NOTE: The sics scan object alread checks if a variable is drivable
# so we don't have to.
# TODO We can't check limits of virtual motors yet because the
# configurablevirtualmotor doesn't set a checklimits function.
proc check_scanvar {sobj uobj} {
set vlist [split [$sobj getvarpar 0] = ];
set NP [SplitReply [$sobj np]]
set scan_variable [string trim [lindex [split [lindex $vlist 0] . ] 1]]
set scan_start [lindex $vlist 1];
set scan_increment [lindex $vlist 2];
if {[getatt $scan_variable type] != "configurablevirtualmotor"} {
if {[SplitReply [$scan_variable fixed]] >= 0} {
return -code error "Scan aborted. $scan_variable position is set to 'fixed'"
}
set target [expr $scan_start + $NP * $scan_increment]
::scan::check_limit $scan_variable hardlowerlim $target
::scan::check_limit $scan_variable hardupperlim $target
::scan::check_limit $scan_variable softlowerlim $target
::scan::check_limit $scan_variable softupperlim $target
}
}
proc hmm_scan_prepare {sobj uobj} {
variable scan_pt_start_time
set nexusdic hmscan.dic
::scan::check_scanvar $sobj $uobj
# stdscan prepare $sobj $uobj;
::scan::hdb_hmscan -set NP [SplitReply [$sobj np]]
@@ -36,7 +89,7 @@ variable scanVariable scan_var scanVarStart 0 scanVarStep 1
::histogram_memory::prepare
data axis 1 [::scan::hdb_hmscan -set scan_variable]
::hdb::set_save / true
newfile [SplitReply [SicsDataSuffix]] $nexusdic
::nexus::newfile data
}
proc hmm_count {sobj uobj point mode preset} {
@@ -50,16 +103,41 @@ variable scanVariable scan_var scanVarStart 0 scanVarStep 1
}
proc hmm_scan_finish {sobj uobj} {
variable save_filetype
variable reset_position
set $save_filetype "data"
::histogram_memory::finish;
::scan::hdb_hmscan -set feedback status IDLE
# Make sure that the next save command doesn't overwrite our scan data.
newfile [SplitReply [SicsDataSuffix]]
# and clear any data links
::nexus::newfile data
::nexus::data clear
if {$reset_position == "true"} {
set svar [::scan::hdb_hmscan -get scan_variable]
set svtype [getatt $svar type]
if {$svtype == "motor" || $svtype == "configurablevirtualmotor"} {
drive $svar [::scan::hdb_hmscan -get scan_start]
}
set reset_position "false"
}
::histogram_memory::configure_server Filler_defaults
}
proc bm_scan_finish {sobj uobj} {
variable reset_position
::scan::hdb_bmonscan -set feedback status IDLE
# Make sure that the next save command doesn't overwrite our scan data.
newfile [SplitReply [SicsDataSuffix]]
# and clear any data links
::nexus::newfile data
::nexus::data clear
if {$reset_position == "true"} {
set svar [::scan::hdb_bmonscan -get scan_variable]
set svtype [getatt $svar type]
if {$svtype == "motor" || $svtype == "configurablevirtualmotor"} {
drive $svar [::scan::hdb_bmonscan -get scan_start]
}
set reset_position "false"
}
}
#proc hmm_scan_finish {sobj uobj} {
# nxclosefile;
@@ -84,15 +162,16 @@ variable scanVariable scan_var scanVarStart 0 scanVarStep 1
proc bm_writepoint {sobj uobj pt} {
variable bmoncounts_array
set bmoncounts_array [string map {\{ "" \} ""} [SplitReply [bmonscan getcounts]]];
save $pt
::nexus::save $pt
::scan::hdb_bmonscan -set feedback counts [SplitReply [bm getcounts]];
}
#TODO Feedback for Histogram memory scan
proc hmm_writepoint {sobj uobj pt} {
variable save_filetype
# Write hdb tree
save $pt
::nexus::save $pt
}
proc donothing {args} {}
@@ -110,8 +189,6 @@ variable scanVariable scan_var scanVarStart 0 scanVarStep 1
proc bm_scan_prepare {sobj uobj} {
variable event;
variable nexusdic
set nexusdic bmonscan.dic
variable bmoncounts_array;
variable bmoncounts_axis;
@@ -139,12 +216,11 @@ variable scanVariable scan_var scanVarStart 0 scanVarStep 1
data axis 1 [::scan::hdb_bmonscan -set scan_variable]
::hdb::set_save / true
::hdb::set_save /instrument/detector false
newfile [SplitReply [SicsDataSuffix]] $nexusdic
::nexus::newfile data
#stdscan prepare $sobj $uobj;
}
# group=beam_monitor_scan
proc hdb_bmonscan_graphics {process args} {
set eid hdb_bmonscan/graphics
@@ -220,8 +296,7 @@ command hdb_bmonscan { text:drivable scan_variable float: scan_start float: scan
if {$status == 0} {
return $msg
} else {
clientput "ERROR, [info level 0], $msg"
error $msg
return -code error "ERROR [info level 0]"
}
@@ -242,8 +317,7 @@ command hdb_hmscan { text:drivable scan_variable float: scan_start float: scan_i
if {$status == 0} {
return $msg
} else {
clientput "ERROR, [info level 0], $msg"
error $msg
return -code error "ERROR [info level 0]"
}