/* ************************************************************** */ /* * Module SENSOR VS Z * This module contains functions to measure the output of a sensor * vs position. It can be used for measurements or sensor calibrations. * * Zachary Wolf * 2/14/01 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "param.h" #include "runparam.h" #include "sensor vs z ui.h" #include "sensor.h" #include "sensorparam.h" #include "movez.h" #include "movezparam.h" #include "cm2100.h" /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static char log_file[80]; static char dat_file[80]; static char plt_file[80]; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONS */ void senvsz_init(void); void senvsz_meas(void); void senvsz_exit(void); void senvsz_dat_meas(double z, double v[]); void senvsz_plt_meas(double z, double v[]); void senvsz_error(char* message); /* ************************************************************* */ /* PUBLIC FUNCTIONS */ /* ************************************************************* */ int main(int argc, char *argv[]) { /* Perform all initialization for the program */ senvsz_init(); /* Perform the measurements */ senvsz_meas(); /* Exit all systems */ senvsz_exit(); /* Message */ printf("\nDone\n"); /* Done */ return 0; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * senvsz_init * This function is used to initialize the sensor vs z measurements. * * Zachary Wolf * 2/14/01 */ void senvsz_init(void) { /* Declare variables */ struct run_param_struct run_param; int err; struct sensor_param_struct sensor_param; struct movez_param_struct movez_param; int i; char par_file[80]; /* Get the run parameters from the user */ try_again: runparam_get_run_param(&run_param); /* Create all output files */ err = runparam_create_file(run_param, "senlog", log_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "sendat", dat_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "senplt", plt_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "senpar", par_file); if (err != 0) goto try_again; /* Save the parameter file */ err = CopyFile("param.h", par_file); if (err != 0) printf("Error saving parameter file"); /* Update the run index file */ runparam_update_index(run_param); /* Write file headers */ runparam_write_header(run_param, log_file); runparam_write_header(run_param, dat_file); /* Get system parameters */ sensorparam_fill_param_struct(&sensor_param); movezparam_fill_param_struct(&movez_param); for (i = 0; i < SENVSZ_NUM_Z_POS; i++) SENVSZ_Z_POS[i] = (double)SENVSZ_START_Z_POS + i * (double)SENVSZ_Z_STEP; /* Initialize the user interface */ SetStdioWindowPosition(430, 15); SetStdioWindowSize(300, 660); senvszui_init(25, 15); senvszui_scale_horiz_axis(SENVSZ_NUM_Z_POS, SENVSZ_Z_POS); /* Message */ printf("\n\n*** Sensor vs Z Measurement System ***\n"); /* Initialize all systems */ sensor_init(log_file, sensor_param); movez_init(log_file, movez_param); /* Done */ return; } /* ************************************************************** */ /* * senvsz_meas * This function measures the sensor output vs z. * * Zachary Wolf * 2/14/01 */ void senvsz_meas(void) { /* Declare variables */ int i; double zpos; double v[SENVSZ_NUM_SENSORS]; /* Message */ printf("\nBeginning a sensor vs z map...\n"); /* Perform the sensor measurements */ for (i = 0; i < SENVSZ_NUM_Z_POS; i++) { /* Move to the required Z position */ movez_abs_move(SENVSZ_Z_POS[i]); /* Let things settle after the move */ Delay(0.5); /* Measure the Z position */ movez_get_pos(&zpos); /* Measure the sensor voltages */ sensor_get_multi_chan_voltages(SENVSZ_NUM_SENSORS, SENVSZ_SENSOR_CHAN, v); /* Write the result to the dat file */ senvsz_dat_meas(zpos, v); /* Write the result to the plt file */ senvsz_plt_meas(zpos, v); /* Display the results */ senvszui_update_meas(zpos, SENVSZ_NUM_SENSORS, v); } /* Move back to the home position */ printf("\nMoving back to the zero position...\n"); movez_abs_move(0.); /* Let things settle after the move */ Delay(0.5); /* Done */ return; } /* ************************************************************** */ void senvsz_exit(void) { /* Declare variables */ char buf[80]; /* Let the operator look at the measurements */ Beep(); printf("\nPress ENTER to exit program."); fgets(buf, 80, stdin); /* Exit the Sensor system */ sensor_exit(); /* Exit the MoveZ system */ movez_exit(); /* Done */ return; } /* ************************************************************** */ /* * senvsz_dat_meas * This function writes the z position and the sensor voltages to * the data file. * * Input: * z, z position (m, mrad, ...) * v[0 to SENVSZ_NUM_SENSORS - 1], the sensor voltages (V) * * Zachary Wolf * 2/16/00 */ void senvsz_dat_meas(double z, double v[]) { /* Declare variables */ FILE* file_ptr; static int call_num; int i; /* Open the dat file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("senvsz_dat_meas: Unable to open dat file\n"); return; } /* Increment the number of calls */ call_num++; /* Write a header on the first call */ if (call_num == 1) { fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "Sensor Voltage vs Z:\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Z "); for (i = 0; i < SENVSZ_NUM_SENSORS; i++) fprintf(file_ptr, " V%i ", i); fprintf(file_ptr, "\n"); fprintf(file_ptr, " "); for (i = 0; i < SENVSZ_NUM_SENSORS; i++) fprintf(file_ptr, " (V) "); fprintf(file_ptr, "\n"); fprintf(file_ptr, "-------"); for (i = 0; i < SENVSZ_NUM_SENSORS; i++) fprintf(file_ptr, " -------"); fprintf(file_ptr, "\n"); } /* Write the data */ fprintf(file_ptr, "%7.3f", z); for (i = 0; i < SENVSZ_NUM_SENSORS; i++) fprintf(file_ptr, " %7.3f", v[i]); fprintf(file_ptr, "\n"); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * senvsz_plt_meas * This function writes the z position and the sensor voltages to * the plot file. * * Input: * z, z position (m, mrad, ...) * v[0 to SENVSZ_NUM_SENSORS - 1], the sensor voltages (V) * * Zachary Wolf * 2/16/00 */ void senvsz_plt_meas(double z, double v[]) { /* Declare variables */ FILE* file_ptr; static int call_num; int i; /* Open the dat file */ file_ptr = fopen(plt_file, "a"); if (file_ptr == NULL) { printf("senvsz_plt_sen: Unable to open plt file\n"); return; } /* Increment the number of calls */ call_num++; /* Write a header on the first call */ if (call_num == 1) { fprintf(file_ptr, "%%z, V1(V), V2(V), ...\n"); } /* Write the data */ fprintf(file_ptr, "%7.3f", z); for (i = 0; i < SENVSZ_NUM_SENSORS; i++) fprintf(file_ptr, " %7.3f", v[i]); fprintf(file_ptr, "\n"); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * senvsz_error * This function handles errors for the Gap vs Z module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/11/98 */ void senvsz_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nERROR: %s\n", message); Beep(); Delay(.5); Beep(); /* Terminate the program if the operator desires */ printf("Press ENTER to continue.\nPress any key then ENTER to terminate program.\n"); fgets(buf, 80, stdin); if (buf[0] == '\n') return; else exit(0); }