forked from zietzm/Helmholtz_Test_Bench
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
# import time
|
|
|
|
from pyps2000b import PS2000B
|
|
import globals as g
|
|
|
|
|
|
def set_devices(xPort, yPort, zPort): # creates device objects for all PSUs
|
|
g.xDevice = PS2000B.PS2000B(xPort)
|
|
g.yDevice = PS2000B.PS2000B(yPort)
|
|
g.zDevice = PS2000B.PS2000B(zPort)
|
|
|
|
|
|
def activate_all(): # enables remote control and output on all PSUs and channels
|
|
g.xDevice.enable_all()
|
|
g.yDevice.enable_all()
|
|
g.zDevice.enable_all()
|
|
|
|
|
|
def deactivate_all(): # disables remote control and output on all PSUs and channels
|
|
g.xDevice.disable_all()
|
|
g.yDevice.disable_all()
|
|
g.zDevice.disable_all()
|
|
|
|
|
|
def set_field_simple(vector): # forms magnetic field as specified by vector, w/o cancelling ambient field
|
|
i_vec = vector/g.Coil_const
|
|
set_current_vec(i_vec)
|
|
|
|
|
|
def set_field(vector): # forms magnetic field as specified by vector, corrected for ambient field
|
|
field = vector - g.ambientField
|
|
i_vec = field/g.Coil_const
|
|
set_current_vec(i_vec)
|
|
|
|
|
|
def set_current_vec(i_vec): # sets needed currents on each axis for given vector
|
|
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): # sets current with correct polarity on one axis
|
|
# 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 be impossible.)")
|