forked from zietzm/Helmholtz_Test_Bench
Added most functions needed for cage operation
This commit is contained in:
+2
-2
@@ -50,8 +50,8 @@ device1.enable_output(1)
|
||||
time.sleep(5)
|
||||
print("Device status 1: %s" % device1.get_device_status_information(0))
|
||||
print("Device status 2: %s" % device1.get_device_status_information(1))
|
||||
print("Current output 1: %0.2f V , %0.2f A" % (device1.voltage1, device1.current1))
|
||||
print("Current output 2: %0.2f V , %0.2f A" % (device1.voltage2, device1.current2))
|
||||
print("Output 1: %0.2f V , %0.2f A" % (device1.voltage1, device1.current1))
|
||||
print("Output 2: %0.2f V , %0.2f A" % (device1.voltage2, device1.current2))
|
||||
|
||||
time.sleep(5)
|
||||
device1.disable_output(0)
|
||||
|
||||
+25
-7
@@ -4,24 +4,42 @@ from pyps2000b import PS2000B
|
||||
import globals as g
|
||||
|
||||
|
||||
def set_devices(xPort, yPort, zPort):
|
||||
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 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 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 set_current_vec(i_vec):
|
||||
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):
|
||||
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:
|
||||
@@ -34,4 +52,4 @@ def set_current(device, value):
|
||||
device.voltage1 = 0
|
||||
device.voltage2 = 0
|
||||
else:
|
||||
raise ValueError("Invalid current value. (This should never happen.)")
|
||||
raise ValueError("Invalid current value. (This should be impossible.)")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
global Coil_const
|
||||
global ambientField
|
||||
|
||||
global xDevice
|
||||
global yDevice
|
||||
|
||||
@@ -6,13 +6,21 @@ import cage_func as func
|
||||
# from pyps2000b import PS2000B
|
||||
|
||||
# User Inputs/Configuration----------------------------------
|
||||
# Coil data:
|
||||
# Desired output:
|
||||
mag_vec1 = np.array([10, 10, 5])*1e-6
|
||||
|
||||
# Constants:
|
||||
g.Coil_const = np.array([38.6, 38.45, 37.9])*1e-9 # Coil constants [x,y,z] in T/A
|
||||
g.ambientField = np.array([80])*1e-6 # ambient magnetic field in measurement area, to be cancelled out
|
||||
|
||||
# COM-Ports for power supply units:
|
||||
xPort = "COM1" # placeholders
|
||||
yPort = "COM3"
|
||||
zPort = "COM5"
|
||||
|
||||
func.set_devices(xPort, yPort, zPort)
|
||||
print(func.current_vec(np.array([10, 10, 5])*1e-6))
|
||||
func.set_devices(xPort, yPort, zPort) # initiate communication, set handles
|
||||
func.activate_all() # activate remote control and outputs
|
||||
|
||||
func.set_field_simple(mag_vec1)
|
||||
|
||||
func.deactivate_all()
|
||||
|
||||
@@ -278,6 +278,18 @@ class PS2000B:
|
||||
_ = self.__send_and_receive(telegram.get_byte_array())
|
||||
self.update_device_information(channel)
|
||||
|
||||
def enable_all(self):
|
||||
self.enable_remote_control(0)
|
||||
self.enable_remote_control(1)
|
||||
self.enable_output(0)
|
||||
self.enable_output(1)
|
||||
|
||||
def disable_all(self):
|
||||
self.disable_output(0)
|
||||
self.disable_output(1)
|
||||
self.disable_remote_control(0)
|
||||
self.disable_remote_control(1)
|
||||
|
||||
def enable_remote_control(self, channel):
|
||||
self.__send_device_control(ControlParam.SWITCH_MODE_CMD, ControlParam.SWITCH_MODE_REMOTE, channel)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user