/* ************************************************************** */ /* * Module PSD1D * This module contains functions for making laser beam position * measurements using a one dimensional PSD detector. * * Zachary Wolf * 3/28/01 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include "psd1d.h" #include "daqcard516.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ void psd1d_message(char* msg); void psd1d_error(char* msg); /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static int daqcard516_ID; static char msg[PSD1D_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * psd1d_init * This function performs all required initialization to use the * PSD detector. * * Zachary Wolf * 3/28/01 */ void psd1d_init() { /* Initialize the DaqCard 516 */ daqcard516_init(&daqcard516_ID); /* Done */ return; } /* ************************************************************** */ /* * psd1d_get_v * This function gets the voltage from each side of the detector. * * Output: * v1, voltage from side 1 (V) * v2, voltage from side 2 (V) * * Zachary Wolf * 3/28/01 */ void psd1d_get_v(double* v1, double* v2) { /* Declare variables */ double v[8]; double daq1, daq2; /* Get the voltages from the detector */ daqcard516_scan_v(3, v); /* Differential */ daq1 = v[3]; daq2 = v[2]; /* Take the negative of each voltage to account for the electronics */ *v1 = - daq1; *v2 = - daq2; /* Done */ return; } /* ************************************************************** */ /* * psd1d_get_v_ave * This function gets the voltage from each side of the detector. * It returns the average of several measurements. * * Output: * v1, voltage from side 1 (V) * v2, voltage from side 2 (V) * * Zachary Wolf * 3/28/01 */ void psd1d_get_v_ave(double* v1, double* v2) { /* Declare variables */ double v1_meas[NUM_MEAS_AVE]; double v2_meas[NUM_MEAS_AVE]; double sum_v1, sum_v2; int i; //double t0, t; //t0 = clock(); /* Get the voltages from the quadrants for averaging */ for (i = 0; i < NUM_MEAS_AVE; i++) psd1d_get_v(&v1_meas[i], &v2_meas[i]); /* Compute the average voltages */ sum_v1 = 0.; sum_v2 = 0.; for (i = 0; i < NUM_MEAS_AVE; i++) { sum_v1 = sum_v1 + v1_meas[i]; sum_v2 = sum_v2 + v2_meas[i]; } *v1 = sum_v1 / NUM_MEAS_AVE; *v2 = sum_v2 / NUM_MEAS_AVE; //t = clock(); //printf("scan time = %f\n", (t - t0) / CLOCKS_PER_SEC); /* Done */ return; } /* ************************************************************** */ /* * psd1d_calc_pos * This function calculates the laser beam position from * the PSD voltages. * * Input: * v1, voltage from side 1 (V) * v2, voltage from side 2 (V) * * Output: * x, x position of the laser beam (microns) * * Zachary Wolf * 3/28/01 */ void psd1d_calc_pos(double v1, double v2, double* x) { /* Declare variables */ double rx; /* Calculate the difference ratios */ rx = (v1 - v2) / (v1 + v2); /* Calculate x and y */ *x = rx * PSD1D_MICRONS_PER_RATIO_UNIT; /* Done */ return; } /* ************************************************************** */ /* * psd1d_close * This function performs all required operations to close the * quadrant detector. * * Zachary Wolf * 3/28/01 */ void psd1d_close() { /* Close the DaqCard 516 */ //daqcard516_close(daqcard516_ID); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * psd1d_message * This function handles messages about the quadrant detector. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 3/23/98 */ void psd1d_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * psd1d_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 psd1d_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nPSD1D 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); }