/* ************************************************************** */ /* * Module BTVSZ * This module contains functions to measure the transverse magnetic * field strength with a rotating coil along a line. * * Zachary Wolf * 2/22/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "param.h" #include "runparam.h" #include "btcoil vs z ui.h" #include "btcoil.h" #include "btcoilparam.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 btvsz_init(void); void btvsz_meas(void); void btvsz_dat_meas(int meas_num, double zpos, double imag, double Bt, double th, double Bx, double By); void btvsz_plt_meas(int meas_num, double zpos, double imag, double Bt, double th, double Bx, double By); void btvsz_exit(void); void btvsz_error(char* message); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************* */ int main(int argc, char *argv[]) { /* Perform all initialization for the program */ btvsz_init(); /* Perform the measurements */ btvsz_meas(); /* Exit all systems */ btvsz_exit(); /* Message */ printf("\nDone\n"); /* Done */ return 0; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * btvsz_init * This function is used to initialize Btcoil vs Z measurements. * * Zachary Wolf * 2/22/00 */ void btvsz_init(void) { /* Declare variables */ struct run_param_struct run_param; int err; struct btcoil_param_struct btcoil_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, "btvszlog", log_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "btvszdat", dat_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "btvszplt", plt_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "btvszpar", 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, BTVSZ_NUM_STAND_CYCLES, BTVSZ_STAND_MAX, BTVSZ_STAND_MIN, BTVSZ_NUM_TEST_CURRENTS, BTVSZ_TEST_CURRENTS); imag_write_header(dat_file, BTVSZ_NUM_STAND_CYCLES, BTVSZ_STAND_MAX, BTVSZ_STAND_MIN, BTVSZ_NUM_TEST_CURRENTS, BTVSZ_TEST_CURRENTS); /* Get system parameters */ btcoilparam_fill_param_struct(&btcoil_param); movezparam_fill_param_struct(&movez_param); imagparam_fill_param_struct(&imag_param); for (i = 0; i < BTVSZ_NUM_Z_POS; i++) BTVSZ_Z_POS[i] = (double)BTVSZ_Z_MIN + i * (double)BTVSZ_Z_STEP; /* Initialize the user interface */ SetStdioWindowPosition(430, 15); SetStdioWindowSize(300, 995); btvszui_init(25, 15); btvszui_scale_horiz_axis(BTVSZ_NUM_Z_POS, BTVSZ_Z_POS); imagui_init(25, 685, imag_param); imagui_scale_horiz_axis(BTVSZ_NUM_STAND_CYCLES, BTVSZ_STAND_MIN, BTVSZ_STAND_MAX, BTVSZ_NUM_TEST_CURRENTS, BTVSZ_TEST_CURRENTS); /* Message */ printf("\n\n*** Transverse field mapping program Btcoil vs z ***\n"); /* Initialize all measurement systems */ btcoil_init(log_file, btcoil_param); movez_init(log_file, movez_param); imag_init(log_file, imag_param); /* Done */ return; } /* ************************************************************** */ /* * btvsz_meas * This function measures the transverse magnetic field strength using a * rotating coil at equally spaced positions along a path. * * Zachary Wolf * 2/22/00 */ void btvsz_meas(void) { /* Declare variables */ int i, j, k; double imag; double zpos; double Bt, th; double Bx, By; /* Standardize the magnet */ if (BTVSZ_NUM_STAND_CYCLES > 0) { printf("\nStandardizing the magnet...\n"); imag_standardize(BTVSZ_STAND_MAX, BTVSZ_STAND_MIN, BTVSZ_NUM_STAND_CYCLES); } /* Message */ printf("\nBeginning a transverse field map...\n"); /* Loop over the test currents */ for (i = 0; i < BTVSZ_NUM_TEST_CURRENTS; i++) { /* Ramp the magnet */ imag_ramp(BTVSZ_TEST_CURRENTS[i]); for (j = 1; j <= 30; j++) imagui_update(BTVSZ_TEST_CURRENTS[i]); /* Prepare to plot a new set of measurements */ btvszui_clear_plot(); /* Perform the transverse field measurements */ for (k = 0; k < BTVSZ_NUM_Z_POS; k++) { /* Move to the required Z position */ movez_abs_move(BTVSZ_Z_POS[k]); /* Let things settle after the move */ Delay(1.); /* Message */ printf("Measuring...\n"); /* Measure the Z position */ movez_get_pos(&zpos); /* Measure the magnet current */ imag_get_current(&imag); /* Measure the transverse field strength */ btcoil_get_Bt(&Bt, &th); /* Calculate the x and y components */ Bx = Bt * cos(th*3.1415926/180.); By = Bt * sin(th*3.1415926/180.); /* Write the result to the dat file */ btvsz_dat_meas(k+1, zpos, imag, Bt, th, Bx, By); /* Write the result to the plt file */ btvsz_plt_meas(k+1, zpos, imag, Bt, th, Bx, By); /* Display the measured field strength */ btvszui_update_meas(k+1, zpos, imag, Bt, th, Bx, By); } /* Move the coil back to the zero position */ printf("\nMoving back to the zero position...\n"); movez_abs_move(0.); /* End loop over test currents */ } /* Done */ return; } /* ************************************************************** */ /* * btvsz_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) * Bt, transverse field strength (T) * th, angle from the horizontal to the south pole (deg) * Bx, x component of the transverse field strength (T) * By, y component of the transverse field strength (T) * * Zachary Wolf * 2/22/00 */ void btvsz_dat_meas(int meas_num, double zpos, double imag, double Bt, double th, double Bx, double By) { /* Declare variables */ FILE* file_ptr; static int call_num; /* Open the dat file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("btvsz_dat_meas: Unable to open magnet strength dat file\n"); return; } /* Increment the number of calls */ call_num++; /* Start a new series 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, " Transverse Magnetic Field Strength vs Z\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Z Imag Btrans Angle Bx By \n"); fprintf(file_ptr, " # (m) (A) (G) (deg) (G) (G) \n"); fprintf(file_ptr, " ----- --------- ---------- -------- -------- -------- --------\n"); } /* Write the data */ fprintf(file_ptr, " %5i %9.4f %10.4f %8.2f %8.2f %8.2f %8.2f\n", meas_num, zpos, imag, Bt*10000., th, Bx*10000., By*10000.); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * btvsz_plt_meas * 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) * Bt, transverse field strength (T) * th, angle from the horizontal to the south pole (deg) * Bx, x component of the transverse field strength (T) * By, y component of the transverse field strength (T) * * Zachary Wolf * 2/22/00 */ void btvsz_plt_meas(int meas_num, double zpos, double imag, double Bt, double th, double Bx, double By) { /* Declare variables */ FILE* file_ptr; static int call_num; /* Open the dat file */ file_ptr = fopen(plt_file, "a"); if (file_ptr == NULL) { printf("btvsz_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) Bt(G) th(deg) Bx(G) By(G)\n"); } /* Write the data */ fprintf(file_ptr, " %5i %9.4f %10.4f %8.2f %8.2f %8.2f %8.2f\n", meas_num, zpos, imag, Bt*10000., th, Bx*10000., By*10000.); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ void btvsz_exit(void) { /* Exit the Bhall system */ btcoil_exit(); /* Exit the MoveZ system */ movez_exit(); /* Exit the magnet current system */ imag_exit(); /* Done */ return; } /* ************************************************************** */ /* * btvsz_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 btvsz_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); }