# WPS_1.txt, an Acquisifier script for the WPS1 Instrument. # Copyright (C) 2007-2008 Kevan Hashemi, Open Source Instruments Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # This Acquisifier script takes images from the two cameras of a WPS1. For a # description of the WPS1 see: http://www.opensourceinstruments.com/WPS/WPS1/ # The script produces a result file called WPS_Results.txt. This file appears # in the same directory as the the script itself. If the file already exists, # the script appends new lines of data to the end of the file. # # Each line in WPS_Results.txt contains nine numbers and represents one # execution of the entire script. The first number is a timestamp # in seconds. You can calculate the time in seconds since the beginning # of your experiment by subtracting the timestamp of the first line in # the results file from the timestamp of the subsequent lines. # # The second number in each line is the center of the wire image in Camera 1. # We find the center position by taking the average of the two wire edges. The # positions of the wire edges given in the result string we obtain from # the WPS Instrument. We give the position is in microns from the left edge # of the image. # # The third number in each line is the width of the wire image in microns. We # calculate the width by subtracting the position of the right edge from that # of the left edge. # # The fourth number is the rotation of the wire image in milliradians, with anti- # clockwise positive. We obtain the image rotation by taking the average of the # rotations of its two edges. # # The fifth number is the center of the wire image in Camera 2, the sixth is # the width of the wire image in Camera 2, and the seventh number is the rotation # of the wire image in Camera 2, all of which we calculate in exactly the same # way as for Camera 1. # # The eighth number is the horizontal position in microns of the wire with # respect to the intersection of the WPS1 camera axese. This intersectgion is # the center of the WPS1's field of view. The ninth and final number is the # vertical position of the wire in microns, also with respect to the intersection # of the two axese. Thuse (0.0 0.0) means the wire is at the intersection, # (1.0 -2.0) means the wire is 1.0 mm to the left (as seen from the back RJ-45 # end of the WPS) of the intersection and 2.0 mm below. # # For more information about the Acquisifier that runs this script, see # http://alignment.hep.brandeis.edu/Electronics/LWDAQ/Manual.html#Acquisifier # # Kevan Hashemi 26-MAR-08, Open Source Instruments Inc. # acquisifier: post_processing: { set config(run_result) "[clock seconds] " set destination [file dirname $config(daq_script)] if {![file exists $destination]} { error "Results destination directory \"$destination\" does not exist." } set config(run_results) [file join $destination WPS_Results.txt] } config: end. default: instrument: WPS default_post_processing: { # Check to make sure that both edges of the wire are visible. This # we do by checking to see if there are at least $mp pixels in the # wire edge. if {![LWDAQ_is_error_result $result]} { set mp 100 if {([lindex $result 3] < $mp) || ([lindex $result 9] < $mp)} { set result "ERROR: Wire is out of bounds." LWDAQ_print $info(text) $result } } # We prepare an output line that has the position of the center # of the image, the width of the image, and the rotation. We obtain # the center as the average of the left and right edge positions, # the width as their difference, and the rotation as the average # of the two rotations. if {![LWDAQ_is_error_result $result]} { append config(run_result) " \ [format %8.2f [expr ([lindex $result 7] + [lindex $result 1]) / 2]] \ [format %8.2f [expr ([lindex $result 7] - [lindex $result 1])]] \ [format %8.2f [expr ([lindex $result 8] + [lindex $result 2]) / 2]]" } { append config(run_result) " -1 -1 -1" } } config: daq_adjust_flash 1 daq_ip_addr 129.64.37.88 daq_driver_socket 1 daq_mux_socket 7 end. acquire: name: Camera_1 instrument: WPS result: None time: 0 config: daq_flash_seconds 0.05 daq_device_element 1 end. acquire: name: Camera_2 instrument: WPS result: None time: 0 config: daq_flash_seconds 0.05 daq_device_element 2 end. acquisifier: post_processing: { # We have the following calibration constants. Our constants are in microns. To # make sense of our formulas, consult the WPS1 Geometry Drawing in the WPS1 # manual. # The center x-value for both CCDs we define as follows. set center_ccd_x 1700 # The first two constants give the distance frome the camera pivot points to their # CCD centers. set ccd_to_pivot_1 11400 set ccd_to_pivot_2 11400 # The axis inclination is the angle made with the vertical by the camera axis. The camera # axis is the line from the center of the CCD to the pivot point. We specify this angle # in milliradians, which is why we divide it by 1000 in later calculations. set axis_inclination_1 1030 set axis_inclination_2 1030 # The pivot-to-pivot separation is the distance between the two camera pivots. This line # defines the vertical for our calculations. Up is from Camera 2 to Camera 1. set pivot_to_pivot 50000 # The offsets give the position of the WPS center with respect to the Camera 2 pivot # point. set offset_x 42500 set offset_y 25000 # We scan the x, width, and rotation of both images. This version of the code does not # use the width or rotation, but it uses x. scan $config(run_result) "%s %f %f %f %f %f %f" ts ccd_x_1 ccd_w_1 ccd_rot_1 ccd_x_2 ccd_w_2 ccd_rot_2 # We determine the inclination of the line from the center of the wire to each camera # pivot point. We subtract the center_ccd_x from both ccd x-positions before we determine # the off-axis bearing of each image. set angle_1 [expr $axis_inclination_1/1000 + atan(($ccd_x_1-$center_ccd_x)/$ccd_to_pivot_1)] set angle_2 [expr $axis_inclination_2/1000 + atan(($ccd_x_2-$center_ccd_x)/$ccd_to_pivot_2)] # We triangulate to the wire center, and get its position to the left (x) and up (y) # from the Camera 2 pivot point. set y [expr $pivot_to_pivot / (1 + tan($angle_2) / tan($angle_1))] set x [expr $y * tan($angle_2)] # We now offset our x and y by the nominal distance from the WPS center to the pivot point # of Camera 2, so we get the WPS measurement or wire positions. set x [format %8.1f [expr $x - $offset_x]] set y [format %8.1f [expr $y - $offset_y]] append config(run_result) " $x $y" LWDAQ_print $info(text) "X Position = $x" LWDAQ_print $info(text) "Y Position = $y" LWDAQ_print $config(run_results) $config(run_result) } config: end.