forked from zietzm/Helmholtz_Test_Bench
38 lines
1005 B
Python
38 lines
1005 B
Python
# import time
|
|
|
|
from pyps2000b import PS2000B
|
|
import globals as g
|
|
|
|
|
|
def set_devices(xPort, yPort, zPort):
|
|
g.xDevice = PS2000B.PS2000B(xPort)
|
|
g.yDevice = PS2000B.PS2000B(yPort)
|
|
g.zDevice = PS2000B.PS2000B(zPort)
|
|
|
|
|
|
def current_vec(mag_vec): # calculates needed current in each axis for given magnetic field vector
|
|
i_vec = mag_vec/g.Coil_const
|
|
return i_vec
|
|
|
|
|
|
def set_current_vec(i_vec):
|
|
set_current(g.xDevice, i_vec[0])
|
|
set_current(g.yDevice, i_vec[1])
|
|
set_current(g.zDevice, i_vec[2])
|
|
|
|
|
|
def set_current(device, value):
|
|
# ToDo: Check behaviour with only current or only voltage set
|
|
# ToDo: Check behaviour when trying to set too high currents
|
|
if value > 0:
|
|
device.current1 = value
|
|
device.voltage2 = 0
|
|
elif value < 0:
|
|
device.voltage1 = 0
|
|
device.current2 = -value
|
|
elif value == 0:
|
|
device.voltage1 = 0
|
|
device.voltage2 = 0
|
|
else:
|
|
raise ValueError("Invalid current value. (This should never happen.)")
|