From dba8e9f8ff331bfdd1da0933a4588013ea20957c Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 18 Nov 2024 22:25:15 -0600 Subject: [PATCH 01/53] Add KDC101 class --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 9cdd755..a3e9bd2 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -323,6 +323,11 @@ def get_position(self) -> float: def stop(self): pass +class KDC101(Kinesis): + def __init__(self): + self._device = + + if __name__ == '__main__': controller = BrushlessDCMotor() controller.connect(serialnumbers_brushless[0]) From 9cb8b7a3e2e22b5b80361590ead5abd7f7fa84ff Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 18 Nov 2024 22:31:50 -0600 Subject: [PATCH 02/53] Update kdc101 --- .../hardware/kinesis.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index a3e9bd2..c7ec9e0 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -19,6 +19,7 @@ clr.AddReference("Thorlabs.MotionControl.FilterFlipperCLI") clr.AddReference("Thorlabs.MotionControl.Benchtop.BrushlessMotorCLI") clr.AddReference("Thorlabs.MotionControl.KCube.PiezoCLI") +clr.AddReference("Thorlabs.MotionControl.KCube.DCServoCLI") import Thorlabs.MotionControl.FilterFlipperCLI as FilterFlipper import Thorlabs.MotionControl.IntegratedStepperMotorsCLI as Integrated @@ -26,6 +27,7 @@ import Thorlabs.MotionControl.GenericMotorCLI as Generic import Thorlabs.MotionControl.Benchtop.BrushlessMotorCLI as BrushlessMotorCLI import Thorlabs.MotionControl.KCube.PiezoCLI as KCubePiezo +import Thorlabs.MotionControl.KCube.DCServoCLI as KCube Device.DeviceManagerCLI.BuildDeviceList() serialnumbers_integrated_stepper = [str(ser) for ser in @@ -35,6 +37,7 @@ serialnumbers_brushless = [str(ser) for ser in Device.DeviceManagerCLI.GetDeviceList(BrushlessMotorCLI.BenchtopBrushlessMotor.DevicePrefix)] serialnumbers_piezo = [str(ser) for ser in Device.DeviceManagerCLI.GetDeviceList(KCubePiezo.KCubePiezo.DevicePrefix)] +serialnumbers_kdc101 = [str(ser) for ser in Device.DeviceManagerCLI.GetDeviceList(KCube.KCubeDCServo.DevicePrefix)] class Kinesis: @@ -325,7 +328,33 @@ def stop(self): class KDC101(Kinesis): def __init__(self): - self._device = + self._device = KCube.KCubeDCServo = None + def connect(self, serial: int): + if serial in serialnumbers_kdc101: + self._device = KCube.KCubeDCServo.CreateDCServo(serial) + self._device.Connect(serial) + self._device.StartPolling(250) + self._device.EnableDevice() + self._device.GetMotorConfiguration(serial) + else: + raise ValueError('Invalid Serial Number') + + def get_position(self): + return Decimal.ToDouble(self._device.RequestPosition()) + + def move_abs(self, position: float, callback=None): + if callback is not None: + callback = Action[UInt64](callback) + else: + callback = 0 + self._device.SetPosition(Decimal(position), callback) + + def home(self, callback=None): + if callback is not None: + callback = Action[UInt64](callback) + else: + callback = 0 + self._device.Home(callback) if __name__ == '__main__': From aae7bf661cbfc8594977f798858f22c886267de5 Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:11:47 +0900 Subject: [PATCH 03/53] Test and debug - init - connect --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index c7ec9e0..9270c77 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -326,16 +326,17 @@ def get_position(self) -> float: def stop(self): pass -class KDC101(Kinesis): +class KDC101(Kinesis): # DK - Rename once we finish writing the hardware def __init__(self): - self._device = KCube.KCubeDCServo = None + self._device: KCube.DCServo = None + def connect(self, serial: int): if serial in serialnumbers_kdc101: - self._device = KCube.KCubeDCServo.CreateDCServo(serial) + self._device = KCube.KCubeDCServo.CreateKCubeDCServo(serial) self._device.Connect(serial) self._device.StartPolling(250) self._device.EnableDevice() - self._device.GetMotorConfiguration(serial) + # self._device.GetMotorConfiguration(serial) else: raise ValueError('Invalid Serial Number') @@ -347,7 +348,8 @@ def move_abs(self, position: float, callback=None): callback = Action[UInt64](callback) else: callback = 0 - self._device.SetPosition(Decimal(position), callback) + # self._device.SetPosition(Decimal(position), callback) + self._device.MoveTo(Decimal(position), callback) def home(self, callback=None): if callback is not None: @@ -356,7 +358,6 @@ def home(self, callback=None): callback = 0 self._device.Home(callback) - if __name__ == '__main__': controller = BrushlessDCMotor() controller.connect(serialnumbers_brushless[0]) From a003d4468ddfe4c3a48123878cba355dc2b7ca2d Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 18 Nov 2024 23:14:38 -0600 Subject: [PATCH 04/53] Update the initialization --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index c7ec9e0..579b3fb 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -328,14 +328,21 @@ def stop(self): class KDC101(Kinesis): def __init__(self): - self._device = KCube.KCubeDCServo = None + self._device: KCube.KCubeDCServo = None def connect(self, serial: int): if serial in serialnumbers_kdc101: - self._device = KCube.KCubeDCServo.CreateDCServo(serial) + self._device = KCube.KCubeDCServo.CreateKCubeDCServo(serial) self._device.Connect(serial) + time.sleep(0.25) self._device.StartPolling(250) + time.sleep(0.25) self._device.EnableDevice() - self._device.GetMotorConfiguration(serial) + time.sleep(0.25) + + if not self._device.IsSettingsInitialized(): + raise Exception("Device not initialized") + + # self._device.GetMotorConfiguration(serial) else: raise ValueError('Invalid Serial Number') @@ -347,7 +354,7 @@ def move_abs(self, position: float, callback=None): callback = Action[UInt64](callback) else: callback = 0 - self._device.SetPosition(Decimal(position), callback) + self._device.MoveTo(Decimal(position), callback) def home(self, callback=None): if callback is not None: From 999ac9b0bab57dc03acdee9929f47508bea6eed5 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 18 Nov 2024 23:15:42 -0600 Subject: [PATCH 05/53] Comment out get_position --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 579b3fb..3df6e96 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -346,8 +346,8 @@ def connect(self, serial: int): else: raise ValueError('Invalid Serial Number') - def get_position(self): - return Decimal.ToDouble(self._device.RequestPosition()) + # def get_position(self): #Not implemented? + # return Decimal.ToDouble(self._device.RequestPosition()) def move_abs(self, position: float, callback=None): if callback is not None: From 3e6919acd817f7193034513f1dfc0b0a05712723 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 18 Nov 2024 23:21:28 -0600 Subject: [PATCH 06/53] import time --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 3df6e96..f14edcd 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -1,6 +1,7 @@ import clr import sys from typing import Dict +import time from System import Decimal from System import Action From 93d898b1a8f7622672cb00361e69c89608d688e2 Mon Sep 17 00:00:00 2001 From: Daichi Kozawa <50872819+nano713@users.noreply.github.com> Date: Tue, 19 Nov 2024 18:54:09 +0900 Subject: [PATCH 07/53] Update kinesis.py Add suggestion of methods. --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index f14edcd..e8a36bb 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -340,9 +340,12 @@ def connect(self, serial: int): self._device.EnableDevice() time.sleep(0.25) + # DK - perhaps you need xxx.GetDeviceInfo() + if not self._device.IsSettingsInitialized(): raise Exception("Device not initialized") + # DK - restore this because the say "Before homing or moving device, ensure the motor's configuration is loaded" # self._device.GetMotorConfiguration(serial) else: raise ValueError('Invalid Serial Number') @@ -356,7 +359,9 @@ def move_abs(self, position: float, callback=None): else: callback = 0 self._device.MoveTo(Decimal(position), callback) - + + # DK - add move_rel if there is an appropriate dll method. + def home(self, callback=None): if callback is not None: callback = Action[UInt64](callback) @@ -364,6 +369,9 @@ def home(self, callback=None): callback = 0 self._device.Home(callback) +# DK - add stop method if there is a dll method. + +# DK - add get_position method if there is a dll method. if __name__ == '__main__': controller = BrushlessDCMotor() @@ -380,4 +388,4 @@ def home(self, callback=None): print(f'Moving: {motor.is_moving}') print(motor.get_target_position()) - controller.close() \ No newline at end of file + controller.close() From 9d86e2870e8baefb22572542d3cfc7e8896f32ee Mon Sep 17 00:00:00 2001 From: Daichi Kozawa <50872819+nano713@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:30:00 +0900 Subject: [PATCH 08/53] Update kinesis.py Add suggestion in initalization. --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index e8a36bb..996f5a4 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -344,9 +344,10 @@ def connect(self, serial: int): if not self._device.IsSettingsInitialized(): raise Exception("Device not initialized") - - # DK - restore this because the say "Before homing or moving device, ensure the motor's configuration is loaded" - # self._device.GetMotorConfiguration(serial) + + # DK - add this. The example says "Before homing or moving device, ensure the motor's configuration is loaded" Edit variable names. + m_config = device.LoadMotorConfiguration(serial_no, + DeviceConfiguration.DeviceSettingsUseOptionType.UseFileSettings) else: raise ValueError('Invalid Serial Number') From 14ec645a1c90969bab8084956efb4b2520493e5c Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 19 Nov 2024 17:55:09 -0600 Subject: [PATCH 09/53] Update stop and initialize methods --- .../hardware/kinesis.py | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index e8a36bb..60fb1c2 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -340,19 +340,16 @@ def connect(self, serial: int): self._device.EnableDevice() time.sleep(0.25) - # DK - perhaps you need xxx.GetDeviceInfo() if not self._device.IsSettingsInitialized(): - raise Exception("Device not initialized") + self._device.WaitForSettingsInitialized(10000) + assert self._device.IsSettingsInitialized() is True + + servo_config = self._device.LoadMotorConfiguration(serial) + servo_config.DeviceSettingsName = "PRMTZ8" #??? + servo_config.UpdateCurrentConfiguration() + self._device.SetSettings(self._device.MotorDeviceSettings, True, False) - # DK - restore this because the say "Before homing or moving device, ensure the motor's configuration is loaded" - # self._device.GetMotorConfiguration(serial) - else: - raise ValueError('Invalid Serial Number') - - # def get_position(self): #Not implemented? - # return Decimal.ToDouble(self._device.RequestPosition()) - def move_abs(self, position: float, callback=None): if callback is not None: callback = Action[UInt64](callback) @@ -360,8 +357,6 @@ def move_abs(self, position: float, callback=None): callback = 0 self._device.MoveTo(Decimal(position), callback) - # DK - add move_rel if there is an appropriate dll method. - def home(self, callback=None): if callback is not None: callback = Action[UInt64](callback) @@ -369,9 +364,9 @@ def home(self, callback=None): callback = 0 self._device.Home(callback) -# DK - add stop method if there is a dll method. + def stop(self): + self._device.Stop(0) -# DK - add get_position method if there is a dll method. if __name__ == '__main__': controller = BrushlessDCMotor() From 257c8345cab022a287a5426a4523450cc9b2f35d Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:29:24 +0900 Subject: [PATCH 10/53] Add suggestion where I tested with KDC101. --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 60fb1c2..a398691 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -346,25 +346,27 @@ def connect(self, serial: int): assert self._device.IsSettingsInitialized() is True servo_config = self._device.LoadMotorConfiguration(serial) - servo_config.DeviceSettingsName = "PRMTZ8" #??? - servo_config.UpdateCurrentConfiguration() - self._device.SetSettings(self._device.MotorDeviceSettings, True, False) + # servo_config.DeviceSettingsName = "PRMTZ8" #??? # DK - delete. we don't use. I guess this is their own setting name. + # servo_config.UpdateCurrentConfiguration() # DK - delete. we don't use + # self._device.SetSettings(self._device.MotorDeviceSettings, True, False) # DK - delete. we don't use - def move_abs(self, position: float, callback=None): + # DK - write your own get_position because kinesis shows raise NotImplementedError + + def move_abs(self, position: float, callback=None): # DK - delete this method because this is exactly same as the method in kinesis class. if callback is not None: callback = Action[UInt64](callback) else: callback = 0 self._device.MoveTo(Decimal(position), callback) - def home(self, callback=None): + def home(self, callback=None): # DK - delete because of the same reason. if callback is not None: callback = Action[UInt64](callback) else: callback = 0 - self._device.Home(callback) + self._device.Home(callback) - def stop(self): + def stop(self): # DK - delete because of the same reason. self._device.Stop(0) From 0fac5ce978fcedbfde37cd8e680b8e3147d2f4a6 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 19 Nov 2024 22:28:09 -0600 Subject: [PATCH 11/53] Add get_position and stop --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 60fb1c2..f75bf68 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -330,6 +330,7 @@ def stop(self): class KDC101(Kinesis): def __init__(self): self._device: KCube.KCubeDCServo = None + self._class = KDC101() def connect(self, serial: int): if serial in serialnumbers_kdc101: self._device = KCube.KCubeDCServo.CreateKCubeDCServo(serial) @@ -340,7 +341,6 @@ def connect(self, serial: int): self._device.EnableDevice() time.sleep(0.25) - if not self._device.IsSettingsInitialized(): self._device.WaitForSettingsInitialized(10000) assert self._device.IsSettingsInitialized() is True @@ -350,6 +350,9 @@ def connect(self, serial: int): servo_config.UpdateCurrentConfiguration() self._device.SetSettings(self._device.MotorDeviceSettings, True, False) + def get_position(self): + return self._class.home() + def move_abs(self, position: float, callback=None): if callback is not None: callback = Action[UInt64](callback) @@ -365,7 +368,7 @@ def home(self, callback=None): self._device.Home(callback) def stop(self): - self._device.Stop(0) + return self._class.stop() if __name__ == '__main__': From b0026aef88e6b7430bda8005227921af8dd178f5 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 19 Nov 2024 22:30:04 -0600 Subject: [PATCH 12/53] Add logger --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 1ab8e84..465c3cb 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -2,6 +2,8 @@ import sys from typing import Dict import time +import logging +logger = logging.getLogger(__name__) from System import Decimal from System import Action @@ -346,9 +348,7 @@ def connect(self, serial: int): assert self._device.IsSettingsInitialized() is True servo_config = self._device.LoadMotorConfiguration(serial) - servo_config.DeviceSettingsName = "PRMTZ8" #??? - servo_config.UpdateCurrentConfiguration() - self._device.SetSettings(self._device.MotorDeviceSettings, True, False) + logger.info(f"Servo Configuration: {servo_config}") def get_position(self): return self._class.home() From a1de23c41800a756a0c777e3f9b24d23f78a541e Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 19 Nov 2024 22:31:32 -0600 Subject: [PATCH 13/53] edit home and stop --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 465c3cb..31296bc 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -360,15 +360,11 @@ def move_abs(self, position: float, callback=None): callback = 0 self._device.MoveTo(Decimal(position), callback) - def home(self, callback=None): # DK - delete because of the same reason. - if callback is not None: - callback = Action[UInt64](callback) - else: - callback = 0 - self._device.Home(callback) + def home(self, callback=None): + self._class.home(callback) def stop(self): - return self._class.stop() + self._class.stop() if __name__ == '__main__': From 1cbe449d81c58e69f005692209becda56bf23ed4 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 19 Nov 2024 23:03:15 -0600 Subject: [PATCH 14/53] Utilize super for inheritance --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 31296bc..bbcf191 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -351,7 +351,7 @@ def connect(self, serial: int): logger.info(f"Servo Configuration: {servo_config}") def get_position(self): - return self._class.home() + return super().get_position() def move_abs(self, position: float, callback=None): if callback is not None: @@ -361,10 +361,10 @@ def move_abs(self, position: float, callback=None): self._device.MoveTo(Decimal(position), callback) def home(self, callback=None): - self._class.home(callback) + super().home(callback) def stop(self): - self._class.stop() + super().stop() if __name__ == '__main__': From ddd1c86ce11b8786385890da2ade219a46a3196f Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 20 Nov 2024 06:36:40 -0600 Subject: [PATCH 15/53] Delete code --- .../hardware/kinesis.py | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index bbcf191..99b0f92 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -329,42 +329,6 @@ def get_position(self) -> float: def stop(self): pass -class KDC101(Kinesis): - def __init__(self): - self._device: KCube.KCubeDCServo = None - self._class = KDC101() - def connect(self, serial: int): - if serial in serialnumbers_kdc101: - self._device = KCube.KCubeDCServo.CreateKCubeDCServo(serial) - self._device.Connect(serial) - time.sleep(0.25) - self._device.StartPolling(250) - time.sleep(0.25) - self._device.EnableDevice() - time.sleep(0.25) - - if not self._device.IsSettingsInitialized(): - self._device.WaitForSettingsInitialized(10000) - assert self._device.IsSettingsInitialized() is True - - servo_config = self._device.LoadMotorConfiguration(serial) - logger.info(f"Servo Configuration: {servo_config}") - - def get_position(self): - return super().get_position() - - def move_abs(self, position: float, callback=None): - if callback is not None: - callback = Action[UInt64](callback) - else: - callback = 0 - self._device.MoveTo(Decimal(position), callback) - - def home(self, callback=None): - super().home(callback) - - def stop(self): - super().stop() if __name__ == '__main__': From cb330d9dde50338c788b044b804e6b4802be0c0b Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 20 Nov 2024 07:18:59 -0600 Subject: [PATCH 16/53] Restore and update logger --- .../hardware/kinesis.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 99b0f92..29feda9 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -329,6 +329,42 @@ def get_position(self) -> float: def stop(self): pass +class KDC101(Kinesis): + def __init__(self): + self._device: KCube.KCubeDCServo = None + + def connect(self, serial: int): + if serial in serialnumbers_kdc101: + self._device = KCube.KCubeDCServo.CreateKCubeDCServo(serial) + self._device.Connect(serial) + time.sleep(0.25) + self._device.StartPolling(250) + time.sleep(0.25) + self._device.EnableDevice() + time.sleep(0.25) + + if not self._device.IsSettingsInitialized(): + self._device.WaitForSettingsInitialized(10000) + assert self._device.IsSettingsInitialized() is True + + servo_config = self._device.LoadMotorConfiguration(serial) + logger.info(f"Servo Configuration: {servo_config}") + + def get_position(self): + return super().get_position() + + def move_abs(self, position: float, callback=None): + if callback is not None: + callback = Action[UInt64](callback) + else: + callback = 0 + self._device.MoveTo(Decimal(position), callback) + + def home(self, callback=None): + super().home(callback) + + def stop(self): + super().stop() if __name__ == '__main__': From 58010852623b1150be4cc56e554995307e293aa5 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 20 Nov 2024 07:24:03 -0600 Subject: [PATCH 17/53] updateget_position --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 29feda9..da15095 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -351,7 +351,7 @@ def connect(self, serial: int): logger.info(f"Servo Configuration: {servo_config}") def get_position(self): - return super().get_position() + return Decimal.ToDouble(self._device.get_DevicePosition()) def move_abs(self, position: float, callback=None): if callback is not None: From 7b0dda50c366b8a07fd430e30980f769c4850899 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 20 Nov 2024 07:34:59 -0600 Subject: [PATCH 18/53] update move_rel --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index da15095..2af745c 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -359,6 +359,9 @@ def move_abs(self, position: float, callback=None): else: callback = 0 self._device.MoveTo(Decimal(position), callback) + + def move_rel(self, position: float, callback=None): + super().move_rel(position, callback) def home(self, callback=None): super().home(callback) From ee5c59c0426ee15955ebde5930cbe0ba9547885e Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 20 Nov 2024 22:30:14 -0600 Subject: [PATCH 19/53] Update and add commands to daq_move --- .../daq_move_plugins/daq_move_KDC101.py | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py new file mode 100644 index 0000000..a2096de --- /dev/null +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -0,0 +1,146 @@ +from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, KDC101 +from typing import Union, List, Dict +from pymodaq.control_modules.move_utility_classes import DAQ_Move_base, comon_parameters_fun, main, DataActuatorType,\ + DataActuator # common set of parameters for all actuators +from pymodaq.utils.daq_utils import ThreadCommand # object used to send info back to the main thread +from pymodaq.utils.parameter import Parameter + + +# TODO: +# (1) change the name of the following class to DAQ_Move_TheNameOfYourChoice +# (2) change the name of this file to daq_move_TheNameOfYourChoice ("TheNameOfYourChoice" should be the SAME +# for the class name and the file name.) +# (3) this file should then be put into the right folder, namely IN THE FOLDER OF THE PLUGIN YOU ARE DEVELOPING: +# pymodaq_plugins_my_plugin/daq_move_plugins +class DAQ_Move_Template(DAQ_Move_base): + """ Instrument plugin class for an actuator. + + This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Move module through inheritance via + DAQ_Move_base. It makes a bridge between the DAQ_Move module and the Python wrapper of a particular instrument. + + TODO Complete the docstring of your plugin with: + * The set of controllers and actuators that should be compatible with this instrument plugin. + * With which instrument and controller it has been tested. + * The version of PyMoDAQ during the test. + * The version of the operating system. + * Installation instructions: what manufacturer’s drivers should be installed to make it run? + + Attributes: + ----------- + controller: object + The particular object that allow the communication with the hardware, in general a python wrapper around the + hardware library. + + # TODO add your particular attributes here if any + + """ + is_multiaxes = True + _axis_names: Union[List[str], Dict[str, int]] = {'1': 1} + _controller_units: Union[str, List[str]] = 'mm' + _epsilon: Union[float, List[float]] = 0.01 + data_actuator_type = DataActuatorType.DataActuator + + params = [ + {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', + 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} + + ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) + + def ini_attributes(self): + self.controller: KDC101 = None + + + def get_actuator_value(self): + """Get the current value from the hardware with scaling conversion. + + Returns + ------- + float: The position obtained after scaling conversion. + """ + + pos = DataActuator(data=self.controller.get_position()) # when writing your own plugin replace this line + pos = self.get_position_with_scaling(pos) + return pos + + def close(self): + """Terminate the communication protocol""" + self.controller.close() + + def commit_settings(self, param: Parameter): + """Apply the consequences of a change of value in the detector settings + + Parameters + ---------- + param: Parameter + A given parameter (within detector_settings) whose value has been changed by the user + """ + if param.name() == 'axis': + self.axis_unit = self.controller.get_units() + else: + pass + + def ini_stage(self, controller=None): + """Actuator communication initialization + + Parameters + ---------- + controller: (object) + custom object of a PyMoDAQ plugin (Slave case). None if only one actuator by controller (Master case) + + Returns + ------- + info: str + initialized: bool + False if initialization failed otherwise True + """ + self.ini_stage_init(slave_controller=controller) # will be useful when controller is slave + + if self.is_master: # is needed when controller is master + self.controller = KDC101() + + info = "KDC101 DCServo initialized" + initialized = True + return info, initialized + + def move_abs(self, value: DataActuator): + """ Move the actuator to the absolute target defined by value + + Parameters + ---------- + value: (float) value of the absolute target positioning + """ + + value = self.check_bound(value) + self.target_value = value + value = self.set_position_with_scaling(value) + self.controller.move_abs(value.value()) + + def move_rel(self, value: DataActuator): + """ Move the actuator to the relative target actuator value defined by value + + Parameters + ---------- + value: (float) value of the relative target positioning + """ + value = self.check_bound(self.current_position + value) - self.current_position + self.target_value = value + self.current_position + value = self.set_position_relative_with_scaling(value) + + + self.controller.move_rel(value.value()) + + def move_home(self): + """Call the reference method of the controller""" + + self.controller.home() + + def stop_motion(self): + """Stop the actuator and emits move_done signal""" + + self.controller.stop() + self.emit_status(ThreadCommand('Update_Status', ['KDC101 DCServo stopped'])) + + +if __name__ == '__main__': + main(__file__) + From f70713387aacc0538e38026bbd86990fa3bdf8be Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Thu, 21 Nov 2024 06:31:45 -0600 Subject: [PATCH 20/53] Delete comments --- .../daq_move_plugins/daq_move_KDC101.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index a2096de..e126b19 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -1,8 +1,8 @@ from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, KDC101 from typing import Union, List, Dict from pymodaq.control_modules.move_utility_classes import DAQ_Move_base, comon_parameters_fun, main, DataActuatorType,\ - DataActuator # common set of parameters for all actuators -from pymodaq.utils.daq_utils import ThreadCommand # object used to send info back to the main thread + DataActuator +from pymodaq.utils.daq_utils import ThreadCommand from pymodaq.utils.parameter import Parameter @@ -12,6 +12,7 @@ # for the class name and the file name.) # (3) this file should then be put into the right folder, namely IN THE FOLDER OF THE PLUGIN YOU ARE DEVELOPING: # pymodaq_plugins_my_plugin/daq_move_plugins + class DAQ_Move_Template(DAQ_Move_base): """ Instrument plugin class for an actuator. @@ -31,7 +32,6 @@ class DAQ_Move_Template(DAQ_Move_base): The particular object that allow the communication with the hardware, in general a python wrapper around the hardware library. - # TODO add your particular attributes here if any """ is_multiaxes = True @@ -58,7 +58,7 @@ def get_actuator_value(self): float: The position obtained after scaling conversion. """ - pos = DataActuator(data=self.controller.get_position()) # when writing your own plugin replace this line + pos = DataActuator(data=self.controller.get_position()) pos = self.get_position_with_scaling(pos) return pos @@ -93,9 +93,9 @@ def ini_stage(self, controller=None): initialized: bool False if initialization failed otherwise True """ - self.ini_stage_init(slave_controller=controller) # will be useful when controller is slave + self.ini_stage_init(slave_controller=controller) - if self.is_master: # is needed when controller is master + if self.is_master: self.controller = KDC101() info = "KDC101 DCServo initialized" From db232f6986f957126144e95a2ad6bfdefa48f01b Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Thu, 21 Nov 2024 07:01:58 -0600 Subject: [PATCH 21/53] update units --- .../daq_move_plugins/daq_move_KDC101.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index e126b19..3dceb4e 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -36,13 +36,14 @@ class DAQ_Move_Template(DAQ_Move_base): """ is_multiaxes = True _axis_names: Union[List[str], Dict[str, int]] = {'1': 1} - _controller_units: Union[str, List[str]] = 'mm' - _epsilon: Union[float, List[float]] = 0.01 + _controller_units: Union[str, List[str]] = KDC101.default_units + _epsilon: Union[float, List[float]] = 0.2e-3 data_actuator_type = DataActuatorType.DataActuator params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', - 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} + 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]}, + {'title': 'Units:', 'name': 'units', 'type': 'string', 'value': _controller_units} ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) From 68dfd2529a59279e1da46bea6743cb71a8edddfe Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Thu, 21 Nov 2024 07:31:21 -0600 Subject: [PATCH 22/53] update callback --- .../daq_move_plugins/daq_move_KDC101.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 3dceb4e..16de475 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -1,18 +1,11 @@ -from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, KDC101 from typing import Union, List, Dict from pymodaq.control_modules.move_utility_classes import DAQ_Move_base, comon_parameters_fun, main, DataActuatorType,\ DataActuator from pymodaq.utils.daq_utils import ThreadCommand from pymodaq.utils.parameter import Parameter +from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, KDC101 -# TODO: -# (1) change the name of the following class to DAQ_Move_TheNameOfYourChoice -# (2) change the name of this file to daq_move_TheNameOfYourChoice ("TheNameOfYourChoice" should be the SAME -# for the class name and the file name.) -# (3) this file should then be put into the right folder, namely IN THE FOLDER OF THE PLUGIN YOU ARE DEVELOPING: -# pymodaq_plugins_my_plugin/daq_move_plugins - class DAQ_Move_Template(DAQ_Move_base): """ Instrument plugin class for an actuator. @@ -75,7 +68,7 @@ def commit_settings(self, param: Parameter): param: Parameter A given parameter (within detector_settings) whose value has been changed by the user """ - if param.name() == 'axis': + if param.name() == 'units': self.axis_unit = self.controller.get_units() else: pass @@ -98,6 +91,7 @@ def ini_stage(self, controller=None): if self.is_master: self.controller = KDC101() + self.controller.connect(self.settings['serial_number']) info = "KDC101 DCServo initialized" initialized = True @@ -114,7 +108,7 @@ def move_abs(self, value: DataActuator): value = self.check_bound(value) self.target_value = value value = self.set_position_with_scaling(value) - self.controller.move_abs(value.value()) + self.controller.move_abs(value.value(), 60000) def move_rel(self, value: DataActuator): """ Move the actuator to the relative target actuator value defined by value @@ -128,12 +122,12 @@ def move_rel(self, value: DataActuator): value = self.set_position_relative_with_scaling(value) - self.controller.move_rel(value.value()) + self.controller.move_rel(value.value(), 60000) #TODO: CHECK IF MOVE_REL IS IMPLEMENTED IN KDC101 def move_home(self): """Call the reference method of the controller""" - self.controller.home() + self.controller.home(60000) def stop_motion(self): """Stop the actuator and emits move_done signal""" From 35bb5ea176ca2f0408e1688e700210adb9214bb7 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Thu, 21 Nov 2024 07:44:02 -0600 Subject: [PATCH 23/53] test multiaxis = false --- .../daq_move_plugins/daq_move_KDC101.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 16de475..c03e2bf 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -25,9 +25,8 @@ class DAQ_Move_Template(DAQ_Move_base): The particular object that allow the communication with the hardware, in general a python wrapper around the hardware library. - """ - is_multiaxes = True + is_multiaxes = False #TODO: TEST WITHOUT MULTIAXIS _axis_names: Union[List[str], Dict[str, int]] = {'1': 1} _controller_units: Union[str, List[str]] = KDC101.default_units _epsilon: Union[float, List[float]] = 0.2e-3 From 86d046a682bb082732a7928b31e2dc5fe247410a Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 3 Dec 2024 21:05:34 -0700 Subject: [PATCH 24/53] Remove units in params --- .../daq_move_plugins/daq_move_KDC101.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index c03e2bf..bbc6682 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -6,7 +6,7 @@ from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, KDC101 -class DAQ_Move_Template(DAQ_Move_base): +class DAQ_Move_KDC101(DAQ_Move_base): """ Instrument plugin class for an actuator. This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Move module through inheritance via @@ -34,8 +34,8 @@ class DAQ_Move_Template(DAQ_Move_base): params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', - 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]}, - {'title': 'Units:', 'name': 'units', 'type': 'string', 'value': _controller_units} + 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} + # {'title': 'Units:', 'name': 'units', 'type': 'string', 'value': _controller_units} ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) From cb083db307f1d07f1cf5a7e3b780ad025e54507c Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 3 Dec 2024 21:48:41 -0700 Subject: [PATCH 25/53] Update default_units --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 2af745c..9cd2603 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -330,6 +330,7 @@ def stop(self): pass class KDC101(Kinesis): + default_units = 'mm' def __init__(self): self._device: KCube.KCubeDCServo = None From b1077b83895ce2861b1d1f74aedf48067afebb61 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 3 Dec 2024 21:59:05 -0700 Subject: [PATCH 26/53] Added set_unitd and reset default_units --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 9cd2603..f584645 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -330,7 +330,7 @@ def stop(self): pass class KDC101(Kinesis): - default_units = 'mm' + default_units = '' def __init__(self): self._device: KCube.KCubeDCServo = None @@ -370,6 +370,9 @@ def home(self, callback=None): def stop(self): super().stop() + def set_units(self, units: str): + self._device.get_UnitConverter().SetUnits(units) + if __name__ == '__main__': controller = BrushlessDCMotor() From 0e2efdb3717560ca8a5b0309c4f8afed940a1d25 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 4 Dec 2024 12:16:24 -0700 Subject: [PATCH 27/53] Update hardware --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index f584645..114e7d2 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -355,20 +355,16 @@ def get_position(self): return Decimal.ToDouble(self._device.get_DevicePosition()) def move_abs(self, position: float, callback=None): - if callback is not None: - callback = Action[UInt64](callback) - else: - callback = 0 self._device.MoveTo(Decimal(position), callback) def move_rel(self, position: float, callback=None): - super().move_rel(position, callback) + self._device.MoveRelative(KCube.KCubeDCServo.MoveDirection.Forward, Decimal(position), callback) def home(self, callback=None): - super().home(callback) + self._device.Home(callback) def stop(self): - super().stop() + self._device.Stop(0) def set_units(self, units: str): self._device.get_UnitConverter().SetUnits(units) From 3d9dfd908bcd0c0e79d89daf49abc92a52b751f4 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 4 Dec 2024 12:20:55 -0700 Subject: [PATCH 28/53] Update units method --- .../daq_move_plugins/daq_move_KDC101.py | 4 ++-- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index bbc6682..8cc1a6d 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -26,7 +26,7 @@ class DAQ_Move_KDC101(DAQ_Move_base): hardware library. """ - is_multiaxes = False #TODO: TEST WITHOUT MULTIAXIS + is_multiaxes = False _axis_names: Union[List[str], Dict[str, int]] = {'1': 1} _controller_units: Union[str, List[str]] = KDC101.default_units _epsilon: Union[float, List[float]] = 0.2e-3 @@ -35,7 +35,7 @@ class DAQ_Move_KDC101(DAQ_Move_base): params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} - # {'title': 'Units:', 'name': 'units', 'type': 'string', 'value': _controller_units} + {'title': 'Units:', 'name': 'units', 'type': 'string', 'value': _controller_units} ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 114e7d2..24b92e8 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -367,7 +367,11 @@ def stop(self): self._device.Stop(0) def set_units(self, units: str): - self._device.get_UnitConverter().SetUnits(units) + """ Set the stage units from the controller""" + self.default_units = self._device.get_UnitConverter().SetUnits(units) + def get_units(self): + """ Get the stage units from the controller""" + return self.default_units if __name__ == '__main__': From 514bb6f86e2e6bd6da2ae29107588225c18ed0b7 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 4 Dec 2024 12:26:18 -0700 Subject: [PATCH 29/53] Update set_units --- src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 8cc1a6d..63c4170 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -69,6 +69,7 @@ def commit_settings(self, param: Parameter): """ if param.name() == 'units': self.axis_unit = self.controller.get_units() + self.settings.child(('units')).setValue(self.axis_unit) else: pass From b726153d851b3b0f29e2e97b09f3c783c3bdc2d7 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 4 Dec 2024 12:26:27 -0700 Subject: [PATCH 30/53] Update set_units correctly --- .../daq_move_plugins/daq_move_KDC101.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 63c4170..be66dd1 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -68,8 +68,7 @@ def commit_settings(self, param: Parameter): A given parameter (within detector_settings) whose value has been changed by the user """ if param.name() == 'units': - self.axis_unit = self.controller.get_units() - self.settings.child(('units')).setValue(self.axis_unit) + self.controller.set_units(self.settings.child(('units')).value()) else: pass From fddeb181cfaf1d16b2883de050556258bc3e5571 Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Thu, 5 Dec 2024 11:43:10 +0900 Subject: [PATCH 31/53] Add suggestion --- .../daq_move_plugins/daq_move_KDC101.py | 8 ++++---- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index be66dd1..2ca17d8 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -34,8 +34,8 @@ class DAQ_Move_KDC101(DAQ_Move_base): params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', - 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} - {'title': 'Units:', 'name': 'units', 'type': 'string', 'value': _controller_units} + 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} # DK - add comma at the end + # {'title': 'Units:', 'name': 'units', 'type': 'string', 'value': _controller_units} # DK - correct type. This causes an error in initialization ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) @@ -68,7 +68,7 @@ def commit_settings(self, param: Parameter): A given parameter (within detector_settings) whose value has been changed by the user """ if param.name() == 'units': - self.controller.set_units(self.settings.child(('units')).value()) + self.controller.set_units(self.settings.child(('units')).value()) # DK - Is neting tuple (('units')) correct? else: pass @@ -126,7 +126,7 @@ def move_rel(self, value: DataActuator): def move_home(self): """Call the reference method of the controller""" - self.controller.home(60000) + self.controller.home(60000) # DK - Revise. This causes an error in initialization def stop_motion(self): """Stop the actuator and emits move_done signal""" diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 24b92e8..40ff1fb 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -330,7 +330,7 @@ def stop(self): pass class KDC101(Kinesis): - default_units = '' + default_units = 'mm' def __init__(self): self._device: KCube.KCubeDCServo = None From 9a3ce46a63f46708952e0dd57315cde312d800b1 Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Thu, 5 Dec 2024 11:47:53 +0900 Subject: [PATCH 32/53] Edit comments --- .../daq_move_plugins/daq_move_KDC101.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 2ca17d8..0715639 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -68,7 +68,7 @@ def commit_settings(self, param: Parameter): A given parameter (within detector_settings) whose value has been changed by the user """ if param.name() == 'units': - self.controller.set_units(self.settings.child(('units')).value()) # DK - Is neting tuple (('units')) correct? + self.controller.set_units(self.settings.child(('units')).value()) # DK - Is nesting tuple (('units')) correct? else: pass @@ -126,7 +126,7 @@ def move_rel(self, value: DataActuator): def move_home(self): """Call the reference method of the controller""" - self.controller.home(60000) # DK - Revise. This causes an error in initialization + self.controller.home(60000) def stop_motion(self): """Stop the actuator and emits move_done signal""" From 8b73ea774ce9acdebdbd5f0796b6d93b9bd9440a Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 4 Dec 2024 21:33:17 -0700 Subject: [PATCH 33/53] Update params --- .../daq_move_plugins/daq_move_KDC101.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index be66dd1..e0c56da 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -35,7 +35,8 @@ class DAQ_Move_KDC101(DAQ_Move_base): params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} - {'title': 'Units:', 'name': 'units', 'type': 'string', 'value': _controller_units} + {'title': 'Units:', 'name': 'units', 'type': 'list', "limits": ["mm", "um", "m", "nm"], + "value": 'mm'} ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) From 674f74b77ef4d842dcd8807c79b566109a9aa941 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 4 Dec 2024 21:33:58 -0700 Subject: [PATCH 34/53] delete comments --- .../daq_move_plugins/daq_move_KDC101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index e0c56da..9963038 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -122,7 +122,7 @@ def move_rel(self, value: DataActuator): value = self.set_position_relative_with_scaling(value) - self.controller.move_rel(value.value(), 60000) #TODO: CHECK IF MOVE_REL IS IMPLEMENTED IN KDC101 + self.controller.move_rel(value.value(), 60000) def move_home(self): """Call the reference method of the controller""" From 22d96ec794bf5de78ff3e3f8b0c93689a73b333b Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Thu, 5 Dec 2024 22:27:44 +0900 Subject: [PATCH 35/53] Add suggestion in commit_settings, methods around units --- .../daq_move_plugins/daq_move_KDC101.py | 10 ++++++---- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 0715639..ad270df 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -34,8 +34,8 @@ class DAQ_Move_KDC101(DAQ_Move_base): params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', - 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} # DK - add comma at the end - # {'title': 'Units:', 'name': 'units', 'type': 'string', 'value': _controller_units} # DK - correct type. This causes an error in initialization + 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]}, # DK - add comma at the end + # {'title': 'Units:', 'name': 'units', 'type': 'list', "limits": ["mm", "um", "m", "nm"], "value": 'mm'} ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) @@ -68,7 +68,8 @@ def commit_settings(self, param: Parameter): A given parameter (within detector_settings) whose value has been changed by the user """ if param.name() == 'units': - self.controller.set_units(self.settings.child(('units')).value()) # DK - Is nesting tuple (('units')) correct? + self.controller.set_units(self.settings.child('units').value()) # DK - Is nesting tuple (('units')) correct? + # DK - if you update the units, also update _controller_units = xxx else: pass @@ -86,7 +87,8 @@ def ini_stage(self, controller=None): initialized: bool False if initialization failed otherwise True """ - self.ini_stage_init(slave_controller=controller) + + self.ini_stage_init(slave_controller=controller) if self.is_master: self.controller = KDC101() diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 40ff1fb..a1892fd 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -368,10 +368,10 @@ def stop(self): def set_units(self, units: str): """ Set the stage units from the controller""" - self.default_units = self._device.get_UnitConverter().SetUnits(units) + self.default_units = self._device.get_UnitConverter().SetUnits(units) # DK - correct or delete set_units method def get_units(self): """ Get the stage units from the controller""" - return self.default_units + return self.default_units # DK - inherit or follow the way Kinesit class does if __name__ == '__main__': From 7985ad8d7348b1952f878d94700a89475beabd87 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Thu, 5 Dec 2024 23:07:23 -0600 Subject: [PATCH 36/53] delete kdc_move --- .../daq_move_plugins/daq_move_KDC101.py | 141 ------------------ 1 file changed, 141 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 9963038..e69de29 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -1,141 +0,0 @@ -from typing import Union, List, Dict -from pymodaq.control_modules.move_utility_classes import DAQ_Move_base, comon_parameters_fun, main, DataActuatorType,\ - DataActuator -from pymodaq.utils.daq_utils import ThreadCommand -from pymodaq.utils.parameter import Parameter -from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, KDC101 - - -class DAQ_Move_KDC101(DAQ_Move_base): - """ Instrument plugin class for an actuator. - - This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Move module through inheritance via - DAQ_Move_base. It makes a bridge between the DAQ_Move module and the Python wrapper of a particular instrument. - - TODO Complete the docstring of your plugin with: - * The set of controllers and actuators that should be compatible with this instrument plugin. - * With which instrument and controller it has been tested. - * The version of PyMoDAQ during the test. - * The version of the operating system. - * Installation instructions: what manufacturer’s drivers should be installed to make it run? - - Attributes: - ----------- - controller: object - The particular object that allow the communication with the hardware, in general a python wrapper around the - hardware library. - - """ - is_multiaxes = False - _axis_names: Union[List[str], Dict[str, int]] = {'1': 1} - _controller_units: Union[str, List[str]] = KDC101.default_units - _epsilon: Union[float, List[float]] = 0.2e-3 - data_actuator_type = DataActuatorType.DataActuator - - params = [ - {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', - 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} - {'title': 'Units:', 'name': 'units', 'type': 'list', "limits": ["mm", "um", "m", "nm"], - "value": 'mm'} - - ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) - - def ini_attributes(self): - self.controller: KDC101 = None - - - def get_actuator_value(self): - """Get the current value from the hardware with scaling conversion. - - Returns - ------- - float: The position obtained after scaling conversion. - """ - - pos = DataActuator(data=self.controller.get_position()) - pos = self.get_position_with_scaling(pos) - return pos - - def close(self): - """Terminate the communication protocol""" - self.controller.close() - - def commit_settings(self, param: Parameter): - """Apply the consequences of a change of value in the detector settings - - Parameters - ---------- - param: Parameter - A given parameter (within detector_settings) whose value has been changed by the user - """ - if param.name() == 'units': - self.controller.set_units(self.settings.child(('units')).value()) - else: - pass - - def ini_stage(self, controller=None): - """Actuator communication initialization - - Parameters - ---------- - controller: (object) - custom object of a PyMoDAQ plugin (Slave case). None if only one actuator by controller (Master case) - - Returns - ------- - info: str - initialized: bool - False if initialization failed otherwise True - """ - self.ini_stage_init(slave_controller=controller) - - if self.is_master: - self.controller = KDC101() - self.controller.connect(self.settings['serial_number']) - - info = "KDC101 DCServo initialized" - initialized = True - return info, initialized - - def move_abs(self, value: DataActuator): - """ Move the actuator to the absolute target defined by value - - Parameters - ---------- - value: (float) value of the absolute target positioning - """ - - value = self.check_bound(value) - self.target_value = value - value = self.set_position_with_scaling(value) - self.controller.move_abs(value.value(), 60000) - - def move_rel(self, value: DataActuator): - """ Move the actuator to the relative target actuator value defined by value - - Parameters - ---------- - value: (float) value of the relative target positioning - """ - value = self.check_bound(self.current_position + value) - self.current_position - self.target_value = value + self.current_position - value = self.set_position_relative_with_scaling(value) - - - self.controller.move_rel(value.value(), 60000) - - def move_home(self): - """Call the reference method of the controller""" - - self.controller.home(60000) - - def stop_motion(self): - """Stop the actuator and emits move_done signal""" - - self.controller.stop() - self.emit_status(ThreadCommand('Update_Status', ['KDC101 DCServo stopped'])) - - -if __name__ == '__main__': - main(__file__) - From 18549b2e232871f7ac30b29aaef2da0538bda031 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Thu, 5 Dec 2024 23:08:21 -0600 Subject: [PATCH 37/53] delete kdc hardware --- .../hardware/kinesis.py | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 24b92e8..b0cee03 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -329,49 +329,7 @@ def get_position(self) -> float: def stop(self): pass -class KDC101(Kinesis): - default_units = '' - def __init__(self): - self._device: KCube.KCubeDCServo = None - - def connect(self, serial: int): - if serial in serialnumbers_kdc101: - self._device = KCube.KCubeDCServo.CreateKCubeDCServo(serial) - self._device.Connect(serial) - time.sleep(0.25) - self._device.StartPolling(250) - time.sleep(0.25) - self._device.EnableDevice() - time.sleep(0.25) - - if not self._device.IsSettingsInitialized(): - self._device.WaitForSettingsInitialized(10000) - assert self._device.IsSettingsInitialized() is True - - servo_config = self._device.LoadMotorConfiguration(serial) - logger.info(f"Servo Configuration: {servo_config}") - - def get_position(self): - return Decimal.ToDouble(self._device.get_DevicePosition()) - - def move_abs(self, position: float, callback=None): - self._device.MoveTo(Decimal(position), callback) - - def move_rel(self, position: float, callback=None): - self._device.MoveRelative(KCube.KCubeDCServo.MoveDirection.Forward, Decimal(position), callback) - - def home(self, callback=None): - self._device.Home(callback) - - def stop(self): - self._device.Stop(0) - def set_units(self, units: str): - """ Set the stage units from the controller""" - self.default_units = self._device.get_UnitConverter().SetUnits(units) - def get_units(self): - """ Get the stage units from the controller""" - return self.default_units if __name__ == '__main__': From 2a721e0752e4435619c7c5d25906829020f90a9c Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Fri, 6 Dec 2024 23:02:25 +0900 Subject: [PATCH 38/53] Delete unused lines --- .../daq_move_plugins/daq_move_KDC101.py | 10 ++-------- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 8 -------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index ad270df..46ef383 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -34,9 +34,7 @@ class DAQ_Move_KDC101(DAQ_Move_base): params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', - 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]}, # DK - add comma at the end - # {'title': 'Units:', 'name': 'units', 'type': 'list', "limits": ["mm", "um", "m", "nm"], "value": 'mm'} - + 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]}, ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) def ini_attributes(self): @@ -67,11 +65,7 @@ def commit_settings(self, param: Parameter): param: Parameter A given parameter (within detector_settings) whose value has been changed by the user """ - if param.name() == 'units': - self.controller.set_units(self.settings.child('units').value()) # DK - Is nesting tuple (('units')) correct? - # DK - if you update the units, also update _controller_units = xxx - else: - pass + pass def ini_stage(self, controller=None): """Actuator communication initialization diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index a1892fd..bbc1315 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -366,14 +366,6 @@ def home(self, callback=None): def stop(self): self._device.Stop(0) - def set_units(self, units: str): - """ Set the stage units from the controller""" - self.default_units = self._device.get_UnitConverter().SetUnits(units) # DK - correct or delete set_units method - def get_units(self): - """ Get the stage units from the controller""" - return self.default_units # DK - inherit or follow the way Kinesit class does - - if __name__ == '__main__': controller = BrushlessDCMotor() controller.connect(serialnumbers_brushless[0]) From 2b1578acb4ba16acb46ca0349d2611b9ac049fb0 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Fri, 6 Dec 2024 21:49:09 -0600 Subject: [PATCH 39/53] Restore daq_move --- .../daq_move_plugins/daq_move_KDC101.py | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index e69de29..01413c5 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -0,0 +1,140 @@ +from typing import Union, List, Dict +from pymodaq.control_modules.move_utility_classes import DAQ_Move_base, comon_parameters_fun, main, DataActuatorType,\ + DataActuator +from pymodaq.utils.daq_utils import ThreadCommand +from pymodaq.utils.parameter import Parameter +from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, KDC101 + + +class DAQ_Move_KDC101(DAQ_Move_base): + """ Instrument plugin class for an actuator. + + This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Move module through inheritance via + DAQ_Move_base. It makes a bridge between the DAQ_Move module and the Python wrapper of a particular instrument. + + TODO Complete the docstring of your plugin with: + * The set of controllers and actuators that should be compatible with this instrument plugin. + * With which instrument and controller it has been tested. + * The version of PyMoDAQ during the test. + * The version of the operating system. + * Installation instructions: what manufacturer’s drivers should be installed to make it run? + + Attributes: + ----------- + controller: object + The particular object that allow the communication with the hardware, in general a python wrapper around the + hardware library. + + """ + is_multiaxes = False + _axis_names: Union[List[str], Dict[str, int]] = {'1': 1} + _controller_units: Union[str, List[str]] = KDC101.default_units + _epsilon: Union[float, List[float]] = 0.2e-3 + data_actuator_type = DataActuatorType.DataActuator + + params = [ + {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', + 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} + {'title': 'Units:', 'name': 'units', 'type': 'list', "limits": ["mm", "um", "m", "nm"], + "value": 'mm'} + + ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) + + def ini_attributes(self): + self.controller: KDC101 = None + + + def get_actuator_value(self): + """Get the current value from the hardware with scaling conversion. + + Returns + ------- + float: The position obtained after scaling conversion. + """ + + pos = DataActuator(data=self.controller.get_position()) + pos = self.get_position_with_scaling(pos) + return pos + + def close(self): + """Terminate the communication protocol""" + self.controller.close() + + def commit_settings(self, param: Parameter): + """Apply the consequences of a change of value in the detector settings + + Parameters + ---------- + param: Parameter + A given parameter (within detector_settings) whose value has been changed by the user + """ + if param.name() == 'units': + self.controller.set_units(self.settings.child(('units')).value()) + else: + pass + + def ini_stage(self, controller=None): + """Actuator communication initialization + + Parameters + ---------- + controller: (object) + custom object of a PyMoDAQ plugin (Slave case). None if only one actuator by controller (Master case) + + Returns + ------- + info: str + initialized: bool + False if initialization failed otherwise True + """ + self.ini_stage_init(slave_controller=controller) + + if self.is_master: + self.controller = KDC101() + self.controller.connect(self.settings['serial_number']) + + info = "KDC101 DCServo initialized" + initialized = True + return info, initialized + + def move_abs(self, value: DataActuator): + """ Move the actuator to the absolute target defined by value + + Parameters + ---------- + value: (float) value of the absolute target positioning + """ + + value = self.check_bound(value) + self.target_value = value + value = self.set_position_with_scaling(value) + self.controller.move_abs(value.value(), 60000) + + def move_rel(self, value: DataActuator): + """ Move the actuator to the relative target actuator value defined by value + + Parameters + ---------- + value: (float) value of the relative target positioning + """ + value = self.check_bound(self.current_position + value) - self.current_position + self.target_value = value + self.current_position + value = self.set_position_relative_with_scaling(value) + + + self.controller.move_rel(value.value(), 60000) + + def move_home(self): + """Call the reference method of the controller""" + + self.controller.home(60000) + + def stop_motion(self): + """Stop the actuator and emits move_done signal""" + + self.controller.stop() + self.emit_status(ThreadCommand('Update_Status', ['KDC101 DCServo stopped'])) + + +if __name__ == '__main__': + main(__file__) From 672337f6a2a377dc97adc309c84014c92d7d1850 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Fri, 6 Dec 2024 21:50:01 -0600 Subject: [PATCH 40/53] Restore kinesis --- .../hardware/kinesis.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index b0cee03..24b92e8 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -329,7 +329,49 @@ def get_position(self) -> float: def stop(self): pass +class KDC101(Kinesis): + default_units = '' + def __init__(self): + self._device: KCube.KCubeDCServo = None + + def connect(self, serial: int): + if serial in serialnumbers_kdc101: + self._device = KCube.KCubeDCServo.CreateKCubeDCServo(serial) + self._device.Connect(serial) + time.sleep(0.25) + self._device.StartPolling(250) + time.sleep(0.25) + self._device.EnableDevice() + time.sleep(0.25) + + if not self._device.IsSettingsInitialized(): + self._device.WaitForSettingsInitialized(10000) + assert self._device.IsSettingsInitialized() is True + + servo_config = self._device.LoadMotorConfiguration(serial) + logger.info(f"Servo Configuration: {servo_config}") + + def get_position(self): + return Decimal.ToDouble(self._device.get_DevicePosition()) + + def move_abs(self, position: float, callback=None): + self._device.MoveTo(Decimal(position), callback) + + def move_rel(self, position: float, callback=None): + self._device.MoveRelative(KCube.KCubeDCServo.MoveDirection.Forward, Decimal(position), callback) + + def home(self, callback=None): + self._device.Home(callback) + + def stop(self): + self._device.Stop(0) + def set_units(self, units: str): + """ Set the stage units from the controller""" + self.default_units = self._device.get_UnitConverter().SetUnits(units) + def get_units(self): + """ Get the stage units from the controller""" + return self.default_units if __name__ == '__main__': From a7cb24ca3a876d0f6a1a4391d65de2199915da69 Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:45:54 +0900 Subject: [PATCH 41/53] update params --- .../daq_move_plugins/daq_move_KDC101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 01413c5..7b90564 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -34,7 +34,7 @@ class DAQ_Move_KDC101(DAQ_Move_base): params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', - 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]} + 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]}, {'title': 'Units:', 'name': 'units', 'type': 'list', "limits": ["mm", "um", "m", "nm"], "value": 'mm'} From c7a0ac9e6714e14c55f3962b89db07f182b12392 Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Thu, 12 Dec 2024 22:09:03 +0900 Subject: [PATCH 42/53] Update params --- .../daq_move_plugins/daq_move_KDC101.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 7b90564..628378c 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -35,9 +35,6 @@ class DAQ_Move_KDC101(DAQ_Move_base): params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]}, - {'title': 'Units:', 'name': 'units', 'type': 'list', "limits": ["mm", "um", "m", "nm"], - "value": 'mm'} - ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) def ini_attributes(self): From 840f0565cea5bae18acd2b19c802c77f672fd6f1 Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:34:05 +0900 Subject: [PATCH 43/53] Add suggestion in move_rel error. --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index bbc1315..e189269 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -358,7 +358,7 @@ def move_abs(self, position: float, callback=None): self._device.MoveTo(Decimal(position), callback) def move_rel(self, position: float, callback=None): - self._device.MoveRelative(KCube.KCubeDCServo.MoveDirection.Forward, Decimal(position), callback) + self._device.MoveRelative(KCube.KCubeDCServo.MoveDirection.Forward, Decimal(position), callback) # DK - KCube.KCubeDCServo.MoveDirection.Forward should be corrected def home(self, callback=None): self._device.Home(callback) From c782772a7f69e807c7517202073cee55f6bf90e2 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 16 Dec 2024 21:54:05 -0600 Subject: [PATCH 44/53] Update move_rel --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index e189269..b578278 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -358,7 +358,7 @@ def move_abs(self, position: float, callback=None): self._device.MoveTo(Decimal(position), callback) def move_rel(self, position: float, callback=None): - self._device.MoveRelative(KCube.KCubeDCServo.MoveDirection.Forward, Decimal(position), callback) # DK - KCube.KCubeDCServo.MoveDirection.Forward should be corrected + self._device.MoveRelative(Generic.MoveDirection.Forward, Decimal(position), callback) # DK - KCube.KCubeDCServo.MoveDirection.Forward should be corrected def home(self, callback=None): self._device.Home(callback) From 545d73637c790135640d116a6764e26205c81a82 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 16 Dec 2024 21:56:03 -0600 Subject: [PATCH 45/53] Update README --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 5873809..5f7803a 100644 --- a/README.rst +++ b/README.rst @@ -39,6 +39,7 @@ Actuators * **PRM1Z8_pylablib**: DC servo motorized 360° rotation mount (Thorlabs PRM1Z8) using the pylablib control module. The Thorlabs APT software should be installed: https://www.thorlabs.com/newgrouppage9.cfm?objectgroup_id=9019. * **BrushlessDCMotor**: Kinesis control of DC Brushless Motor (tested with the BBD201 controller) * **Kinesis_KPZ101**: Piezo Electric Stage Kinesis series (KPZ101) +* **Kinesis_KDC101**: DC Servo Motor Kinesis series (KDC101) Viewer0D From 419e305e59e8c1b2e819e87a68ea8ad07392c368 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 16 Dec 2024 22:43:02 -0600 Subject: [PATCH 46/53] Delete comment --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index b578278..06f6b4e 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -358,7 +358,7 @@ def move_abs(self, position: float, callback=None): self._device.MoveTo(Decimal(position), callback) def move_rel(self, position: float, callback=None): - self._device.MoveRelative(Generic.MoveDirection.Forward, Decimal(position), callback) # DK - KCube.KCubeDCServo.MoveDirection.Forward should be corrected + self._device.MoveRelative(Generic.MoveDirection.Forward, Decimal(position), callback) def home(self, callback=None): self._device.Home(callback) From 9cfea1d4d8680607e0d6f55b5c6c4d7b8f28179a Mon Sep 17 00:00:00 2001 From: nano713 <50872819+nano713@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:43:13 +0900 Subject: [PATCH 47/53] Update move_rel --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 06f6b4e..5488865 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -358,7 +358,7 @@ def move_abs(self, position: float, callback=None): self._device.MoveTo(Decimal(position), callback) def move_rel(self, position: float, callback=None): - self._device.MoveRelative(Generic.MoveDirection.Forward, Decimal(position), callback) + self._device.MoveRelative(Generic.MotorDirection.Forward, Decimal(position), callback) def home(self, callback=None): self._device.Home(callback) From 3bb45a592f0d1d5f60fb5d140978375fa65b51f7 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 16 Dec 2024 22:58:34 -0600 Subject: [PATCH 48/53] Update class name --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 06f6b4e..e688927 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -329,7 +329,7 @@ def get_position(self) -> float: def stop(self): pass -class KDC101(Kinesis): +class DCservo(Kinesis): default_units = 'mm' def __init__(self): self._device: KCube.KCubeDCServo = None From ffe6e82ed6f52255b3224fd32bbc57f737a20fb0 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 16 Dec 2024 23:01:47 -0600 Subject: [PATCH 49/53] Update daq_move import --- .../daq_move_plugins/daq_move_KDC101.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 628378c..f853ebe 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -3,7 +3,7 @@ DataActuator from pymodaq.utils.daq_utils import ThreadCommand from pymodaq.utils.parameter import Parameter -from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, KDC101 +from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, DCservo as KDC101 class DAQ_Move_KDC101(DAQ_Move_base): From 897eb46d2b815f54a742c278d9a38e991e8e0185 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 16 Dec 2024 23:04:19 -0600 Subject: [PATCH 50/53] Update serial numbers --- .../daq_move_plugins/daq_move_KDC101.py | 4 ++-- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index f853ebe..7282f90 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -3,7 +3,7 @@ DataActuator from pymodaq.utils.daq_utils import ThreadCommand from pymodaq.utils.parameter import Parameter -from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_kdc101, DCservo as KDC101 +from pymodaq_plugins_thorlabs.hardware.kinesis import serialnumbers_dcServo, DCservo as KDC101 class DAQ_Move_KDC101(DAQ_Move_base): @@ -34,7 +34,7 @@ class DAQ_Move_KDC101(DAQ_Move_base): params = [ {'title': 'Serial Number:', 'name': 'serial_number', 'type': 'list', - 'limits': serialnumbers_kdc101, 'value': serialnumbers_kdc101[0]}, + 'limits': serialnumbers_dcServo, 'value': serialnumbers_dcServo[0]}, ] + comon_parameters_fun(is_multiaxes, axes_names=_axis_names, epsilon=_epsilon) def ini_attributes(self): diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index e688927..5b7d907 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -40,7 +40,7 @@ serialnumbers_brushless = [str(ser) for ser in Device.DeviceManagerCLI.GetDeviceList(BrushlessMotorCLI.BenchtopBrushlessMotor.DevicePrefix)] serialnumbers_piezo = [str(ser) for ser in Device.DeviceManagerCLI.GetDeviceList(KCubePiezo.KCubePiezo.DevicePrefix)] -serialnumbers_kdc101 = [str(ser) for ser in Device.DeviceManagerCLI.GetDeviceList(KCube.KCubeDCServo.DevicePrefix)] +serialnumbers_dcServo = [str(ser) for ser in Device.DeviceManagerCLI.GetDeviceList(KCube.KCubeDCServo.DevicePrefix)] class Kinesis: From 253c9d20b8b725641a2382aca7b2d778d22624d3 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 16 Dec 2024 23:04:29 -0600 Subject: [PATCH 51/53] Update serialnumbers --- src/pymodaq_plugins_thorlabs/hardware/kinesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py index 5b7d907..b6bca60 100644 --- a/src/pymodaq_plugins_thorlabs/hardware/kinesis.py +++ b/src/pymodaq_plugins_thorlabs/hardware/kinesis.py @@ -335,7 +335,7 @@ def __init__(self): self._device: KCube.KCubeDCServo = None def connect(self, serial: int): - if serial in serialnumbers_kdc101: + if serial in serialnumbers_dcServo: self._device = KCube.KCubeDCServo.CreateKCubeDCServo(serial) self._device.Connect(serial) time.sleep(0.25) From c6a1c8977e7f92c1d0cc4fc8d8d23d910db9f1fc Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 17 Dec 2024 21:57:55 -0600 Subject: [PATCH 52/53] Add author --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 5f7803a..4a3a5e1 100644 --- a/README.rst +++ b/README.rst @@ -24,6 +24,7 @@ Authors * David Bresteau (david.bresteau@cea.fr) * Nicolas Tappy (nicolas.tappy@epfl.ch) * Romain Geneaux (romain.geneaux@cea.fr) +* Amelie Deshazer Instruments =========== From 89d74b35b3a4463b39ffe7251bcf3776a232b7a6 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 13 Jan 2025 19:59:49 -0600 Subject: [PATCH 53/53] Delete comments --- .../daq_move_plugins/daq_move_KDC101.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py index 7282f90..ceea14d 100644 --- a/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py +++ b/src/pymodaq_plugins_thorlabs/daq_move_plugins/daq_move_KDC101.py @@ -12,13 +12,6 @@ class DAQ_Move_KDC101(DAQ_Move_base): This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Move module through inheritance via DAQ_Move_base. It makes a bridge between the DAQ_Move module and the Python wrapper of a particular instrument. - TODO Complete the docstring of your plugin with: - * The set of controllers and actuators that should be compatible with this instrument plugin. - * With which instrument and controller it has been tested. - * The version of PyMoDAQ during the test. - * The version of the operating system. - * Installation instructions: what manufacturer’s drivers should be installed to make it run? - Attributes: ----------- controller: object