From 0b15116fd978e3586e390d261190077f4717a845 Mon Sep 17 00:00:00 2001 From: Martin Zietz Date: Fri, 4 Dec 2020 16:54:17 +0100 Subject: [PATCH] Added most functions needed for cage operation --- Testing1.py | 4 ++-- cage_func.py | 32 +++++++++++++++++++++++++------- globals.py | 1 + main.py | 14 +++++++++++--- pyps2000b/PS2000B.py | 12 ++++++++++++ 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/Testing1.py b/Testing1.py index 9eb1f2d..e004f49 100644 --- a/Testing1.py +++ b/Testing1.py @@ -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) diff --git a/cage_func.py b/cage_func.py index 20087bf..2c0b9f9 100644 --- a/cage_func.py +++ b/cage_func.py @@ -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.)") diff --git a/globals.py b/globals.py index 1bce948..091f2be 100644 --- a/globals.py +++ b/globals.py @@ -1,4 +1,5 @@ global Coil_const +global ambientField global xDevice global yDevice diff --git a/main.py b/main.py index 0641bb3..3961e0a 100644 --- a/main.py +++ b/main.py @@ -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)) \ No newline at end of file +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() diff --git a/pyps2000b/PS2000B.py b/pyps2000b/PS2000B.py index d8122a7..60e4463 100644 --- a/pyps2000b/PS2000B.py +++ b/pyps2000b/PS2000B.py @@ -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)