diff --git a/Dasha_LCRCode.py b/Dasha_LCRCode.py index ca5f391..ef1c30e 100644 --- a/Dasha_LCRCode.py +++ b/Dasha_LCRCode.py @@ -354,11 +354,23 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True ################################################################# DASHA'S CODE HERE ############################################################################################## # TODO: modify b field scan script for Dasha, to be used for the KLC controller - +# NOTE: all voltage values are the RMS values, and have the unit V def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float, res:float, base_file_name='', reversescan_bool=False, zerowhenfin_bool=False, loopscan_bool=False)->None: + # TODO: docstring + """_summary_ + Args: + handle (int): _description_ + init_voltage (float): _description_ + final_voltage (float): _description_ + res (float): _description_ + base_file_name (str, optional): _description_. Defaults to ''. + reversescan_bool (bool, optional): _description_. Defaults to False. + zerowhenfin_bool (bool, optional): _description_. Defaults to False. + loopscan_bool (bool, optional): _description_. Defaults to False. + """ def pyramid_list(lst) -> Union[list, np.ndarray]: """reverses the list and removes the first element of reversed list. Then, this is appended to the end of the original list and returned as the 'pyramid' list. @@ -385,43 +397,37 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float, start_time = time.time() # start of the scan function - # if '2101014' in instr_info and (magnet_coil=='y-axis'): # single power supply - # if (min_bval< -BY_MAX) or (max_bval > BY_MAX): - # raise ValueError('Input limits exceed that of the magnet By! Please input smaller limits.') - # elif '2301034' in instr_info: # dual power supply - # if magnet_coil=='z-axis': # check if its the coils for Bz - # if (min_bval < -BZ_MAX) or (max_bval > BZ_MAX): - # raise ValueError('Input limits exceed that of the magnet (Bz)! Please input smaller limits.') - # write_no_echo(instr, 'CHAN 1') - # elif magnet_coil=='x-axis': # checks limits of Bx - # if (min_bval< -BX_MAX) or (max_bval > BX_MAX): - # raise ValueError('Input limits exceed that of the magnet Bx! Please input smaller limits.') - # write_no_echo(instr, 'CHAN 2') - # else: - # raise ConnectionError('Device is not connected!') + # Check if the given start and/or end voltages are within the accepted limits + if (init_voltage >= V_MAX): + raise ValueError('Maximum device voltage exceeded! Please input a smaller initial voltage!') + elif (end_voltage >= V_MAX): + raise ValueError('Maximum device voltage exceeded! Please input a smaller final voltage!') + elif (res >= V_MAX): + raise ValueError('Entered step size exceeds 25 V! Please choose a smaller step size!') - write_no_echo(instr, f'LLIM {min_bval*10};ULIM {max_bval*10}') # sets the given limits, must convert to kG for the device to read - bval_lst = np.arange(min_bval, max_bval + res, res) # creates list of B values to measure at, with given resolution, in T + # creates list of voltage values to measure at, with given resolution, in V + voltage_lst = np.arange(init_voltage, final_voltage + res, res) + # TODO: remove the two lines below, probs not needed init_lim, subsequent_lim = 'LLIM', 'ULIM' - init_sweep, subsequent_sweep = 'DOWN', 'UP' + init_sweep, subsequent_sweep = 'DOWN', 'UP' - - # if reverse scan, then flip the values in the b list, and swap the initial limit and sweep conditions + # if reverse scan, flips the direction of the scan if reversescan_bool: - bval_lst = bval_lst[::-1] + voltage_lst = voltage_lst[::-1] init_lim, subsequent_lim = subsequent_lim, init_lim init_sweep, subsequent_sweep = subsequent_sweep, init_sweep # creates the pyramid list of B vals if one were to perform a hysteresis measurement if loopscan_bool: - bval_lst = pyramid_list(bval_lst) + voltage_lst = pyramid_list(voltage_lst) - total_points = len(bval_lst) - middle_index_bval_lst = total_points // 2 + total_points = len(voltage_lst) + middle_index_voltage_lst = total_points // 2 intensity_data = [] # To store data from each scan cwd = os.getcwd() # save original directory + # TODO: edit the helpe_scan_func and scanning loop below, after this, the code should be complete! # NOTE: helper function for the scanning loop def helper_scan_func(idx, bval, instr=instr, init_lim=init_lim, init_sweep=init_sweep, subsequent_lim=subsequent_lim, subsequent_sweep=subsequent_sweep, sleep=5): @@ -442,12 +448,12 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float, print(f'Actual magnet strength: {actual_bval} T,', f'Target magnet strength: {bval} T') #scanning loop - for i, bval in enumerate(bval_lst): + for i, bval in enumerate(voltage_lst): if not loopscan_bool: helper_scan_func(i, bval) else: - if i <= middle_index_bval_lst: + if i <= middle_index_voltage_lst: helper_scan_func(i, bval) else: helper_scan_func(i, bval, instr=instr, init_lim=subsequent_lim, init_sweep=subsequent_sweep, @@ -511,11 +517,11 @@ try: if(len(devs)<=0): print('There is no device connected') sys.exit() - klc = devs[0] + klc = devs[0] # devs is a list of 2-element lists, in which the serial-nr. and device name are contained serialnumber = klc[0] # Connect device - KLC_handle = klcOpen(serialnumber, 115200, 3) + KLC_handle = klcOpen(serialnumber, 115200, 3) # baud rate and timeout(in s) if(KLC_handle<0): print("open ", serialnumber, " failed") sys.exit()