/* ************************************************************** */ /* * Module GAP * This module contains functions to measure the gap of a magnet * and take out the roll, pitch,... * * Zachary Wolf * 4/14/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "param.h" #include "runparam.h" #include "gap vs z ui.h" #include "sensor.h" #include "sensorparam.h" #include "movez.h" #include "movezparam.h" /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static char log_file[80]; static char dat_file[80]; static char plt_file[80]; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONS */ void gap_init(void); void gap_meas(void); void gap_exit(void); void gap_calc_dist(double z, double v[], double d[]); void gap_calc_arm_roll(double z, double* roll); void gap_calc_arm_xy(double z, double* x, double* y); void gap_calc_gap(double d[], double* gap_out, double* gap_in, double* frac_grad, double* height_out, double* height_in, double* roll, double* x); void gap_calc_mag_dof(double h_out_vs_z[], double roll_vs_z[], double x_vs_z[], double z_meas_vs_z[], double* height, double* pitch, double* roll, double* twist, double* x, double* yaw); void gap_calc_motions(double height, double pitch, double roll, double twist, double x, double yaw, double* dy_front, double* dy_back_zmin, double* dy_back_zmax, double* dx_zmin, double* dx_zmax); void gap_dat_gap(double z, double gap_out, double gap_in, double frac_grad, double height_out, double height_in, double roll, double x); void gap_dat_mag_dof(double height, double pitch, double roll, double twist, double x, double yaw); void gap_dat_motions(double dy_front, double dy_back_zmin, double dy_back_zmax, double dx_zmin, double dx_zmax); void gap_plt_gap(double z, double v[], double d[], double gap_out, double gap_in, double frac_grad, double height_out, double height_in, double roll, double x); void gap_log_calc_dist(double arm_roll, double arm_x, double arm_y, double v[], double d_raw[], double d_corr[], double d_garage[], double d[]); void gap_message(char* message); void gap_error(char* message); /* ************************************************************* */ /* PUBLIC FUNCTIONS */ /* ************************************************************* */ int main(int argc, char *argv[]) { /* Perform all initialization for the program */ gap_init(); /* Perform the measurements */ gap_meas(); /* Exit all systems */ gap_exit(); /* Message */ printf("\nDone\n"); /* Done */ return 0; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * gap_init * This function is used to initialize the gap measurements. * * Zachary Wolf * 4/14/00 */ void gap_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, "gaplog", log_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "gapdat", dat_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "gapplt", plt_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "gappar", 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 < GAP_NUM_MAG_Z_POS; i++) GAP_MAG_Z_POS[i] = (double)GAP_MAG_START_Z_POS + i * (double)GAP_MAG_Z_STEP; /* Initialize the user interface */ SetStdioWindowPosition(500, 50); SetStdioWindowSize(240, 930); gapui_init(25, 50); gapui_scale_horiz_axis(GAP_NUM_MAG_Z_POS, GAP_MAG_Z_POS); /* Message */ printf("\n\n*** Gap Measurement System ***\n"); /* Initialize all systems */ sensor_init(log_file, sensor_param); movez_init(log_file, movez_param); /* Done */ return; } /* ************************************************************** */ /* * gap_meas * This function measures the magnet gap along the magnet. * * Zachary Wolf * 4/14/00 */ void gap_meas(void) { /* Declare variables */ int i; double zpos; double v[GAP_NUM_SENSORS]; double d[GAP_NUM_SENSORS]; double gap_out, gap_in, frac_grad; double height_out, height_in, roll; double x; double height, pitch, twist, yaw; double h_out_vs_z[GAP_NUM_MAG_Z_POS]; double roll_vs_z[GAP_NUM_MAG_Z_POS]; double x_vs_z[GAP_NUM_MAG_Z_POS]; double z_meas_vs_z[GAP_NUM_MAG_Z_POS]; double dy_front, dy_back_zmin, dy_back_zmax, dx_zmin, dx_zmax; /* Message */ printf("\nBeginning a magnet gap map...\n"); /* Perform a measurement in the home (garage 0) position */ /* Move to the required Z position */ movez_abs_move(GAP_GARAGE0_Z_POS); /* 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(GAP_NUM_SENSORS, GAP_SENSOR_CHAN, v); /* Establish the reference distances to the poles in the garage */ gap_calc_dist(zpos, v, d); /* Calculate magnet characteristics */ gap_calc_gap(d, &gap_out, &gap_in, &frac_grad, &height_out, &height_in, &roll, &x); /* Write the result to the dat file */ gap_dat_gap(zpos, gap_out, gap_in, frac_grad, height_out, height_in, roll, x); /* Write the result to the plt file */ gap_plt_gap(zpos, v, d, gap_out, gap_in, frac_grad, height_out, height_in, roll, x); /* Display the results */ gapui_update_meas(zpos, v, d, height_out, roll, x); /* Perform the gap measurements in the magnet */ for (i = 0; i < GAP_NUM_MAG_Z_POS; i++) { /* Move to the required Z position */ movez_abs_move(GAP_MAG_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(GAP_NUM_SENSORS, GAP_SENSOR_CHAN, v); /* Calculate distances to the poles relative to the garage distances */ gap_calc_dist(zpos, v, d); /* Calculate magnet characteristics */ gap_calc_gap(d, &gap_out, &gap_in, &frac_grad, &height_out, &height_in, &roll, &x); /* Save the required values */ h_out_vs_z[i] = height_out; roll_vs_z[i] = roll; x_vs_z[i] = x; z_meas_vs_z[i] = zpos; /* Write the result to the dat file */ gap_dat_gap(zpos, gap_out, gap_in, frac_grad, height_out, height_in, roll, x); /* Write the result to the plt file */ gap_plt_gap(zpos, v, d, gap_out, gap_in, frac_grad, height_out, height_in, roll, x); /* Display the results */ gapui_update_meas(zpos, v, d, height_out, roll, x); } /* Perform a measurement in the second garage (garage 1) position */ /* Move to the required Z position */ movez_abs_move(GAP_GARAGE1_Z_POS); /* 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(GAP_NUM_SENSORS, GAP_SENSOR_CHAN, v); /* Establish the reference distances to the poles in the garage */ gap_calc_dist(zpos, v, d); /* Calculate magnet characteristics */ gap_calc_gap(d, &gap_out, &gap_in, &frac_grad, &height_out, &height_in, &roll, &x); /* Write the result to the dat file */ gap_dat_gap(zpos, gap_out, gap_in, frac_grad, height_out, height_in, roll, x); /* Write the result to the plt file */ gap_plt_gap(zpos, v, d, gap_out, gap_in, frac_grad, height_out, height_in, roll, x); /* Display the results */ gapui_update_meas(zpos, v, d, height_out, roll, x); /* 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); /* Perform a final measurement in the home (garage 0) position */ /* Move to the required Z position */ movez_abs_move(GAP_GARAGE0_Z_POS); /* 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(GAP_NUM_SENSORS, GAP_SENSOR_CHAN, v); /* Establish the reference distances to the poles in the garage */ gap_calc_dist(zpos, v, d); /* Calculate magnet characteristics */ gap_calc_gap(d, &gap_out, &gap_in, &frac_grad, &height_out, &height_in, &roll, &x); /* Write the result to the dat file */ gap_dat_gap(zpos, gap_out, gap_in, frac_grad, height_out, height_in, roll, x); /* Write the result to the plt file */ gap_plt_gap(zpos, v, d, gap_out, gap_in, frac_grad, height_out, height_in, roll, x); /* Display the results */ gapui_update_meas(zpos, v, d, height_out, roll, x); /* Calculate the roll, pitch, etc. of the magnet */ gap_calc_mag_dof(h_out_vs_z, roll_vs_z, x_vs_z, z_meas_vs_z, &height, &pitch, &roll, &twist, &x, &yaw); /* Write the roll, pitch, etc. to the data file */ gap_dat_mag_dof(height, pitch, roll, twist, x, yaw); /* Calculate the motions necessary to bring the magnet into alignment */ gap_calc_motions(height, pitch, roll, twist, x, yaw, &dy_front, &dy_back_zmin, &dy_back_zmax, &dx_zmin, &dx_zmax); /* Write the motions to the data file */ gap_dat_motions(dy_front, dy_back_zmin, dy_back_zmax, dx_zmin, dx_zmax); /* Done */ return; } /* ************************************************************** */ void gap_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; } /* ************************************************************** */ /* * gap_calc_dist * This function calculates the distance from each capacitive sensor * to the steel. It subtracts the initial measurement in the garage, * so distances are measured relative to the garage. * * Input: * z, z position of the arm (m) * v[0 to GAP_NUM_SENSORS - 1], voltages from the sensors (V) * * Output: * d[0 to GAP_NUM_SENSORS - 1], distance from each sensor to the pole (m), angle of the arm (rad), ... * * Zachary Wolf * 4/20/00 */ void gap_calc_dist(double z, double v[], double d[]) { /* Declare variables */ static int num_call = 0; double d_raw[GAP_NUM_SENSORS]; double d_corr[GAP_NUM_SENSORS]; static double d_garage[GAP_NUM_SENSORS]; int i; double arm_roll_level, arm_roll_map, arm_roll; double arm_x, arm_y; /* Check that no sensor is too close to a pole */ /* Stop if a sensor is less than 20 mils from a pole */ if (v[INDEX_UI] < 20. / GAP_MILS_PER_VOLT) gap_error("A capacitive sensor is too close to a pole."); if (v[INDEX_UO] < 20. / GAP_MILS_PER_VOLT) gap_error("A capacitive sensor is too close to a pole."); if (v[INDEX_LI] < 20. / GAP_MILS_PER_VOLT) gap_error("A capacitive sensor is too close to a pole."); if (v[INDEX_LO] < 20. / GAP_MILS_PER_VOLT) gap_error("A capacitive sensor is too close to a pole."); if (v[INDEX_UF] < 20. / GAP_MILS_PER_VOLT) gap_error("A capacitive sensor is too close to a pole."); if (v[INDEX_LF] < 20. / GAP_MILS_PER_VOLT) gap_error("A capacitive sensor is too close to a pole."); /* Apply sensor calibrations */ d_raw[INDEX_UI] = v[INDEX_UI] * GAP_MILS_PER_VOLT * GAP_METERS_PER_MIL; d_raw[INDEX_UO] = v[INDEX_UO] * GAP_MILS_PER_VOLT * GAP_METERS_PER_MIL; d_raw[INDEX_LI] = v[INDEX_LI] * GAP_MILS_PER_VOLT * GAP_METERS_PER_MIL; d_raw[INDEX_LO] = v[INDEX_LO] * GAP_MILS_PER_VOLT * GAP_METERS_PER_MIL; d_raw[INDEX_UF] = v[INDEX_UF] * GAP_MILS_PER_VOLT * GAP_METERS_PER_MIL; d_raw[INDEX_LF] = v[INDEX_LF] * GAP_MILS_PER_VOLT * GAP_METERS_PER_MIL; d_raw[INDEX_TILT] = v[INDEX_TILT] * GAP_MRAD_PER_VOLT * GAP_RADIAN_PER_MRAD; /* Account for the slope of the poles */ /* The cosine factor gives the vertical distance instead of the sloping distance */ d_raw[INDEX_UI] = d_raw[INDEX_UI] * cos(GAP_POLE_ANGLE_DEG * 3.1415926 / 180.); d_raw[INDEX_UO] = d_raw[INDEX_UO] * cos(GAP_POLE_ANGLE_DEG * 3.1415926 / 180.); d_raw[INDEX_LI] = d_raw[INDEX_LI] * cos(GAP_POLE_ANGLE_DEG * 3.1415926 / 180.); d_raw[INDEX_LO] = d_raw[INDEX_LO] * cos(GAP_POLE_ANGLE_DEG * 3.1415926 / 180.); d_raw[INDEX_UF] = d_raw[INDEX_UF]; d_raw[INDEX_LF] = d_raw[INDEX_LF]; d_raw[INDEX_TILT] = d_raw[INDEX_TILT]; /* Save the measurements in the garage */ num_call++; if (num_call == 1) { for (i = 0; i < GAP_NUM_SENSORS; i++) d_garage[i] = d_raw[i]; } /* Correct for the roll angle of the arm relative to its value in the garage */ /* Positive roll angles move the arm up */ arm_roll_level = d_raw[INDEX_TILT] - d_garage[INDEX_TILT]; gap_calc_arm_roll(z, &arm_roll_map); if (fabs(arm_roll_level - arm_roll_map) > .00003) gap_message("The measured roll of the arm does not agree with the map."); arm_roll = arm_roll_level; d_corr[INDEX_UI] = d_raw[INDEX_UI] + GAP_L_ARM_INNER * arm_roll; d_corr[INDEX_UO] = d_raw[INDEX_UO] + GAP_L_ARM_OUTER * arm_roll; d_corr[INDEX_LI] = d_raw[INDEX_LI] - GAP_L_ARM_INNER * arm_roll; d_corr[INDEX_LO] = d_raw[INDEX_LO] - GAP_L_ARM_OUTER * arm_roll; d_corr[INDEX_UF] = d_raw[INDEX_UF]; d_corr[INDEX_LF] = d_raw[INDEX_LF]; d_corr[INDEX_TILT] = d_raw[INDEX_TILT]; /* Correct for the xy position of the arm relative to its value in the garage */ /* X is toward the magnet, Y is up */ gap_calc_arm_xy(z, &arm_x, &arm_y); d_corr[INDEX_UI] = d_corr[INDEX_UI] + arm_y; d_corr[INDEX_UO] = d_corr[INDEX_UO] + arm_y; d_corr[INDEX_LI] = d_corr[INDEX_LI] - arm_y; d_corr[INDEX_LO] = d_corr[INDEX_LO] - arm_y; d_corr[INDEX_UF] = d_corr[INDEX_UF] + arm_x; d_corr[INDEX_LF] = d_corr[INDEX_LF] + arm_x; d_corr[INDEX_TILT] = d_corr[INDEX_TILT]; /* Return positions measured with respect to the initial positions */ d[INDEX_UI] = d_corr[INDEX_UI] - d_garage[INDEX_UI]; d[INDEX_UO] = d_corr[INDEX_UO] - d_garage[INDEX_UO]; d[INDEX_LI] = d_corr[INDEX_LI] - d_garage[INDEX_LI]; d[INDEX_LO] = d_corr[INDEX_LO] - d_garage[INDEX_LO]; d[INDEX_UF] = d_corr[INDEX_UF] - d_garage[INDEX_UF]; d[INDEX_LF] = d_corr[INDEX_LF] - d_garage[INDEX_LF]; d[INDEX_TILT] = d_corr[INDEX_TILT] - d_garage[INDEX_TILT]; /* Log the calculation */ gap_log_calc_dist(arm_roll, arm_x, arm_y, v, d_raw, d_corr, d_garage, d); /* Done */ return; } /* ************************************************************** */ /* * gap_calc_arm_roll * This function calculates the roll angle of the arm from a table * made during mapping. * * Input: * z, the z position of the arm (m) * * Output: * roll, the roll angle of the arm (rad) * * Zachary Wolf * 3/14/01 */ void gap_calc_arm_roll(double z, double* roll) { /* Define variables */ int i; int z_index = -1; /* Find the neighboring z positions in the table */ for (i = 0; i <= GAP_NUM_Z_POS_ARM_ROLL - 2; i++) { if (z >= GAP_Z_POS_ARM_ROLL[i] && z < GAP_Z_POS_ARM_ROLL[i+1]) { z_index = i; break; } } if (z_index == -1) gap_error("Problem in gap_calc_arm_roll"); /* Calculate the arm roll */ *roll = GAP_ARM_ROLL_MRAD[z_index] + ((z - GAP_Z_POS_ARM_ROLL[z_index]) / (GAP_Z_POS_ARM_ROLL[z_index+1] - GAP_Z_POS_ARM_ROLL[z_index])) * (GAP_ARM_ROLL_MRAD[z_index+1] - GAP_ARM_ROLL_MRAD[z_index]); *roll = *roll / 1000.; /* Convert from mrad to rad */ /* Done */ return; } /* ************************************************************** */ /* * gap_calc_arm_xy * This function calculates the xy position of the arm from a table * made during mapping. * * Input: * z, the z position of the arm (m) * * Output: * x, the x position of the arm (m) * y, the y position of the arm (m) * * Zachary Wolf * 3/14/01 */ void gap_calc_arm_xy(double z, double* x, double* y) { /* Define variables */ int i; int z_index = -1; double x_micron, y_micron; /* Find the neighboring z positions in the table */ for (i = 0; i <= GAP_NUM_Z_POS_ARM_XY - 2; i++) { if (z >= GAP_Z_POS_ARM_XY[i] && z < GAP_Z_POS_ARM_XY[i+1]) { z_index = i; break; } } if (z_index == -1) gap_error("Problem in gap_calc_arm_xy"); /* Calculate the arm's x and y positions */ x_micron = GAP_ARM_X_MICRON[z_index] + ((z - GAP_Z_POS_ARM_XY[z_index]) / (GAP_Z_POS_ARM_XY[z_index+1] - GAP_Z_POS_ARM_XY[z_index])) * (GAP_ARM_X_MICRON[z_index+1] - GAP_ARM_X_MICRON[z_index]); y_micron = GAP_ARM_Y_MICRON[z_index] + ((z - GAP_Z_POS_ARM_XY[z_index]) / (GAP_Z_POS_ARM_XY[z_index+1] - GAP_Z_POS_ARM_XY[z_index])) * (GAP_ARM_Y_MICRON[z_index+1] - GAP_ARM_Y_MICRON[z_index]); /* Convert from microns to meters */ *x = x_micron / 1.e6; *y = y_micron / 1.e6; /* Done */ return; } /* ************************************************************** */ /* * gap_calc_gap * This function calculates the gap size, gap gradient, and the * midplane height and roll angle. * * Input: * d[0 to GAP_NUM_SENSORS - 1], distance from each sensor to the pole (m), angle of the arm (rad), ... * * Output: * gap_out, outer gap size (m) * gap_in, inner gap size (m) * frac_grad, fractional gap gradient (1/m) * height_out, height of the outer gap center (m) * height_in, height of the inner gap center (m) * roll, roll angle of the magnet (rad) * x, horizontal x position of the magnet (m) * * Zachary Wolf * 5/1/00 */ void gap_calc_gap(double d[], double* gap_out, double* gap_in, double* frac_grad, double* height_out, double* height_in, double* roll, double* x) { /* Calculate the gap sizes */ *gap_out = d[INDEX_UO] + d[INDEX_LO] + GAP_REF_GAP_OUT; *gap_in = d[INDEX_UI] + d[INDEX_LI] + GAP_REF_GAP_IN; *frac_grad = (*gap_out - *gap_in) / GAP_DIST_OUT_IN / ((*gap_out + *gap_in) / 2.); /* Calculate the midplane heights */ *height_out = (d[INDEX_UO] - d[INDEX_LO]) / 2.; *height_in = (d[INDEX_UI] - d[INDEX_LI]) / 2.; *roll = (*height_in - *height_out) / GAP_DIST_OUT_IN; /* Calculate the horizontal x position */ *x = (d[INDEX_UF] + d[INDEX_LF]) / 2.; /* Done */ return; } /* ************************************************************** */ /* * gap_calc_mag_dof * This function calculates the height, roll, pitch, etc. of the magnet. * * Input: * h_out_vs_z[0 to GAP_NUM_MAG_Z_POS - 1], midplane heights vs z (m) * roll_vs_z[0 to GAP_NUM_MAG_Z_POS - 1], magnet roll vs z (rad) * x_vs_z[0 to GAP_NUM_MAG_Z_POS - 1], horizontal x position vs z (m) * z_meas_vs_z[0 to GAP_NUM_MAG_Z_POS - 1], measured z position vs z index (m) * * Output: * height, height of the gap midplane at the magnet center (m) * pitch, angle of the height vs z (rad) * roll, magnet roll angle (rad) * twist, change of roll with z (rad/m) * x, horizontal x position at the magnet center (m) * yaw, angle of the x vs z (rad) * * Zachary Wolf * 5/3/00 */ void gap_calc_mag_dof(double h_out_vs_z[], double roll_vs_z[], double x_vs_z[], double z_meas_vs_z[], double* height, double* pitch, double* roll, double* twist, double* x, double* yaw) { /* Declare variables */ int i; double z_centered[GAP_NUM_MAG_Z_POS]; double z_min, z_max, z_cent; double best_fit[GAP_NUM_MAG_Z_POS]; double slope, intercept, mse; /* Translate the z coordinates so z=0 is at the magnet center */ z_min = z_meas_vs_z[0]; z_max = z_meas_vs_z[GAP_NUM_MAG_Z_POS - 1]; z_cent = (z_max + z_min) / 2.; for (i = 0; i < GAP_NUM_MAG_Z_POS; i++) z_centered[i] = z_meas_vs_z[i] - z_cent; /* Fit a line to the height vs z data */ /* Calculate the height at the center and the pitch */ LinFit(z_centered, h_out_vs_z, GAP_NUM_MAG_Z_POS, best_fit, &slope, &intercept, &mse); *height = intercept; *pitch = atan(slope); /* Fit a line to the roll vs z data */ /* Calculate the roll at the center and the twist */ LinFit(z_centered, roll_vs_z, GAP_NUM_MAG_Z_POS, best_fit, &slope, &intercept, &mse); *roll = intercept; *twist = slope; /* Fit a line to the x vs z data */ /* Calculate the x at the center and the yaw */ LinFit(z_centered, x_vs_z, GAP_NUM_MAG_Z_POS, best_fit, &slope, &intercept, &mse); *x = intercept; *yaw = atan(slope); /* Done */ return; } /* ************************************************************** */ /* * gap_calc_motions * This function calculates the height, roll, pitch, etc. of the magnet. * * Input: * height, height of the gap midplane at the magnet center (m) * pitch, angle of the height vs z (rad) * roll, magnet roll angle (rad) * twist, change of roll with z (rad/m) * x, horizontal x position at the magnet center (m) * yaw, angle of the x vs z (rad) * * Output: * dy_front, change in front (gap side) jack height (m) * dy_back_zmin, change in back small z end jack height (m) * dy_back_zmax, change in back large z end jack height (m) * dx_zmin, change in small z x adjust (m) * dx_zmax, change in large z x adjust (m) * * Zachary Wolf * 5/3/00 */ void gap_calc_motions(double height, double pitch, double roll, double twist, double x, double yaw, double* dy_front, double* dy_back_zmin, double* dy_back_zmax, double* dx_zmin, double* dx_zmax) { /* Initialize motions */ *dy_front = 0.; *dy_back_zmin = 0.; *dy_back_zmax = 0.; *dx_zmin = 0.; *dx_zmax = 0.; /* Roll adjust */ *dy_front += 0.; *dy_back_zmin += -tan(roll) * GAP_DIST_BETWN_FRONT_BACK_Y_MEAS; *dy_back_zmax += -tan(roll) * GAP_DIST_BETWN_FRONT_BACK_Y_MEAS; /* Height adjust */ *dy_front += -height; *dy_back_zmin += -height; *dy_back_zmax += -height; /* Pitch adjust */ *dy_front += 0.; *dy_back_zmin += tan(pitch) * GAP_DIST_BETWN_ZMIN_ZMAX_Y_MEAS / 2.; *dy_back_zmax += -tan(pitch) * GAP_DIST_BETWN_ZMIN_ZMAX_Y_MEAS / 2.; /* Twist adjust */ // No twist adjust on these magnets /* X adjust */ *dx_zmin += -x; *dx_zmax += -x; /* Yaw adjust */ *dx_zmin += tan(yaw) * GAP_DIST_BETWN_ZMIN_ZMAX_X_MEAS / 2.; *dx_zmax += -tan(yaw) * GAP_DIST_BETWN_ZMIN_ZMAX_X_MEAS / 2.; /* Subtract the effect of the roll adjust on x */ *dx_zmin += -tan(roll) * GAP_DIST_BETWN_BOTTOM_AND_GAP; *dx_zmax += -tan(roll) * GAP_DIST_BETWN_BOTTOM_AND_GAP; /* Done */ return; } /* ************************************************************** */ /* * gap_dat_gap * This function writes the z position, the gap size, gap gradient, and the * midplane height and roll angle to the data file. * * Input: * z, z position along the magnet (m) * gap_out, outer gap size (m) * gap_in, inner gap size (m) * frac_grad, fractional gap gradient (1/m) * height_out, height of the outer gap center (m) * height_in, height of the inner gap center (m) * roll, roll angle of the magnet (rad) * x, horizontal x position of the magnet (m) * * Zachary Wolf * 5/18/00 */ void gap_dat_gap(double z, double gap_out, double gap_in, double frac_grad, double height_out, double height_in, double roll, double x) { /* Declare variables */ FILE* file_ptr; static int call_num; /* Open the dat file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("gap_dat_gap: 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, " Magnet Gap Measurements vs Z\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Z Gap Out Gap In HeightO HeightI Roll X \n"); fprintf(file_ptr, " (m) (mm) (mm) (mm) (mm) (mrad) (mm) \n"); fprintf(file_ptr, "------- ------- ------- ------- ------- ------- -------\n"); } /* Write the data */ fprintf(file_ptr, "%7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", z, gap_out*1000., gap_in*1000., height_out*1000., height_in*1000., roll*1000., x*1000.); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * gap_dat_mag_dof * This function writes the magnet height, roll, pitch, etc. to the * data file. * * Input: * height, height of the gap midplane at the magnet center (m) * pitch, angle of the height vs z (rad) * roll, magnet roll angle (rad) * twist, change of roll with z (rad/m) * x, horizontal x position at the magnet center (m) * yaw, angle of the x vs z (rad) * * Zachary Wolf * 5/30/00 */ void gap_dat_mag_dof(double height, double pitch, double roll, double twist, double x, double yaw) { /* Declare variables */ FILE* file_ptr; /* Open the dat file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("gap_dat_mag_dof: Unable to open the data file\n"); return; } /* Write the magnet orientation parameters */ fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "Magnet Orientation:\n"); fprintf(file_ptr, "Height = %7.3f mm\n", height*1000.); fprintf(file_ptr, "Pitch = %7.3f mrad\n", pitch*1000.); fprintf(file_ptr, "Roll = %7.3f mrad\n", roll*1000.); fprintf(file_ptr, "Twist = %7.3f mrad/m\n", twist*1000.); fprintf(file_ptr, "X = %7.3f mm\n", x*1000.); fprintf(file_ptr, "Yaw = %7.3f mrad\n", yaw*1000.); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * gap_dat_motions * This function writes the required motions to bring the magnet * into alignment to the data file. * * Input: * dy_front, change in front (gap side) jack height (m) * dy_back_zmin, change in back small z jack height (m) * dy_back_zmax, change in back large z jack height (m) * dx_zmin, change in small z x adjust (m) * dx_zmax, change in large z x adjust (m) * * Zachary Wolf * 5/16/00 */ void gap_dat_motions(double dy_front, double dy_back_zmin, double dy_back_zmax, double dx_zmin, double dx_zmax) { /* Declare variables */ FILE* file_ptr; /* Open the dat file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("gap_dat_motions: Unable to open the data file\n"); return; } /* Begin on a new page */ //fprintf(file_ptr, "%c", 12); /* Write the required motions */ fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Required Motions To Bring The Magnet Into Alignment\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Top View\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " -----------------------\n"); fprintf(file_ptr, " | O --|\n"); fprintf(file_ptr, " | y2 | |x2 x2 = %7.1f mils\n", dx_zmax / GAP_METERS_PER_MIL); fprintf(file_ptr, " | --|\n"); fprintf(file_ptr, " | |\n"); fprintf(file_ptr, " | |\n"); fprintf(file_ptr, " | |\n"); fprintf(file_ptr, " | |\n"); fprintf(file_ptr, " +z | | y2 = %7.1f mils\n", dy_back_zmax / GAP_METERS_PER_MIL); fprintf(file_ptr, " ^ |y3 |\n"); fprintf(file_ptr, " |-> |O | y3 = %7.1f mils\n", dy_front / GAP_METERS_PER_MIL); fprintf(file_ptr, " +x | |\n"); fprintf(file_ptr, " | | y1 = %7.1f mils\n", dy_back_zmin / GAP_METERS_PER_MIL); fprintf(file_ptr, " | |\n"); fprintf(file_ptr, " | |\n"); fprintf(file_ptr, " | |\n"); fprintf(file_ptr, " | |\n"); fprintf(file_ptr, " | --|\n"); fprintf(file_ptr, " | y1 | |x1 x1 = %7.1f mils\n", dx_zmin / GAP_METERS_PER_MIL); fprintf(file_ptr, " | O --|\n"); fprintf(file_ptr, " -----------------------\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Gap Side Back Side\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " +x is to the right in the figure\n"); fprintf(file_ptr, " +y is up\n"); fprintf(file_ptr, " +z is to the top of the figure\n"); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * gap_plt_gap * This function writes the z position, the gap size, gap gradient, and the * midplane height and roll angle to a plotting file. * * Input: * z, z position along the magnet (m) * v[0 to GAP_NUM_SENSORS - 1], voltages from the sensors (V) * d[0 to GAP_NUM_SENSORS - 1], distance from each sensor to the pole (m), angle of the arm (rad), ... * gap_out, outer gap size (m) * gap_in, inner gap size (m) * frac_grad, fractional gap gradient (1/m) * height_out, height of the outer gap center (m) * height_in, height of the inner gap center (m) * roll, roll angle of the magnet (rad) * x, horizontal x position of the magnet (m) * * Zachary Wolf * 5/17/00 */ void gap_plt_gap(double z, double v[], double d[], double gap_out, double gap_in, double frac_grad, double height_out, double height_in, double roll, double x) { /* 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("gap_plt_gap: 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(m), V0(V), ..., Vn-1(V), d0(mm), ..., dn-1(mm), gap_out(mm), gap_in(mm), frac_grad(1/m), height_out(mm), height_in(mm), roll(mrad), x(mm)\n"); } /* Write the data */ fprintf(file_ptr, "%7.3f", z); fprintf(file_ptr, " "); for (i = 0; i < GAP_NUM_SENSORS; i++) fprintf(file_ptr, " %7.3f", v[i]); fprintf(file_ptr, " "); for (i = 0; i < GAP_NUM_SENSORS; i++) fprintf(file_ptr, " %7.3f", d[i]*1000.); fprintf(file_ptr, " "); fprintf(file_ptr, " %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", gap_out*1000., gap_in*1000., frac_grad, height_out*1000., height_in*1000., roll*1000., x*1000.); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * gap_log_calc_dist * This function logs the sensor distance calculation results. * * Input: * arm_roll, roll angle of the arm (rad) * arm_x, x position of the arm (m) * arm_y, y position of the arm (m) * v[GAP_NUM_SENSORS], voltages from the sensors (V) * d_raw[GAP_NUM_SENSORS], quantity each sensor is measuring (m) or (rad) * d_corr[GAP_NUM_SENSORS], sensor measurement corrected for tilt of the arm (m) or (rad) * d_garage[GAP_NUM_SENSORS], sensor measurements in the garage (m) or (rad) * d[GAP_NUM_SENSORS], tilt corrected measurements relative to the garage values (m) or (rad) * * Zachary Wolf * 5/30/00 */ void gap_log_calc_dist(double arm_roll, double arm_x, double arm_y, double v[], double d_raw[], double d_corr[], double d_garage[], double d[]) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { printf("gap_log_calc_dist: Unable to open log file\n"); return; } /* Write the data */ fprintf(file_ptr, "%s Sensor distance calculations:\n", TimeStr()); fprintf(file_ptr, " Arm roll = %11.6f rad\n", arm_roll); fprintf(file_ptr, " Arm X = %11.6f m, Arm Y = %11.6f m\n", arm_x, arm_y); fprintf(file_ptr, " Sensor, voltage (V), d_raw (m or rad), d_corr (m or rad), d_garage (m or rad), d (m or rad)\n"); fprintf(file_ptr, " UI %11.6f %11.6f %11.6f %11.6f %11.6f\n", v[INDEX_UI], d_raw[INDEX_UI], d_corr[INDEX_UI], d_garage[INDEX_UI], d[INDEX_UI]); fprintf(file_ptr, " UO %11.6f %11.6f %11.6f %11.6f %11.6f\n", v[INDEX_UO], d_raw[INDEX_UO], d_corr[INDEX_UO], d_garage[INDEX_UO], d[INDEX_UO]); fprintf(file_ptr, " LI %11.6f %11.6f %11.6f %11.6f %11.6f\n", v[INDEX_LI], d_raw[INDEX_LI], d_corr[INDEX_LI], d_garage[INDEX_LI], d[INDEX_LI]); fprintf(file_ptr, " LO %11.6f %11.6f %11.6f %11.6f %11.6f\n", v[INDEX_LO], d_raw[INDEX_LO], d_corr[INDEX_LO], d_garage[INDEX_LO], d[INDEX_LO]); fprintf(file_ptr, " UF %11.6f %11.6f %11.6f %11.6f %11.6f\n", v[INDEX_UF], d_raw[INDEX_UF], d_corr[INDEX_UF], d_garage[INDEX_UF], d[INDEX_UF]); fprintf(file_ptr, " LF %11.6f %11.6f %11.6f %11.6f %11.6f\n", v[INDEX_LF], d_raw[INDEX_LF], d_corr[INDEX_LF], d_garage[INDEX_LF], d[INDEX_LF]); fprintf(file_ptr, " TILT %11.6f %11.6f %11.6f %11.6f %11.6f\n", v[INDEX_TILT], d_raw[INDEX_TILT], d_corr[INDEX_TILT], d_garage[INDEX_TILT], d[INDEX_TILT]); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * gap_message * This function handles messages for the Gap vs Z module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void gap_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * gap_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 gap_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); }