# WPS_2.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 eleven numbers and represents one # execution of the entire script. # # The 1st 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 2nd 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 3rd 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 4th number is the center of the wire image in Camera 2, 5th is the rotation # of the wire. # # The 2nd to 4th numbers give the coordinates of a point on the wire center # in WPS coordinates. We define WPS coordinates in the same way as BCAM # coordinates. We choose the point where the wire center intersects the # z=-5mm plane, because this plane contains the nominal pivot points and # CCD centers. The coordinates are in millimeters. # # The 5th to 7th numbers are the direction of the wire, expressed as a unit # vector in WPS coordinates. The wires are almost parallel to the z-axis, so # the x and y coordinates of the vector are the direction cosines of the # wire direction. # # The remaining numbers in the results line give the position and rotation of # each wire image. The wire images are vertical in the image. We pick # a reference line at y-coordinate analysis_reference_um and take the wire # position as the intersection of the wire center and the reference line, # measured from the left side of the sensor. We express the position in # millimeters. The rotation of each center-line is in milliradians counter- # clockwise in the image. The position and rotation of each wire add four # more numbers to the result line, and so we arrive at eleven in all. # # To obtain our measurement of the wire position and direction, we use the # calibration constants of both cameras. These are declared in the post- # processing of the final acquisifier step. # # For more information about the Acquisifier that runs this script, see # http://alignment.hep.brandeis.edu/Electronics/LWDAQ/Manual.html#Acquisifier # # Kevan Hashemi 16-JAN-09, 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." } } # We prepare an output line that has the position of the center # of the image in mm and the rotation in mrad. We obtain # the center as the average of the left and right edge positions, # and the rotation as the average of the two rotations. if {![LWDAQ_is_error_result $result]} { append config(run_result) "\ [format %6.4f [expr ([lindex $result 7] + [lindex $result 1]) / 2000]]\ [format %6.4f [expr ([lindex $result 8] + [lindex $result 2]) / 2]]" } { append config(run_result) " -1 -1" } } config: daq_adjust_flash 1 daq_ip_addr 129.64.37.88 daq_driver_socket 1 daq_mux_socket 7 analysis_reference_um 1220 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. To make sense of the constants # consult the WPS1 Calibration Manual. Here we include the constants for the # default WPS1-A cameras and some other specific cameras, which we identify by # their serial numbers. Comment out the cameras you don't want to use and un-comment # those you want to use. set camera_1 "WPS1_A_1 -4.500 87.400 -5.000 -14.272 93.271 -5.000 -1570.796 0.000 -541.000" set camera_2 "WPS1_A_2 -4.500 37.400 -5.000 -14.272 31.529 -5.000 1570.796 0.000 541.000" # set camera_1 "Q0129_1 -7.042 89.787 -3.590 -17.226 95.844 -3.894 -1573.266 33.136 -551.365" # set camera_2 "Q0129_2 -6.936 37.604 -4.029 -17.316 31.139 -4.009 1569.173 62.729 535.665" # set camera_1 "Q0130_1 -5.062 88.701 -1.794 -15.766 94.982 -1.320 -1567.197 -35.028 -508.767" # set camera_2 "Q0130_2 -2.081 39.930 -6.049 -11.844 34.235 -6.762 1568.043 -0.144 652.383" # set camera_1 "Q0131_1 -3.871 88.557 -4.489 -13.947 95.017 -4.568 -1575.956 -1.148 -588.152" # set camera_2 "Q0131_2 -2.660 40.571 -4.675 -12.279 35.009 -5.323 1584.284 38.425 660.036" # The reference line the wire crosses to obtain the x-coordinate in the image. This value # is in millimeters, and should match the micron value we give about in analysis_reference_um # and the value we used when we determined the calibration constants. set ref_y 1.220 # We scan the x and rotation of both images. scan $config(run_result) "%s %f %f %f %f" ts x_1 rot_1 x_2 rot_2 # We obtain the two planes in which the wire must lie, as determined by the images # and the camera constants. set plane_1 [lwdaq wps_wire_plane "$x_1 $ref_y" $rot_1 $camera_1] set plane_2 [lwdaq wps_wire_plane "$x_2 $ref_y" $rot_2 $camera_2] # We intersect the two planes, and so obtain the wire center-line. set wire [lwdaq xyz_plane_plane_intersection $plane_2 $plane_1 ] # We find the intersection of the wire center-line and the z=-5mm plane. set point [lwdaq xyz_line_plane_intersection $wire "0 0 -5 0 0 1"] # Compose a new result string. set r $point append r " [lrange $wire 3 5]" append r " $x_1 $rot_1 $x_2 $rot_2" # Re-format the data. set result "$ts" foreach p $r {append result " [format %6.4f $p]"} # Print the run result to the screen and the result file. LWDAQ_print $config(run_results) $result } config: end.