forked from zietzm/Helmholtz_Test_Bench
Minor bug fixes
This commit is contained in:
@@ -113,9 +113,9 @@ class ExecCSVThread(Thread):
|
||||
|
||||
def read_csv_to_array(filepath): # convert a given csv file to a numpy array
|
||||
# csv format: time [s], xField [T], yField [T], zField [T] (german excel)
|
||||
# decimal or period commas. Do not use these characters as a thousands seperator!
|
||||
# decimal or period commas. Do not use these characters as a thousands separator!
|
||||
with open(filepath, 'r') as csv_file:
|
||||
# Normalize seperators
|
||||
# Normalize separators
|
||||
csv_string = csv_file.read()
|
||||
# read csv file without column headers
|
||||
file = pandas.read_csv(StringIO(csv_string), sep=',', decimal='.', header=0)
|
||||
@@ -163,12 +163,12 @@ def plot_field_sequence(array, width, height): # create plot of fixed size (pix
|
||||
# modify data to show instantaneous jumps in field to reflect test bench operation
|
||||
new_array = np.array([[0, 0, 0, 0]], dtype=float) # initialize modified array, zeros to show start from no fields
|
||||
|
||||
last_vals = [0, 0, 0] # [x,y,z] field values from last data point (zero here), used to create step in data
|
||||
last_values = [0, 0, 0] # [x,y,z] field values from last data point (zero here), used to create step in data
|
||||
for row in array[:, 0:4]: # go through each row in the original array
|
||||
# create extra datapoint at current timestamp, with field values from last to create a "step" in the plot:
|
||||
new_array = np.append(new_array, [[row[0], *last_vals]], axis=0)
|
||||
new_array = np.append(new_array, [[row[0], *last_values]], axis=0)
|
||||
new_array = np.append(new_array, [row], axis=0) # add actual datapoint for current timestamp
|
||||
last_vals = row[1:4] # save values from current timestamp for next
|
||||
last_values = row[1:4] # save values from current timestamp for next
|
||||
new_array = np.append(new_array, [[new_array[-1, 0], 0, 0, 0]], axis=0) # append last datapoint with 0 fields
|
||||
|
||||
# extract data and plot:
|
||||
|
||||
+17
-19
@@ -653,7 +653,7 @@ class ExecuteCSVMode(Frame):
|
||||
figure = csv_threading.plot_field_sequence(self.sequence_array, width, height) # create figure to be displayed
|
||||
# Clear previous plots first
|
||||
try:
|
||||
if self.plot_canvas != None:
|
||||
if self.plot_canvas is not None:
|
||||
self.plot_canvas.get_tk_widget().destroy()
|
||||
except Exception as e:
|
||||
ui_print("Something went wrong while plotting csv data!", e)
|
||||
@@ -675,13 +675,12 @@ class ExecuteCSVMode(Frame):
|
||||
# Save dictionary to disk
|
||||
save_dict_list_to_csv2('test_sequence_rotation.csv', rot_sequence, query_path=True)
|
||||
ui_print("Saved test sequence to disc.")
|
||||
print("Flag1")
|
||||
|
||||
def generate_load_csv_sequence(self): # Generate and load csv sequence
|
||||
# Generate rotation data
|
||||
t, x, y, z = self.generate_csv_sequence()
|
||||
# Write data into array
|
||||
temp_array = np.ndarray((len(t),4))
|
||||
temp_array = np.ndarray((len(t), 4))
|
||||
for i in range(len(t)):
|
||||
temp_array[i] = [t[i], x[i], y[i], z[i]]
|
||||
self.sequence_array = temp_array
|
||||
@@ -697,17 +696,16 @@ class ExecuteCSVMode(Frame):
|
||||
else: # nothing went wrong
|
||||
self.execute_button["state"] = "normal" # activate run button --> enable execution
|
||||
|
||||
|
||||
def generate_csv_sequence(self):
|
||||
# Some fixed values
|
||||
rot_center_gmean_max = 100 # [µT] Maximum geometric mean
|
||||
rot_center_geom_mean_max = 100 # [µT] Maximum geometric mean
|
||||
rot_center_default = [0, 0, 0] # [µT]
|
||||
rot_mag_default = 100 # [µT]
|
||||
rot_mag_max = 180 # [µT]
|
||||
rot_rate_default = 1 # [deg/s]
|
||||
rot_rate_max = 360 # [deg/s]
|
||||
rot_timestep_default = 1 # [s]
|
||||
rot_timestep_min = 0.2 # [s]
|
||||
rot_time_step_default = 1 # [s]
|
||||
rot_time_step_min = 0.2 # [s]
|
||||
# Initialize and get vectors
|
||||
rot_vector = [0, 0, 0]
|
||||
rot_center = [0, 0, 0]
|
||||
@@ -731,7 +729,7 @@ class ExecuteCSVMode(Frame):
|
||||
if rot_mag < 0:
|
||||
ui_print("Warning: Magnetic field magnitude cannot be negative. Changing sign automatically.")
|
||||
rot_mag = -rot_mag
|
||||
elif rot_mag ==0:
|
||||
elif rot_mag == 0:
|
||||
ui_print("Warning: Magnetic field magnitude cannot be zero. Setting default automatically.")
|
||||
rot_mag = rot_mag_default
|
||||
elif rot_mag > rot_mag_max:
|
||||
@@ -739,16 +737,16 @@ class ExecuteCSVMode(Frame):
|
||||
rot_mag = rot_mag_default
|
||||
self.rot_mag_vars.set("{:.3f}".format(rot_mag))
|
||||
# Checking center point
|
||||
if np.sqrt(rot_center[0]**2+rot_center[1]**2+rot_center[2]**2) > rot_center_gmean_max:
|
||||
ui_print("Warning: Rotation center excessive. Setting to zero automatically.")
|
||||
rot_center = rot_center_default
|
||||
if np.sqrt(rot_center[0]**2+rot_center[1]**2+rot_center[2]**2) > rot_center_geom_mean_max:
|
||||
ui_print("Warning: Rotation center excessive. Setting to zero automatically.")
|
||||
rot_center = rot_center_default
|
||||
for i in range(len(rot_center)):
|
||||
self.rot_center_vars[i].set("{:.3f}".format(rot_center[i]))
|
||||
# Checking rotation rate
|
||||
if rot_rate < 0:
|
||||
ui_print("Warning: Rotation rate cannot be negative. Changing sign automatically.")
|
||||
rot_rate = -rot_rate
|
||||
elif rot_mag ==0:
|
||||
elif rot_mag == 0:
|
||||
ui_print("Warning: Rotation rate cannot be zero. Setting default automatically.")
|
||||
rot_rate = rot_rate_default
|
||||
elif rot_rate > rot_rate_max:
|
||||
@@ -759,12 +757,12 @@ class ExecuteCSVMode(Frame):
|
||||
if rot_time_step < 0:
|
||||
ui_print("Warning: Time step cannot be negative. Changing sign automatically.")
|
||||
rot_time_step = -rot_time_step
|
||||
elif rot_time_step ==0:
|
||||
elif rot_time_step == 0:
|
||||
ui_print("Warning: Time step cannot be zero. Setting default automatically.")
|
||||
rot_time_step = rot_timestep_default
|
||||
elif rot_time_step < rot_timestep_min:
|
||||
rot_time_step = rot_time_step_default
|
||||
elif rot_time_step < rot_time_step_min:
|
||||
ui_print("Warning: Time step too small. Setting default automatically.")
|
||||
rot_time_step = rot_timestep_default
|
||||
rot_time_step = rot_time_step_default
|
||||
self.time_step_vars.set("{:.3f}".format(rot_time_step))
|
||||
# Find perpendicular vectors
|
||||
if v[1] == 0 and v[2] == 0:
|
||||
@@ -773,7 +771,7 @@ class ExecuteCSVMode(Frame):
|
||||
a = np.cross(v, [1, 0, 0])
|
||||
b = np.cross(v, a)
|
||||
# Calculate timing
|
||||
cycle_time = (360 / rot_rate) / rot_time_step
|
||||
cycle_time = (360 / rot_rate)
|
||||
arr_len = int(np.floor(cycle_time / rot_time_step))
|
||||
# Initialize vectors
|
||||
th = 0 # [rad]
|
||||
@@ -783,7 +781,7 @@ class ExecuteCSVMode(Frame):
|
||||
z = np.zeros(arr_len) # [T]
|
||||
# Calculate vectors
|
||||
for i in range(arr_len):
|
||||
th = th + rot_rate * np.pi / 180
|
||||
th = th + rot_rate * np.pi / 180 * rot_time_step
|
||||
t[i] = i * rot_time_step
|
||||
x[i] = (rot_center[0] + rot_mag * np.cos(th) * a[0] + rot_mag * np.sin(th) * b[0])*1e-6
|
||||
y[i] = (rot_center[1] + rot_mag * np.cos(th) * a[1] + rot_mag * np.sin(th) * b[1])*1e-6
|
||||
@@ -1961,7 +1959,7 @@ class CalibrateMagnetometerComplete(Frame):
|
||||
state='readonly')
|
||||
axis_data.grid(row=row_counter + row, column=1 + column, padx=5, pady=5, sticky="nw")
|
||||
results_label_unit = Label(calibration_results_frame, text="-")
|
||||
results_label_unit.grid(row=row_counter + row, column=1 + column + 1, padx=5, pady=5, sticky="nw")
|
||||
results_label_unit.grid(row=row_counter + row, column=1 + 3, padx=5, pady=5, sticky="nw")
|
||||
row_counter += 3
|
||||
"""
|
||||
# A_mat
|
||||
|
||||
Reference in New Issue
Block a user