/* ************************************************************** */ /* * Module ESP7000 * This module contains I/O functions for the Newport model * ESP7000 controller. * * Zachary Wolf * 5/13/05 */ /* ************************************************************** */ /* INCLUDES */ #include "repository.h" #include DELAY //adds most commonly used functions #include #include #include #include #include "esp7000.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int esp7000_open_dev(int gpib_board_addr, int gpib_dev_addr); void esp7000_close_dev(int dev_ID); int esp7000_out(int dev_ID, char *buf); int esp7000_in(int dev_ID, char* buf); int esp7000_check_dev_open(int dev_ID); int esp7000_check_axis_active(int dev_ID, int axis); int esp7000_check_errors(int dev_ID); void esp7000_hold_until_move_complete(int dev_ID, int axis); void esp7000_message(char* msg); void esp7000_error(char* msg); /* ************************************************************** */ /* PRIVATE DEVICE TABLE */ /* * This table allows several devices of the same type to be * used in the system. * dev_addr, contains the GPIB addresses of opened devices * dev_descr, contains the device descriptors of opened devices * dev_count, contains the number of devices open of this type */ static int dev_addr[ESP7000_MAX_NUM_DEV + 1]; static int dev_descr[ESP7000_MAX_NUM_DEV + 1]; static int dev_count; /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ /* * cmd, buffer for GPIB I/O strings * msg, buffer for message strings to Standard I/O */ static char cmd[ESP7000_MAX_CMD + 1]; static char msg[ESP7000_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * esp7000_init * This function opens the device, queries for ID, and * initializes the device to a known state. * * Input: * gpib_board_addr, address of the GPIB board the device is connected to (0, 1, ...) * gpib_dev_addr, GPIB address of the device (1 to 30, 0 is reserved) * * Output: * ID, identifier for future references to the device * * Zachary Wolf * 5/16/05 */ void esp7000_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; int axis, status; /* Message */ esp7000_message(""); esp7000_message("Initializing the ESP7000..."); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s%f", &pos); if (abs(pos) > 0.001) esp7000_error("Position wrong after home."); /* Check for errors */ esp7000_check_errors(dev_ID); /* Done */ return; } /* ************************************************************** */ /* * esp7000_rel_stage_move * This function moves a stage a given distance relative to * its present position. The acceleration and velocity are specified. * * Input: * dev_ID, device identifier * axis, axis to move (1, 2, ...) * acc, acceleration (m/sec/sec) * vel, velocity (m/sec) * dis, distance (m), can be + or - * * Zachary Wolf * 5/27/05 */ void esp7000_rel_stage_move(int dev_ID, int axis, double acc, double vel, double dis) { /* Declare variables */ int dev_open; int axis_active; double ini_pos, fin_pos; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s ESP7000_MAX_ACC) { Fmt(msg, "%s ESP7000_MAX_VEL) { Fmt(msg, "%s ESP7000_MAX_DIS) { Fmt(msg, "%s 1.5e-6) esp7000_error("esp7000_rel_stage_move: the stage did not move the proper amount"); /* Done */ return; } /* ************************************************************** */ /* * esp7000_rel_2_stage_move * This function moves two stages a given distance relative to * their present position. The acceleration and velocity are specified. * * Input: * dev_ID, device identifier * axis1, axis 1 (1, 2, ...) * axis2, axis 2 (1, 2, ...) * acc, acceleration (m/sec/sec) * vel, velocity (m/sec) * dis, distance (m), can be + or - * * Zachary Wolf * 5/27/05 */ void esp7000_rel_2_stage_move(int dev_ID, int axis1, int axis2, double acc, double vel, double dis) { /* Declare variables */ int dev_open; int axis_active; double ini_pos1, fin_pos1; double ini_pos2, fin_pos2; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s ESP7000_MAX_ACC) { Fmt(msg, "%s ESP7000_MAX_VEL) { Fmt(msg, "%s ESP7000_MAX_DIS) { Fmt(msg, "%s 1.5e-6) esp7000_error("esp7000_rel_stage_move: the stage did not move the proper amount"); if (fabs(fin_pos2 - ini_pos2 - dis) > 1.5e-6) esp7000_error("esp7000_rel_stage_move: the stage did not move the proper amount"); /* Done */ return; } /* ************************************************************** */ /* * esp7000_abs_stage_move * This function moves a stage to a specified position. * The acceleration and velocity are specified. * * Input: * dev_ID, device identifier * axis, axis to move (1, 2, ...) * acc, acceleration (m/sec/sec) * vel, velocity (m/sec) * pos, position (m), can be + or - * * Zachary Wolf * 5/16/05 */ void esp7000_abs_stage_move(int dev_ID, int axis, double acc, double vel, double pos) { /* Declare variables */ int dev_open; int axis_active; double fin_pos; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s ESP7000_MAX_ACC) { Fmt(msg, "%s ESP7000_MAX_VEL) { Fmt(msg, "%s ESP7000_MAX_DIS) { Fmt(msg, "%s 1.5e-6) esp7000_error("esp7000_abs_stage_move: the stage did not move the proper amount"); /* Done */ return; } /* ************************************************************** */ /* * esp7000_abs_2_stage_move * This function moves two stages to a specified position. * The acceleration and velocity are specified. * * Input: * dev_ID, device identifier * axis1, axis 1 (1, 2, ...) * axis2, axis 2 (1, 2, ...) * acc, acceleration (m/sec/sec) * vel, velocity (m/sec) * pos, position (m), can be + or - * * Zachary Wolf * 5/27/05 */ void esp7000_abs_2_stage_move(int dev_ID, int axis1, int axis2, double acc, double vel, double pos) { /* Declare variables */ int dev_open; int axis_active; double fin_pos1, fin_pos2; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s ESP7000_MAX_ACC) { Fmt(msg, "%s ESP7000_MAX_VEL) { Fmt(msg, "%s ESP7000_MAX_DIS) { Fmt(msg, "%s 1.5e-6) esp7000_error("esp7000_abs_2_stage_move: the stage did not move the proper amount"); if (fabs(fin_pos2 - pos) > 1.5e-6) esp7000_error("esp7000_abs_2_stage_move: the stage did not move the proper amount"); /* Done */ return; } /* ************************************************************** */ /* * esp7000_zero * This function zeros the specified axis. * * Input: * dev_ID, device identifier * axis, axis to zero (1, 2, ...) * * Zachary Wolf * 5/16/05 */ void esp7000_zero(int dev_ID, int axis) { /* Declare variables */ int dev_open; int axis_active; double fin_pos; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s 1.5e-6) esp7000_error("esp7000_zero: the stage did not zero properly"); /* Done */ return; } /* ************************************************************** */ /* * esp7000_activate_axis * This function turns on the power to the axis * * Input: * dev_ID, device identifier * axis, system axis (1, 2, ...) * * * Michael Levashov * 8/22/07 */ void esp7000_activate_axis(int dev_ID, int axis) { /* Declare variables */ int dev_open; int axis_active; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s%f", &acc_mm_sec_sec); if (num_scan != 1) esp7000_error("Problem reading acceleration."); *acc = acc_mm_sec_sec/1000; /* Check for errors */ esp7000_check_errors(dev_ID); /* Done */ return; } /* ************************************************************** */ /* * esp7000_get_dcl * This function gets the deceleration of the specified axis. * * Input: * dev_ID, device identifier * axis, system axis (1, 2, ...) * * Output: * dcl, stage deceleration (m/sec/sec) * * Zachary Wolf * 5/16/05 */ void esp7000_get_dcl(int dev_ID, int axis, double* dcl) { /* Declare variables */ int dev_open; int axis_active; int num_scan; double dcl_mm_sec_sec; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s%f", &dcl_mm_sec_sec); if (num_scan != 1) esp7000_error("Problem reading deceleration."); *dcl = dcl_mm_sec_sec/1000; /* Check for errors */ esp7000_check_errors(dev_ID); /* Done */ return; } /* ************************************************************** */ /* * esp7000_get_vel * This function gets the velocity of the specified axis. * * Input: * dev_ID, device identifier * axis, system axis (1, 2, ...) * * Output: * vel, stage velocity (m/sec) * * Zachary Wolf * 5/16/05 */ void esp7000_get_vel(int dev_ID, int axis, double* vel) { /* Declare variables */ int dev_open; int axis_active; int num_scan; double vel_mm_sec; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s%f", &vel_mm_sec); if (num_scan != 1) esp7000_error("Problem reading velocity."); *vel = vel_mm_sec/1000; /* Check for errors */ esp7000_check_errors(dev_ID); /* Done */ return; } /* ************************************************************** */ /* * esp7000_get_pos * This function gets the position of the specified axis. * * Input: * dev_ID, device identifier * axis, axis number (1, 2, ...) * * Output: * pos, stage position (m) * * Zachary Wolf * 5/16/05 */ void esp7000_get_pos(int dev_ID, int axis, double* pos) { /* Declare variables */ int dev_open; int axis_active; int num_scan; double pos_mm; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s%f", &pos_mm); if (num_scan != 1) esp7000_error("Problem reading position."); *pos = pos_mm/1000; /* Check for errors */ esp7000_check_errors(dev_ID); /* Done */ return; } /* ************************************************************** */ /* * esp7000_exit * This function prepares the ESP7000 for shutdown and closes * the device. * * Input: * dev_ID, device identifier * * Zachary Wolf * 8/3/99 */ void esp7000_exit(int dev_ID) { /* Declare variables */ int err; int dev_open; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * esp7000_check_dev_open * This function checks to see if the specified device is open. * If the device has been opened, a 1 is returned, 0 otherwise. * * Input: * dev_ID, device identifier * * Output: * status, 1 if device is open, 0 otherwise * * Zachary Wolf * 7/27/98 */ int esp7000_check_dev_open(int dev_ID) { /* See if the device descriptor has a positive value */ if (dev_descr[dev_ID] > 0) { return 1; /* Open */ } else { return 0; /* Not open */ } } /* ************************************************************** */ /* * esp7000_check_axis_active * This function checks whether the specified axis is active, * ie. whether a positioner is connected. * * Input: * dev_ID, device identifier * axis, axis number * * Output: * active, 1 if active, 0 otherwise * * Zachary Wolf * 5/16/05 */ int esp7000_check_axis_active(int dev_ID, int axis) { /* Declare variables */ char system_config[ESP7000_MAX_CMD]; long int config_val; int num_scan; int axis_bit_num; int axis_bit_val; int status; /* Get the system configuration */ esp7000_out(dev_ID, "ZU"); esp7000_in(dev_ID, system_config); num_scan = Scan(system_config, "%s[t72]>%i[r16]", &config_val); if (num_scan != 1) esp7000_error("Problem reading system configuration."); /* Determine the axis bit number */ /* See manual p. 3-150 */ /* Range of axis assumed to have been previously checked */ axis_bit_num = 7 + axis; /* Determine the axis bit value */ axis_bit_val = 1 << (axis_bit_num); /* Bit number starts at 0 */ /* See if the axis is active */ if ((config_val & axis_bit_val) == axis_bit_val) status = 1; else status = 0; /* Debug */ //printf("\nesp7000_check_axis_active\n"); //printf("system_config = %s\n", system_config); //printf("config_val = %i\n", config_val); //printf("axis = %i\n", axis); //printf("axis_bit_num = %i\n", axis_bit_num); //printf("axis_bit_val = %i\n", axis_bit_val); //printf("status = %i\n", status); /* Done */ return status; } /* ************************************************************** */ /* * esp7000_check_errors * This function checks for device errors. * The operator is alerted if there is an error. * * Input: * dev_ID, device identifier * * Output: * err, 0 if no errors, -1 otherwise * * Zachary Wolf * 5/16/05 */ int esp7000_check_errors(int dev_ID) { /* Declare variables */ char err_reg[ESP7000_MAX_CMD]; int err_code; long int time_stamp; char err_msg[ESP7000_MAX_CMD]; int num_scan; int err; /* Initialize */ err = 0; err_code = -1; /* Read the error messages */ while (err_code != 0) { esp7000_out(dev_ID, "TB?"); esp7000_in(dev_ID, err_reg); num_scan = Scan(err_reg, "%s>%i,%i,%s", &err_code, &time_stamp, err_msg); if (num_scan != 3) esp7000_error("Problem reading errors."); if (err_code != 0) { printf("ESP7000 Error: %s\n", err_reg); err = -1; } } /* See if the operator wants to continue if there are errors */ if (err != 0) esp7000_error("esp7000_check_errors found errors"); /* Done */ return err; } /* ************************************************************** */ /* * esp7000_hold_until_move_complete * This function loops until the specified axis has stopped moving. * * Input: * dev_ID, device identifier * axis, axis to check (1, 2, ...) * * Zachary Wolf * 5/16/05 */ void esp7000_hold_until_move_complete(int dev_ID, int axis) { /* Declare variables */ char status_buf[ESP7000_MAX_CMD]; int motion_done_status; enum {MOTION_FALSE, MOTION_TRUE} motion_done; /* Check input parameters */ if (dev_ID < 1 || dev_ID > ESP7000_MAX_NUM_DEV) { Fmt(msg, "%s ESP7000_MAX_NUM_AXES) { Fmt(msg, "%s%i", &motion_done_status); //printf("motion done status: %i\n", motion_done_status); if (motion_done_status == 1) { motion_done = MOTION_TRUE; /* Move complete */ } else { motion_done = MOTION_FALSE; /* Still moving */ Delay(0.1); } } /* Done */ return; } /* ************************************************************** */ /* * esp7000_message * This function handles messages about the ESP7000. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 8/3/98 */ void esp7000_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * esp7000_error * This function handles error messages for the ESP7000. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 8/3/98 */ void esp7000_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nESP7000 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.\n"); fgets(buf, 80, stdin); if (buf[0] == '\n') return; else exit(0); }