/* ************************************************************** */ /* * Module MOVEX * This module contains functions for moving and getting the position * of either one or two stages. * * Zachary Wolf * 6/15/01 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "movex.h" #include "mc4.h" #include "pm500.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ void movex_message(char* msg); void movex_error(char* msg); void movex_log_device_type(enum movex_device_type_enum device_type); void movex_log_abs_move(double x_pos); void movex_log_abs_2_stage_move(double x_pos); void movex_log_rel_move(double x_rel); void movex_log_rel_2_stage_move(double x_rel); void movex_log_get_pos(double x_pos); void movex_log_get_2_pos(double x_pos, double xs_pos); void movex_log_zero(void); /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static int mc4_ID; static int pm500_ID; static double current_nominal_x_position; static double current_nominal_xs_position; /* ************************************************************** */ /* PRIVATE PARAMETERS */ static char log_file[100]; static struct movex_param_struct movex_param; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * movex_init * This function opens the device, queries for ID, and * initializes the device to a known state. * * Zachary Wolf * 6/15/01 */ void movex_init(char log_file_in[], struct movex_param_struct movex_param_in) { /* Save the module parameters */ strcpy(log_file, log_file_in); movex_param = movex_param_in; /* Initialize the appropriate devices */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_init(movex_param.board_addr, movex_param.mc4_addr, &mc4_ID); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_init(movex_param.board_addr, movex_param.pm500_addr, &pm500_ID); } else if (movex_param.device_type == MOVEX_MANUAL_NONE); else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Zero the XY position system */ movex_zero(); /* Log the device type */ movex_log_device_type(movex_param.device_type); /* Done */ return; } /* ************************************************************** */ /* * movex_abs_stage_move * This function moves the stage to the specified position. * * Input: * x_pos, final x stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_abs_stage_move(double x_pos) { /* Declare variables */ char buf[80]; /* Move the stage to the specified position */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_abs_stage_move(mc4_ID, movex_param.mc4_x_axis, movex_param.acc, movex_param.vel, x_pos); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_abs_stage_move(mc4_ID, movex_param.pm500_x_axis, movex_param.acc, movex_param.vel, x_pos); } else if (movex_param.device_type == MOVEX_MANUAL_NONE) { printf("\nPlease move the X stage to %f m.\n", x_pos); printf("Press ENTER when ready."); fgets(buf, 80, stdin); } else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Save the positions */ current_nominal_x_position = x_pos; /* Log the move */ movex_log_abs_move(x_pos); /* Done */ return; } /* ************************************************************** */ /* * movex_abs_2_stage_move * This function moves the stages at the same time to the specified position. * * Input: * x_pos, final x stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_abs_2_stage_move(double x_pos) { /* Declare variables */ char buf[80]; /* Move the stages to the specified position */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_abs_2_stage_move(mc4_ID, movex_param.mc4_x_axis, movex_param.mc4_xs_axis, movex_param.acc, movex_param.vel, x_pos); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_abs_2_stage_move(pm500_ID, movex_param.pm500_x_axis, movex_param.pm500_xs_axis, movex_param.acc, movex_param.vel, x_pos); } else if (movex_param.device_type == MOVEX_MANUAL_NONE) { printf("\nPlease move the X stages to %f m.\n", x_pos); printf("Press ENTER when ready."); fgets(buf, 80, stdin); } else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Save the positions */ current_nominal_x_position = x_pos; current_nominal_xs_position = x_pos; /* Log the move */ movex_log_abs_2_stage_move(x_pos); /* Done */ return; } /* ************************************************************** */ /* * movex_rel_stage_move * This function moves the stage the specified amount. * * Input: * x_rel, relative final x stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_rel_stage_move(double x_rel) { /* Declare variables */ char buf[80]; /* Move the stage the specified amount */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_rel_stage_move(mc4_ID, movex_param.mc4_x_axis, movex_param.acc, movex_param.vel, x_rel); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_rel_stage_move(mc4_ID, movex_param.pm500_x_axis, movex_param.acc, movex_param.vel, x_rel); } else if (movex_param.device_type == MOVEX_MANUAL_NONE) { printf("\nPlease move the X stage %f m from its present position.\n", x_rel); printf("Press ENTER when ready."); fgets(buf, 80, stdin); } else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Save the positions */ current_nominal_x_position += x_rel; /* Log the move */ movex_log_rel_move(x_rel); /* Done */ return; } /* ************************************************************** */ /* * movex_rel_2_stage_move * This function moves the stages at the same time the specified amount. * * Input: * x_rel, relative final x stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_rel_2_stage_move(double x_rel) { /* Declare variables */ char buf[80]; /* Move the stages the specified amount */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_rel_2_stage_move(mc4_ID, movex_param.mc4_x_axis, movex_param.mc4_xs_axis, movex_param.acc, movex_param.vel, x_rel); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_rel_2_stage_move(pm500_ID, movex_param.pm500_x_axis, movex_param.pm500_xs_axis, movex_param.acc, movex_param.vel, x_rel); } else if (movex_param.device_type == MOVEX_MANUAL_NONE) { printf("\nPlease move the X stages %f m from their present position.\n", x_rel); printf("Press ENTER when ready."); fgets(buf, 80, stdin); } else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Save the positions */ current_nominal_x_position += x_rel; current_nominal_xs_position += x_rel; /* Log the move */ movex_log_rel_2_stage_move(x_rel); /* Done */ return; } /* ************************************************************** */ /* * movex_get_stage_pos * This function gets the position of the stage. * * Output: * x_pos, stage x position (m) * * Zachary Wolf * 6/15/01 */ void movex_get_stage_pos(double* x_pos) { /* Get the position of the stages */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_get_stage_pos(mc4_ID, movex_param.mc4_x_axis, x_pos); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_get_pos(pm500_ID, movex_param.pm500_x_axis, x_pos); } else if (movex_param.device_type == MOVEX_MANUAL_NONE) { *x_pos = current_nominal_x_position; } else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Log the position */ movex_log_get_pos(*x_pos); /* Done */ return; } /* ************************************************************** */ /* * movex_get_2_stage_pos * This function gets the positions of the two stages. * * Output: * x_pos, x stage position (m) * xs_pos, xs stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_get_2_stage_pos(double* x_pos, double* xs_pos) { /* Get the positions of the stages */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_get_stage_pos(mc4_ID, movex_param.mc4_x_axis, x_pos); mc4_get_stage_pos(mc4_ID, movex_param.mc4_xs_axis, xs_pos); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_get_pos(pm500_ID, movex_param.pm500_x_axis, x_pos); pm500_get_pos(pm500_ID, movex_param.pm500_xs_axis, xs_pos); } else if (movex_param.device_type == MOVEX_MANUAL_NONE) { *x_pos = current_nominal_x_position; *xs_pos = current_nominal_xs_position; } else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Log the position */ movex_log_get_2_pos(*x_pos, *xs_pos); /* Done */ return; } /* ************************************************************** */ /* * movex_set_zero_pos * This function has the user move to the zero position and then * zeros the move device and the read device. * * Zachary Wolf * 6/15/01 */ void movex_set_zero_pos(void) { /* Declare variables */ char buf[80]; /* Have the user move to the zero position */ printf("\nPosition Zero\n"); printf("Please move the x stages to the zero position.\n"); printf("The X position scales will be zeroed.\n"); printf("Press ENTER when ready."); fgets(buf, 80, stdin); /* Zero the move device and the read device */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_zero(mc4_ID); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_zero(pm500_ID, movex_param.pm500_x_axis); pm500_zero(pm500_ID, movex_param.pm500_xs_axis); } else if (movex_param.device_type == MOVEX_MANUAL_NONE) { current_nominal_x_position = 0.; current_nominal_xs_position = 0.; } else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Log the zero */ movex_log_zero(); /* Message */ printf("The X position zeros have been set.\n"); /* Done */ return; } /* ************************************************************** */ /* * movex_zero * This function zeros the move device and the read device. * * Zachary Wolf * 6/15/01 */ void movex_zero(void) { /* Zero the move device and the read device */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_zero(mc4_ID); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_zero(pm500_ID, movex_param.pm500_x_axis); pm500_zero(pm500_ID, movex_param.pm500_xs_axis); } else if (movex_param.device_type == MOVEX_MANUAL_NONE) { current_nominal_x_position = 0.; current_nominal_xs_position = 0.; } else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Log the zero */ movex_log_zero(); /* Done */ return; } /* ************************************************************** */ /* * movex_exit * This function configures the MOVEX system for program exit and * closes the devices. * * Zachary Wolf * 6/15/01 */ void movex_exit(void) { /* Exit all devices */ if (movex_param.device_type == MOVEX_MC4_MC4) { mc4_exit(mc4_ID); } else if (movex_param.device_type == MOVEX_PM500_PM500) { pm500_exit(pm500_ID); } else if (movex_param.device_type == MOVEX_MANUAL_NONE); else if (movex_param.device_type == MOVEX_NONE_NONE); else movex_error("Unknown device type."); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * movex_message * This function handles messages about the MOVEX. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void movex_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * movex_error * This function handles error messages for the MOVEX module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void movex_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nMOVEX ERROR: %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."); fgets(buf, 80, stdin); if (buf[0] == '\n') return; else exit(0); } /* ************************************************************** */ /* * movex_log_device_type * This function logs the types of devices being used. * * Input: * device_type, types of devices * * Zachary Wolf * 6/15/01 */ void movex_log_device_type(enum movex_device_type_enum device_type) { /* Declare variables */ FILE* file_ptr; char type[50]; /* Put the device type in a string */ if (device_type == MOVEX_MC4_MC4) strcpy(type, "Move Device = MC4, Read Device = MC4"); else if (device_type == MOVEX_PM500_PM500) strcpy(type, "Move Device = PM500, Read Device = PM500"); else if (device_type == MOVEX_MANUAL_NONE) strcpy(type, "Move Device = MANUAL, Read Device = NONE"); else if (device_type == MOVEX_NONE_NONE) strcpy(type, "Move Device = NONE, Read Device = NONE"); else movex_error("Unknown device type in log device function."); /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movex_message("Unable to open log file"); return; } /* Write the types of devices to the log file */ fprintf(file_ptr, "%s MoveX Devices: %s\n", TimeStr(), type); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movex_log_abs_move * This function logs a move. * * Input: * x_pos, final x stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_log_abs_move(double x_pos) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movex_message("Unable to open log file"); return; } /* Write the final positions to the log file */ fprintf(file_ptr, "%s Move X Stages, x_position = %f m\n", TimeStr(), x_pos); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movex_log_abs_2_stage_move * This function logs a move. * * Input: * x_pos, final x stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_log_abs_2_stage_move(double x_pos) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movex_message("Unable to open log file"); return; } /* Write the final positions to the log file */ fprintf(file_ptr, "%s Move X Stages, x_position = %f m\n", TimeStr(), x_pos); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movex_log_rel_move * This function logs a relative move. * * Input: * x_rel, relative final x stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_log_rel_move(double x_rel) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movex_message("Unable to open log file"); return; } /* Write the move to the log file */ fprintf(file_ptr, "%s Relative Move X Stages, x_rel = %f m\n", TimeStr(), x_rel); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movex_log_rel_2_stage_move * This function logs a move. * * Input: * x_rel, relative final x stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_log_rel_2_stage_move(double x_rel) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movex_message("Unable to open log file"); return; } /* Write the move to the log file */ fprintf(file_ptr, "%s Relative Move X Stages, x_rel = %f m\n", TimeStr(), x_rel); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movex_log_get_pos * This function logs the result of a position measurement. * * Input: * x_pos, x stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_log_get_pos(double x_pos) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movex_message("Unable to open log file"); return; } /* Write the measured values to the log file */ fprintf(file_ptr, "%s Stage Position Measurement, x_pos = %f m\n", TimeStr(), x_pos); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movex_log_get_2_pos * This function logs the result of a position measurement. * * Input: * x_pos, x stage position (m) * xs_pos, xs stage position (m) * * Zachary Wolf * 6/15/01 */ void movex_log_get_2_pos(double x_pos, double xs_pos) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movex_message("Unable to open log file"); return; } /* Write the measured values to the log file */ fprintf(file_ptr, "%s Stage Position Measurement, x_pos = %f m, xs_pos = %f m\n", TimeStr(), x_pos, xs_pos); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movex_log_zero * This function logs the zeroing of the move device and the read device. * * Zachary Wolf * 6/15/01 */ void movex_log_zero(void) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movex_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s X Stages Zeroed\n", TimeStr()); /* Close the log file */ fclose(file_ptr); /* Done */ return; }