forked from zietzm/Helmholtz_Test_Bench
3686891a6d
- added functions for status print - renamed Testing1.py to example2.py - prepared test master script
77 lines
2.2 KiB
Python
77 lines
2.2 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 print_status(device):
|
|
print("Channel 1: %s, %0.2f V, %0.2f A" % (device.get_device_status_information(0), device.voltage1, device.current1))
|
|
print("Channel 2: %s, %0.2f V, %0.2f A" % (device.get_device_status_information(1), device.voltage1, device.current1))
|
|
|
|
|
|
def print_status_3():
|
|
print("X-Axis:")
|
|
print_status(g.xDevice)
|
|
print("Y-Axis:")
|
|
print_status(g.yDevice)
|
|
print("Z-Axis:")
|
|
print_status(g.zDevice)
|
|
|
|
|
|
def set_to_zero(device):
|
|
device.voltage1 = 0
|
|
device.current1 = 0
|
|
device.current2 = 0
|
|
device.current2 = 0
|
|
|
|
|
|
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_axis_current(g.xDevice, i_vec[0])
|
|
set_axis_current(g.yDevice, i_vec[1])
|
|
set_axis_current(g.zDevice, i_vec[2])
|
|
|
|
|
|
def set_axis_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.)")
|