From e03b2c8416f4b6a3f16a151e619b918a819ed46e Mon Sep 17 00:00:00 2001 From: Martin Zietz Date: Fri, 4 Dec 2020 14:05:36 +0100 Subject: [PATCH] started work on 3-axis handling --- cage_func.py | 37 +++++++++++++++++++++++++++++++++++++ globals.py | 5 +++++ main.py | 18 ++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 cage_func.py create mode 100644 globals.py create mode 100644 main.py diff --git a/cage_func.py b/cage_func.py new file mode 100644 index 0000000..20087bf --- /dev/null +++ b/cage_func.py @@ -0,0 +1,37 @@ +# 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.)") diff --git a/globals.py b/globals.py new file mode 100644 index 0000000..1bce948 --- /dev/null +++ b/globals.py @@ -0,0 +1,5 @@ +global Coil_const + +global xDevice +global yDevice +global zDevice diff --git a/main.py b/main.py new file mode 100644 index 0000000..0641bb3 --- /dev/null +++ b/main.py @@ -0,0 +1,18 @@ +# import platform +# import time +import numpy as np +import globals as g +import cage_func as func +# from pyps2000b import PS2000B + +# User Inputs/Configuration---------------------------------- +# Coil data: +g.Coil_const = np.array([38.6, 38.45, 37.9])*1e-9 # Coil constants [x,y,z] in T/A + +# 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