/* ************************************************************** */ /* * Module MOVEXY * This module contains functions for moving and getting the position * of two stages. * * Zachary Wolf * 6/14/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "movexy.h" #include "mc4.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ void movexy_message(char* msg); void movexy_error(char* msg); void movexy_log_device_type(enum movexy_device_type_enum device_type); void movexy_log_abs_move(double x_pos, double y_pos); void movexy_log_get_pos(double x_pos, double y_pos); void movexy_log_zero(void); /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static int mc4_ID; static double current_nominal_x_position; static double current_nominal_y_position; /* ************************************************************** */ /* PRIVATE PARAMETERS */ static char log_file[100]; static struct movexy_param_struct movexy_param; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * movexy_init * This function opens the device, queries for ID, and * initializes the device to a known state. * * Zachary Wolf * 6/14/00 */ void movexy_init(char log_file_in[], struct movexy_param_struct movexy_param_in) { /* Save the module parameters */ strcpy(log_file, log_file_in); movexy_param = movexy_param_in; /* Initialize the appropriate devices */ if (movexy_param.device_type == MOVEXY_MC4_MC4) { mc4_init(movexy_param.board_addr, movexy_param.mc4_addr, &mc4_ID); } else if (movexy_param.device_type == MOVEXY_MANUAL_NONE); else if (movexy_param.device_type == MOVEXY_NONE_NONE); else movexy_error("Unknown device type."); /* Zero the XY position system */ movexy_zero(); /* Log the device type */ movexy_log_device_type(movexy_param.device_type); /* Done */ return; } /* ************************************************************** */ /* * movexy_abs_move * This function moves the stages to the specified positions. * * Input: * x_pos, final x stage position (m) * y_pos, final y stage position (m) * * Zachary Wolf * 12/19/00 */ void movexy_abs_move(double x_pos, double y_pos) { /* Declare variables */ char buf[80]; /* Move the stages to the specified positions */ if (movexy_param.device_type == MOVEXY_MC4_MC4) { mc4_abs_stage_move(mc4_ID, movexy_param.mc4_x_axis, movexy_param.acc, movexy_param.vel, x_pos); mc4_abs_stage_move(mc4_ID, movexy_param.mc4_y_axis, movexy_param.acc, movexy_param.vel, y_pos); } else if (movexy_param.device_type == MOVEXY_MANUAL_NONE) { printf("\nPlease move the X stage to %f m and the Y stage to %f m.\n", x_pos, y_pos); printf("Press ENTER when ready."); fgets(buf, 80, stdin); } else if (movexy_param.device_type == MOVEXY_NONE_NONE); else movexy_error("Unknown device type."); /* Save the positions */ current_nominal_x_position = x_pos; current_nominal_y_position = y_pos; /* Log the move */ movexy_log_abs_move(x_pos, y_pos); /* Done */ return; } /* ************************************************************** */ /* * movexy_get_pos * This function gets the positions of the stages. * * Output: * x_pos, x stage position (m) * y_pos, y stage position (m) * * Zachary Wolf * 12/19/00 */ void movexy_get_pos(double* x_pos, double* y_pos) { /* Get the positions of the stages */ if (movexy_param.device_type == MOVEXY_MC4_MC4) { mc4_get_stage_pos(mc4_ID, movexy_param.mc4_x_axis, x_pos); mc4_get_stage_pos(mc4_ID, movexy_param.mc4_y_axis, y_pos); } else if (movexy_param.device_type == MOVEXY_MANUAL_NONE) { *x_pos = current_nominal_x_position; *y_pos = current_nominal_y_position; } else if (movexy_param.device_type == MOVEXY_NONE_NONE); else movexy_error("Unknown device type."); /* Log the position */ movexy_log_get_pos(*x_pos, *y_pos); /* Done */ return; } /* ************************************************************** */ /* * movexy_zero * This function zeros the move device and the read device. * * Zachary Wolf * 12/19/00 */ void movexy_zero(void) { /* Declare variables */ char buf[80]; /* Have the user move to the zero position */ printf("\nPosition Zero\n"); printf("Please move both the x and y stages to the zero position.\n"); printf("The X and Y position scales will be zeroed.\n"); printf("Press ENTER when ready."); fgets(buf, 80, stdin); /* Zero the move device and the read device */ if (movexy_param.device_type == MOVEXY_MC4_MC4) { mc4_zero(mc4_ID); } else if (movexy_param.device_type == MOVEXY_MANUAL_NONE) { current_nominal_x_position = 0.; current_nominal_y_position = 0.; } else if (movexy_param.device_type == MOVEXY_NONE_NONE); else movexy_error("Unknown device type."); /* Log the zero */ movexy_log_zero(); /* Message */ printf("The X and Y position zeros have been set.\n"); /* Done */ return; } /* ************************************************************** */ /* * movexy_exit * This function configures the MOVEXY system for program exit and * closes the devices. * * Zachary Wolf * 12/19/00 */ void movexy_exit(void) { /* Exit all devices */ if (movexy_param.device_type == MOVEXY_MC4_MC4) { mc4_exit(mc4_ID); } else if (movexy_param.device_type == MOVEXY_MANUAL_NONE); else if (movexy_param.device_type == MOVEXY_NONE_NONE); else movexy_error("Unknown device type."); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * movexy_message * This function handles messages about the MOVEXY. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void movexy_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * movexy_error * This function handles error messages for the MOVEXY module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void movexy_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nMOVEXY 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); } /* ************************************************************** */ /* * movexy_log_device_type * This function logs the types of devices being used. * * Input: * device_type, types of devices * * Zachary Wolf * 12/19/00 */ void movexy_log_device_type(enum movexy_device_type_enum device_type) { /* Declare variables */ FILE* file_ptr; char type[50]; /* Put the device type in a string */ if (device_type == MOVEXY_MC4_MC4) strcpy(type, "Move Device = MC4, Read Device = MC4"); else if (device_type == MOVEXY_MANUAL_NONE) strcpy(type, "Move Device = MANUAL, Read Device = NONE"); else if (device_type == MOVEXY_NONE_NONE) strcpy(type, "Move Device = NONE, Read Device = NONE"); else movexy_error("Unknown device type in log device function."); /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movexy_message("Unable to open log file"); return; } /* Write the types of devices to the log file */ fprintf(file_ptr, "%s MoveXY Devices: %s\n", TimeStr(), type); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movexy_log_abs_move * This function logs a move. * * Input: * x_pos, final x stage position (m) * y_pos, final y stage position (m) * * Zachary Wolf * 12/19/00 */ void movexy_log_abs_move(double x_pos, double y_pos) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movexy_message("Unable to open log file"); return; } /* Write the final positions to the log file */ fprintf(file_ptr, "%s Move Stages, x_position = %f m, y_position = %f m\n", TimeStr(), x_pos, y_pos); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movexy_log_get_pos * This function logs the result of a position measurement. * * Input: * x_pos, x stage position (m) * y_pos, y stage position (m) * * Zachary Wolf * 12/19/00 */ void movexy_log_get_pos(double x_pos, double y_pos) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movexy_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, y_pos = %f m\n", TimeStr(), x_pos, y_pos); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * movexy_log_zero * This function logs the zeroing of the move device and the read device. * * Zachary Wolf * 2/2/00 */ void movexy_log_zero(void) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { movexy_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s X and Y Stages Zeroed\n", TimeStr()); /* Close the log file */ fclose(file_ptr); /* Done */ return; }