/* ************************************************************** */ /* * Module BHVSZ * This module contains functions to measure magnetic field strength * with a Hall probe along a line. * * Zachary Wolf * 1/28/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "param.h" #include "runparam.h" #include "bhall vs z ui.h" #include "bhall.h" #include "bhallparam.h" #include "movez.h" #include "movezparam.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 bhvsz_init(void); void bhvsz_meas(void); void bhvsz_dat_meas(int meas_num, double zpos, double imag, double Bhall); void bhvsz_plt_meas(int meas_num, double zpos, double imag, double Bhall); void bhvsz_exit(void); void bhvsz_error(char* message); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************* */ int main(int argc, char *argv[]) { /* Perform all initialization for the program */ bhvsz_init(); /* Perform the measurements */ bhvsz_meas(); /* Exit all systems */ bhvsz_exit(); /* Message */ printf("\nDone\n"); /* Done */ return 0; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * bhvsz_init * This function is used to initialize Bhall vs Z measurements. * * Zachary Wolf * 2/4/00 */ void bhvsz_init(void) { /* Declare variables */ struct run_param_struct run_param; int err; struct bhall_param_struct bhall_param; struct movez_param_struct movez_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, "bhvszlog", log_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "bhvszdat", dat_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "bhvszplt", plt_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "bhvszpar", 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, BHVSZ_NUM_STAND_CYCLES, BHVSZ_STAND_MAX, BHVSZ_STAND_MIN, BHVSZ_NUM_TEST_CURRENTS, BHVSZ_TEST_CURRENTS); imag_write_header(dat_file, BHVSZ_NUM_STAND_CYCLES, BHVSZ_STAND_MAX, BHVSZ_STAND_MIN, BHVSZ_NUM_TEST_CURRENTS, BHVSZ_TEST_CURRENTS); /* Fill measurement parameters */ for (i = 0; i < BHVSZ_NUM_Z_POS; i++) BHVSZ_Z_POS[i] = (double)BHVSZ_Z_MIN + i * (double)BHVSZ_Z_STEP; /* Fill system parameter structures */ movezparam_fill_param_struct(&movez_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(BHVSZ_NUM_STAND_CYCLES, BHVSZ_STAND_MIN, BHVSZ_STAND_MAX, BHVSZ_NUM_TEST_CURRENTS, BHVSZ_TEST_CURRENTS); bhvszui_init(25, 15); bhvszui_scale_horiz_axis(BHVSZ_NUM_Z_POS, BHVSZ_Z_POS); /* Message */ printf("\n\n*** Hall probe mapping program Bhall vs z ***\n"); /* Initialize the measurement systems */ movez_init(log_file, movez_param); bhall_init(log_file, bhall_param); imag_init(log_file, imag_param); /* Done */ return; } /* ************************************************************** */ /* * bhvsz_meas * This function measures the magnetic field strength using a Hall * probe at equally spaced positions along a path. * * Zachary Wolf * 2/7/00 */ void bhvsz_meas(void) { /* Declare variables */ int i, j, k; double imag; double zpos; double Bhall; /* Set the Hall probe range */ bhall_set_range(BHVSZ_HALL_PROBE_RANGE); /* Standardize the magnet */ if (BHVSZ_NUM_STAND_CYCLES > 0) { printf("\nStandardizing the magnet...\n"); imag_standardize(BHVSZ_STAND_MAX, BHVSZ_STAND_MIN, BHVSZ_NUM_STAND_CYCLES); } /* Message */ printf("\nBeginning a Hall probe map...\n"); /* Loop over the test currents */ for (i = 0; i < BHVSZ_NUM_TEST_CURRENTS; i++) { /* Ramp the magnet */ imag_ramp(BHVSZ_TEST_CURRENTS[i]); for (j = 1; j <= 30; j++) imagui_update(BHVSZ_TEST_CURRENTS[i]); /* Prepare to plot a new set of measurements */ bhvszui_clear_plot(); /* Perform the Hall probe measurements */ for (k = 0; k < BHVSZ_NUM_Z_POS; k++) { /* Move to the required Z position */ movez_abs_move(BHVSZ_Z_POS[k]); /* Let things settle after the move */ Delay(1.); /* Measure the Z position */ movez_get_pos(&zpos); /* Measure the magnet current */ imag_get_current(&imag); /* Measure the field strength */ bhall_get_B(&Bhall); /* Write the result to the dat file */ bhvsz_dat_meas(k+1, zpos, imag, Bhall); /* Write the result to the plt file */ bhvsz_plt_meas(k+1, zpos, imag, Bhall); /* Display the measured field strength */ bhvszui_update_meas(k+1, zpos, imag, Bhall); } /* Move the Hall probe back to the zero position */ printf("\nMoving back to the zero position...\n"); movez_abs_move(0.); /* End loop over test currents */ } /* Done */ return; } /* ************************************************************** */ /* * bhvsz_dat_meas * This function writes the results of a magnet strength measurement * to the data file. * * Input: * meas_num, measurement number * zpos, Z position of the Hall probe (m) * imag, magnet current (A) * Bhall, field strength (T) * * Zachary Wolf * 2/18/00 */ void bhvsz_dat_meas(int meas_num, double zpos, 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("bhvsz_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 && meas_num == 1) fprintf(file_ptr, "%c", 12); /* Write a header on the first call */ if (meas_num == 1) { fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Magnetic Field Strength vs Z\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Z Imag Bhall \n"); fprintf(file_ptr, " # (m) (A) (T) \n"); fprintf(file_ptr, " ----- --------- ---------- -----------\n"); } /* Write the data */ fprintf(file_ptr, " %5i %9.4f %10.4f %11.6f\n", meas_num, zpos, imag, Bhall); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bhvsz_plt_bl_vs_x * This function writes the results of a magnet strength measurement * to the plot file. * * Input: * meas_num, measurement number * zpos, Z position of the Hall probe (m) * imag, magnet current (A) * Bhall, field strength (T) * * Zachary Wolf * 2/18/00 */ void bhvsz_plt_meas(int meas_num, double zpos, 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("bhvsz_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, ";num z(m) imag(A) Bhall(T)\n"); } /* Write the data */ fprintf(file_ptr, "%5i %9.4f %10.4f %11.6f\n", meas_num, zpos, imag, Bhall); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ void bhvsz_exit(void) { /* Exit the Bhall system */ bhall_exit(); /* Exit the MoveZ system */ movez_exit(); /* Exit the magnet current system */ imag_exit(); /* Done */ return; } /* ************************************************************** */ /* * bhvsz_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 bhvsz_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); }