/* ************************************************************** */ /* * Module BHVSXY * This module contains functions to measure magnetic field strength * with a Hall probe in a plane. * * Zachary Wolf * 12/18/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "param.h" #include "runparam.h" #include "bhall vs xy ui.h" #include "bhall.h" #include "bhallparam.h" #include "movexy.h" #include "movexyparam.h" #include "imag.h" #include "imagparam.h" #include "imagui.h" /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static char log_file[80]; static char dat_file[80]; static char plt_file[80]; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONS */ void bhvsxy_init(void); void bhvsxy_meas(void); void bhvsxy_dat_meas(int x_meas_num, int y_meas_num, double xpos, double ypos, double imag, double Bhall); void bhvsxy_plt_meas(int x_meas_num, int y_meas_num, double xpos, double ypos, double imag, double Bhall); void bhvsxy_exit(void); void bhvsxy_error(char* message); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************* */ int main(int argc, char *argv[]) { /* Perform all initialization for the program */ bhvsxy_init(); /* Perform the measurements */ bhvsxy_meas(); /* Exit all systems */ bhvsxy_exit(); /* Message */ printf("\nDone\n"); /* Done */ return 0; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * bhvsxy_init * This function is used to initialize Bhall vs XY measurements. * * Zachary Wolf * 12/18/00 */ void bhvsxy_init(void) { /* Declare variables */ struct run_param_struct run_param; int err; struct bhall_param_struct bhall_param; struct movexy_param_struct movexy_param; struct imag_param_struct imag_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, "bhvsxylog", log_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "bhvsxydat", dat_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "bhvsxyplt", plt_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "bhvsxypar", 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); imag_write_header(log_file, BHVSXY_NUM_STAND_CYCLES, BHVSXY_STAND_MAX, BHVSXY_STAND_MIN, BHVSXY_NUM_TEST_CURRENTS, BHVSXY_TEST_CURRENTS); imag_write_header(dat_file, BHVSXY_NUM_STAND_CYCLES, BHVSXY_STAND_MAX, BHVSXY_STAND_MIN, BHVSXY_NUM_TEST_CURRENTS, BHVSXY_TEST_CURRENTS); /* Fill measurement parameters */ for (i = 0; i < BHVSXY_NUM_X_POS; i++) BHVSXY_X_POS[i] = (double)BHVSXY_X_MIN + i * (double)BHVSXY_X_STEP; for (i = 0; i < BHVSXY_NUM_Y_POS; i++) BHVSXY_Y_POS[i] = (double)BHVSXY_Y_MIN + i * (double)BHVSXY_Y_STEP; /* Fill system parameter structures */ movexyparam_fill_param_struct(&movexy_param); imagparam_fill_param_struct(&imag_param); bhallparam_fill_param_struct(&bhall_param); /* Initialize user interfaces */ SetStdioWindowPosition(430, 15); SetStdioWindowSize(300, 995); imagui_init(25, 685, imag_param); imagui_scale_horiz_axis(BHVSXY_NUM_STAND_CYCLES, BHVSXY_STAND_MIN, BHVSXY_STAND_MAX, BHVSXY_NUM_TEST_CURRENTS, BHVSXY_TEST_CURRENTS); bhvsxyui_init(25, 15); bhvsxyui_scale_horiz_axis(BHVSXY_NUM_X_POS, BHVSXY_X_POS); /* Message */ printf("\n\n*** Hall probe mapping program Bhall vs xy ***\n"); /* Initialize the measurement systems */ movexy_init(log_file, movexy_param); bhall_init(log_file, bhall_param); imag_init(log_file, imag_param); /* Done */ return; } /* ************************************************************** */ /* * bhvsxy_meas * This function measures the magnetic field strength using a Hall * probe at equally spaced positions in x and y in a plane. * * Zachary Wolf * 12/18/00 */ void bhvsxy_meas(void) { /* Declare variables */ int i, j, k, l; double imag; double xpos, ypos; double Bhall; /* Set the Hall probe range */ bhall_set_range(BHVSXY_HALL_PROBE_RANGE); /* Standardize the magnet */ if (BHVSXY_NUM_STAND_CYCLES > 0) { printf("\nStandardizing the magnet...\n"); imag_standardize(BHVSXY_STAND_MAX, BHVSXY_STAND_MIN, BHVSXY_NUM_STAND_CYCLES); } /* Message */ printf("\nBeginning a Hall probe map...\n"); /* Loop over the test currents */ for (i = 0; i < BHVSXY_NUM_TEST_CURRENTS; i++) { /* Ramp the magnet */ imag_ramp(BHVSXY_TEST_CURRENTS[i]); for (j = 1; j <= 30; j++) imagui_update(BHVSXY_TEST_CURRENTS[i]); /* Prepare to plot a new set of measurements */ bhvsxyui_clear_plot(); /* Perform the Hall probe measurements */ for (k = 0; k < BHVSXY_NUM_Y_POS; k++) { for (l = 0; l < BHVSXY_NUM_X_POS; l++) { /* Move to the required XY position */ movexy_abs_move(BHVSXY_X_POS[l], BHVSXY_Y_POS[k]); /* Let things settle after the move */ Delay(1.); /* Measure the X and Y positions */ movexy_get_pos(&xpos, &ypos); /* Measure the magnet current */ imag_get_current(&imag); /* Measure the field strength */ bhall_get_B(&Bhall); /* Write the result to the dat file */ bhvsxy_dat_meas(l+1, k+1, xpos, ypos, imag, Bhall); /* Write the result to the plt file */ bhvsxy_plt_meas(l+1, k+1, xpos, ypos, imag, Bhall); /* Display the measured field strength */ bhvsxyui_update_meas(l+1, k+1, xpos, ypos, imag, Bhall); } } /* Move the Hall probe back to the zero position */ printf("\nMoving back to the zero position...\n"); movexy_abs_move(0., 0.); /* End loop over test currents */ } /* Done */ return; } /* ************************************************************** */ /* * bhvsxy_dat_meas * This function writes the results of a magnet strength measurement * to the data file. * * Input: * x_meas_num, x measurement number * y_meas_num, y measurement number * xpos, X position of the Hall probe (m) * ypos, Y position of the Hall probe (m) * imag, magnet current (A) * Bhall, field strength (T) * * Zachary Wolf * 12/18/00 */ void bhvsxy_dat_meas(int x_meas_num, int y_meas_num, double xpos, double ypos, double imag, double Bhall) { /* Declare variables */ FILE* file_ptr; static int call_num; /* Open the dat file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("bhvsxy_dat_meas: Unable to open magnet strength dat file\n"); return; } /* Increment the number of calls */ call_num++; /* Begin a new set of measurements on a new page */ if (call_num > 1 && x_meas_num == 1 && y_meas_num == 1) fprintf(file_ptr, "%c", 12); /* Write a header on the first call */ if (x_meas_num == 1 && y_meas_num == 1) { fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Magnetic Field Strength vs XY\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " X Y X Y Imag Bhall \n"); fprintf(file_ptr, " # # (m) (m) (A) (T) \n"); fprintf(file_ptr, " ----- ----- --------- --------- ---------- -----------\n"); } /* Write the data */ fprintf(file_ptr, " %5i %5i %9.4f %9.4f %10.4f %11.6f\n", x_meas_num, y_meas_num, xpos, ypos, imag, Bhall); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bhvsxy_plt_meas * This function writes the results of a magnet strength measurement * to the plot file. * * Input: * x_meas_num, x measurement number * y_meas_num, y measurement number * xpos, X position of the Hall probe (m) * ypos, Y position of the Hall probe (m) * imag, magnet current (A) * Bhall, field strength (T) * * Zachary Wolf * 12/18/00 */ void bhvsxy_plt_meas(int x_meas_num, int y_meas_num, double xpos, double ypos, double imag, double Bhall) { /* Declare variables */ FILE* file_ptr; static int call_num; /* Open the dat file */ file_ptr = fopen(plt_file, "a"); if (file_ptr == NULL) { printf("bhvsxy_plt_meas: Unable to open magnet strength 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, ";x_num y_num x(m) y(m) imag(A) Bhall(T)\n"); } /* Write the data */ fprintf(file_ptr, "%5i %5i %9.4f %9.4f %10.4f %11.6f\n", x_meas_num, y_meas_num, xpos, ypos, imag, Bhall); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ void bhvsxy_exit(void) { /* Exit the Bhall system */ bhall_exit(); /* Exit the MoveZ system */ movexy_exit(); /* Exit the magnet current system */ imag_exit(); /* Done */ return; } /* ************************************************************** */ /* * bhvsxy_error * This function handles errors for the Bhall vs Z module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/11/98 */ void bhvsxy_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); }