From 2ea516d84bf2902928700e7188eb39f5236d5cca Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Tue, 28 Aug 2012 16:00:32 +1000 Subject: [PATCH] Add virtual motors for initial energy (vei) and wavelength (vwi) and for elastic_time r3713 | dcl | 2012-08-28 16:00:32 +1000 (Tue, 28 Aug 2012) | 1 line --- .../config/motors/motor_configuration.tcl | 78 +++++++++++++++---- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/site_ansto/instrument/pelican/config/motors/motor_configuration.tcl b/site_ansto/instrument/pelican/config/motors/motor_configuration.tcl index 3ec13de1..783f3231 100644 --- a/site_ansto/instrument/pelican/config/motors/motor_configuration.tcl +++ b/site_ansto/instrument/pelican/config/motors/motor_configuration.tcl @@ -865,20 +865,70 @@ proc motor_set_sobj_attributes {} { } # END MOTOR CONFIGURATION -# According to http://www.nexusformat.org/Design units must conform to -# http://www.unidata.ucar.edu/software/udunits/udunits-1/udunits.txt -# So we use "count" for dimensionless decimal numbers -#set vc_units count -#make_coll_motor_2 c1 section_1 pc1 pc2 $vc_units -#make_coll_motor_1 c2 section_2 pc3 $vc_units -#make_coll_motor_1 c3 section_3 pc4 $vc_units -#make_coll_motor_1 c4 section_4 pc5 $vc_units -#make_coll_motor_1 c5 section_5 pc6 $vc_units -#make_coll_motor_1 c6 section_6 pc7 $vc_units -#make_coll_motor_1 c7 section_7 pc8 $vc_units -#make_coll_motor_1 c8 section_8 pc9 $vc_units -#make_coll_motor_1 c9 section_9 pc10 $vc_units -#unset vc_units +# virtual Motors + +# Convert mtth angle to Wavelength in Angstroms +proc get_vwi {} { + set dd 3.35416 + set angle [expr 0.5 * [SplitReply [mtth]]] + set wavelength [expr 2.0 * $dd * sin($angle * 3.141592654 / 180.0)] + return $wavelength +} + +# Convert mtth angle to Energy in mEv +proc get_vei {} { + set h_for_joules 6.62606957e-34 + set neutron_mass 1.674927351e-27 + set ev_to_joules 1.602176565e-19 + set wavelength [expr 1.0e-10 * [get_vwi]] + set temp [expr ($h_for_joules / ($neutron_mass * $wavelength))] + set joules [expr 0.5 * $neutron_mass * ($temp * $temp)] + set mEv [expr 1000 * $joules / $ev_to_joules] + return $mEv +} + +# Convert Wavelength in Angstroms to mom,mtth positions +proc set_vwi {wavelength} { + set dd 3.35416 + set theta [expr (180.0 / 3.141592654) * asin($wavelength / (2.0 * $dd))] + set result [format "mom=%f,mtth=%f" $theta [expr 2.0 * $theta]] + return $result +} + +# Convert Energy in mEv to mom,mtth positions +proc set_vei {mEv} { + set h_for_joules 6.62606957e-34 + set neutron_mass 1.674927351e-27 + set ev_to_joules 1.602176565e-19 + set joules [expr 0.001 * $mEv * $ev_to_joules] + set wavelength [expr $h_for_joules / ($neutron_mass * sqrt(2.0 * $joules / $neutron_mass))] + return [set_vwi [expr 1.0e10 * $wavelength]] +} + +MakeConfigurableMotor vwi +vwi readscript get_vwi +vwi drivescript set_vwi +MakeConfigurableMotor vei +vei readscript get_vei +vei drivescript set_vei + +publish get_vwi user +publish set_vwi user +publish get_vei user +publish set_vei user + +proc get_elastic_time {} { + set h_for_joules 6.62606957e-34 + set neutron_mass 1.674927351e-27 + set wavelength [expr 1.0e-10 * [get_vwi]] + set elastic_time [expr {(3.095 * $neutron_mass * $wavelength) / $h_for_joules}] + return elastic_time +} + +MakeConfigurableMotor elastic_time +elastic_time readscript get_elastic_time + +publish get_elastic_time user # Generator functions proc make_virtual_motor_1 { vm1 vm1_name pm1 aunits klass } {