/* ************************************************************** */ /* * Module QUADDET * This module contains functions for making laser beam position * measurements using a quadrant detector. * * Zachary Wolf * 3/20/99 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include "quaddet.h" #include "daqcard516.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ void quaddet_message(char* msg); void quaddet_error(char* msg); /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static int daqcard516_ID; static char msg[QUADDET_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * quaddet_init * This function performs all required initialization to use the * quadrant detector. * * Zachary Wolf * 3/20/99 */ void quaddet_init() { /* Initialize the DaqCard 516 */ daqcard516_init(&daqcard516_ID); /* Done */ return; } /* ************************************************************** */ /* * quaddet_get_v * This function gets the voltage from each quadrant of the detector. * * Output: * v1, voltage from quadrant 1 (V) * v2, voltage from quadrant 2 (V) * v3, voltage from quadrant 3 (V) * v4, voltage from quadrant 4 (V) * * Zachary Wolf * 3/20/99 */ void quaddet_get_v(double* v1, double* v2, double* v3, double* v4) { /* Declare variables */ double v[8]; double daq1, daq2, daq3, daq4; /* Get the voltages from the quadrants */ //daqcard516_scan_v(4, v); /* Single ended */ daqcard516_scan_v(3, v); /* Differential */ daq1 = v[3]; daq2 = v[2]; daq3 = v[1]; daq4 = v[0]; /* Take the negative of each voltage to account for the electronics */ *v1 = - daq1; *v2 = - daq2; *v3 = - daq3; *v4 = - daq4; /* Done */ return; } /* ************************************************************** */ /* * quaddet_get_v_ave * This function gets the voltage from each quadrant of the detector. * It returns the average of several measurements. * * Output: * v1, voltage from quadrant 1 (V) * v2, voltage from quadrant 2 (V) * v3, voltage from quadrant 3 (V) * v4, voltage from quadrant 4 (V) * * Zachary Wolf * 3/30/99 */ void quaddet_get_v_ave(double* v1, double* v2, double* v3, double* v4) { /* Declare variables */ double v1_meas[NUM_MEAS_AVE]; double v2_meas[NUM_MEAS_AVE]; double v3_meas[NUM_MEAS_AVE]; double v4_meas[NUM_MEAS_AVE]; double sum_v1, sum_v2, sum_v3, sum_v4; int i; //double t0, t; //t0 = clock(); /* Get the voltages from the quadrants for averaging */ for (i = 0; i < NUM_MEAS_AVE; i++) quaddet_get_v(&v1_meas[i], &v2_meas[i], &v3_meas[i], &v4_meas[i]); /* Compute the average voltages */ sum_v1 = 0.; sum_v2 = 0.; sum_v3 = 0.; sum_v4 = 0.; for (i = 0; i < NUM_MEAS_AVE; i++) { sum_v1 = sum_v1 + v1_meas[i]; sum_v2 = sum_v2 + v2_meas[i]; sum_v3 = sum_v3 + v3_meas[i]; sum_v4 = sum_v4 + v4_meas[i]; } *v1 = sum_v1 / NUM_MEAS_AVE; *v2 = sum_v2 / NUM_MEAS_AVE; *v3 = sum_v3 / NUM_MEAS_AVE; *v4 = sum_v4 / NUM_MEAS_AVE; //t = clock(); //printf("scan time = %f\n", (t - t0) / CLOCKS_PER_SEC); /* Done */ return; } /* ************************************************************** */ /* * quaddet_calc_pos * This function calculates the laser beam position from * the quadrant detector voltages. * * Input: * v1, voltage from quadrant 1 (V) * v2, voltage from quadrant 2 (V) * v3, voltage from quadrant 3 (V) * v4, voltage from quadrant 4 (V) * * Output: * x, x position of the laser beam (microns) * y, y position of the laser beam (microns) * * Zachary Wolf * 3/23/99 */ void quaddet_calc_pos(double v1, double v2, double v3, double v4, double* x, double* y) { /* Declare variables */ double vt, vb, vl, vr; double rx, ry; /* Calculate the half cell voltages */ vt = v1 + v2; vb = v3 + v4; vr = v1 + v4; vl = v2 + v3; /* Calculate the difference ratios */ rx = (vr - vl) / (vr + vl); ry = (vt - vb) / (vt + vb); /* Calculate x and y */ *x = rx * QUADDET_MICRONS_PER_RATIO_UNIT; *y = ry * QUADDET_MICRONS_PER_RATIO_UNIT; /* Done */ return; } /* ************************************************************** */ /* * quaddet_close * This function performs all required operations to close the * quadrant detector. * * Zachary Wolf * 3/20/99 */ void quaddet_close() { /* Close the DaqCard 516 */ //daqcard516_close(daqcard516_ID); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * quaddet_message * This function handles messages about the quadrant detector. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 3/23/98 */ void quaddet_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * quaddet_error * This function handles error messages for the quadrant detector. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 3/23/98 */ void quaddet_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nQUADDET ERROR: %s\n", message); Beep(); Delay(.5); Beep(); /* Terminate the program if the operator desires */ printf("Press 0 ENTER to continue, anything else to terminate program: "); scanf("%s", buf); if (buf[0] == '0') return; else exit(0); }