Added function for executing csv-files

This commit is contained in:
Martin Zietz
2021-01-01 18:33:52 +01:00
parent e14dca928f
commit 0dfa013606
3 changed files with 68 additions and 5 deletions
+23
View File
@@ -0,0 +1,23 @@
Time (s);xField (T);yField (T);zField (T)
0,5;0,000015;0,000025;0,00002
1;0,0000155;0,0000245;0,0000205
1,5;0,000016;0,000024;0,000021
2;0,0000165;0,0000235;0,0000215
2,5;0,000017;0,000023;0,000022
3;0,0000175;0,0000225;0,0000225
3,5;0,000018;0,000022;0,000023
4;0,0000185;0,0000215;0,0000235
4,5;0,000019;0,000021;0,000024
5;0,0000195;0,0000205;0,0000245
5,5;0,00002;0,00002;0,000025
6;0,0000205;0,0000195;0,0000245
6,5;0,000021;0,000019;0,000024
7;0,0000215;0,0000185;0,0000235
7,5;0,000022;0,000018;0,000023
8;0,0000225;0,0000175;0,0000225
8,5;0,000023;0,000017;0,000022
9;0,0000235;0,0000165;0,0000215
9,5;0,000024;0,000016;0,000021
10;0,0000245;0,0000155;0,0000205
10,5;0,000025;0,000015;0,00002
11;0,000025;0,000015;0,00002
1 Time (s) xField (T) yField (T) zField (T)
2 0,5 0,000015 0,000025 0,00002
3 1 0,0000155 0,0000245 0,0000205
4 1,5 0,000016 0,000024 0,000021
5 2 0,0000165 0,0000235 0,0000215
6 2,5 0,000017 0,000023 0,000022
7 3 0,0000175 0,0000225 0,0000225
8 3,5 0,000018 0,000022 0,000023
9 4 0,0000185 0,0000215 0,0000235
10 4,5 0,000019 0,000021 0,000024
11 5 0,0000195 0,0000205 0,0000245
12 5,5 0,00002 0,00002 0,000025
13 6 0,0000205 0,0000195 0,0000245
14 6,5 0,000021 0,000019 0,000024
15 7 0,0000215 0,0000185 0,0000235
16 7,5 0,000022 0,000018 0,000023
17 8 0,0000225 0,0000175 0,0000225
18 8,5 0,000023 0,000017 0,000022
19 9 0,0000235 0,0000165 0,0000215
20 9,5 0,000024 0,000016 0,000021
21 10 0,0000245 0,0000155 0,0000205
22 10,5 0,000025 0,000015 0,00002
23 11 0,000025 0,000015 0,00002
+43 -4
View File
@@ -1,5 +1,7 @@
from pyps2000b import PS2000B
import globals as g
import pandas
import time
def set_devices(): # creates device objects for all PSUs
@@ -29,10 +31,9 @@ def setup_arduino():
def safe_arduino(): # sets output pins to low and closes serial connection
for pin in g.RELAY_PINS:
g.ARDUINO.digitalWrite(pin, "LOW")
g.ARDUINO.close()
def print_status(axis): # axis control variable, stored in globals.py
def print_status(axis): # axis = axis control variable, stored in globals.py
device = axis[0] # PSU
channel = axis[1] # output channel on the PSU
print("%s, %0.2f V, %0.2f A"
@@ -48,11 +49,25 @@ def print_status_3():
print_status(g.Z_AXIS)
def set_to_zero(device):
def set_to_zero(device): # sets voltages and currents to 0
device.voltage1 = 0
device.current1 = 0
device.voltage2 = 0
device.current2 = 0
device.current2 = 0
def power_down(): # temporary, set all outputs to 0 but keep connections enabled
set_to_zero(g.XY_DEVICE)
set_to_zero(g.Z_DEVICE)
safe_arduino()
def shut_down(): # shutdown at program end, set outputs to 0 and disable connections
set_to_zero(g.XY_DEVICE)
set_to_zero(g.Z_DEVICE)
deactivate_all()
safe_arduino()
g.ARDUINO.close()
def set_field_simple(vector): # forms magnetic field as specified by vector, w/o cancelling ambient field
@@ -91,3 +106,27 @@ def set_axis_current(axis, value): # sets current with correct polarity on one
device.set_current(abs(value), channel)
maxVoltage = min(max(1.1 * g.MAX_AMPS[axisIndex] * g.RESISTANCES[axisIndex], 12), g.MAX_VOLTS) # limit voltage
device.set_voltage(maxVoltage)
def execute_csv(filepath, printing=0): # runs through csv file containing times and desired field vectors
# csv format: time (s); xField (T); yField (T); zField (T)
# decimal commas
print("Reading File:", filepath)
file = pandas.read_csv(filepath, sep=';', decimal=',', header=0) # read csv file
array = file.to_numpy() # convert csv to array
t_zero = time.time()
t_ref = t_zero
i = 0
print("Starting Execution...")
while i < len(array):
t = time.time() - t_zero
if t >= array[i, 0]:
field_vec = array[i, 1:4]
print("t = %0.2f s, target field vector = " % (array[i, 0]), field_vec)
set_field(field_vec)
i = i + 1
if t - t_ref >= 1 and printing == 1: # print status every second
print_status_3()
t_ref = t
print("File executed, powering down channels.")
power_down() # set currents and voltages to 0, set arduino pins to low
+2 -1
View File
@@ -1,3 +1,4 @@
numpy==1.19.3 # bug in numpy 1.19.4, 1.19.3 used as workaround
pyserial~=3.5
future~=0.18.2
future~=0.18.2
pandas~=1.1.5