From 4894689d27f3117a906f368ddf73b6da1f7851b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Weber?= Date: Wed, 8 Nov 2023 14:04:12 +0100 Subject: [PATCH] updated the move example from right template --- .../daq_move_Monochromator.py | 100 +++++++----- .../daq_move_Monochromator2.py | 144 ------------------ 2 files changed, 62 insertions(+), 182 deletions(-) delete mode 100644 src/pymodaq_plugins_teaching/daq_move_plugins/daq_move_Monochromator2.py diff --git a/src/pymodaq_plugins_teaching/daq_move_plugins/daq_move_Monochromator.py b/src/pymodaq_plugins_teaching/daq_move_plugins/daq_move_Monochromator.py index b63377c..a2b26bc 100644 --- a/src/pymodaq_plugins_teaching/daq_move_plugins/daq_move_Monochromator.py +++ b/src/pymodaq_plugins_teaching/daq_move_plugins/daq_move_Monochromator.py @@ -1,6 +1,9 @@ -from pymodaq.control_modules.move_utility_classes import DAQ_Move_base, comon_parameters_fun, main -from pymodaq.utils.daq_utils import ThreadCommand, getLineInfo # object used to send info back to the main thread -from easydict import EasyDict as edict # type of 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 + + from pymodaq_plugins_teaching.hardware.spectrometer import Spectrometer @@ -15,15 +18,29 @@ class DAQ_Move_Monochromator(DAQ_Move_base): 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 + """ - _controller_units = 'Wavelength' - is_multiaxes = True - axes_names = ['wavelength'] + _controller_units = 'whatever' # TODO for your plugin: put the correct unit here + is_multiaxes = True # TODO for your plugin set to True if this plugin is controlled for a multiaxis controller + axes_names = [] # TODO for your plugin: complete the list + _epsilon = 0.1 # TODO replace this by a value that is correct depending on your controller + data_actuator_type = DataActuatorType['DataActuator'] # wether you use the new data style for actuator otherwise set this + # as DataActuatorType['float'] (or entirely remove the line) + + params = [{'title': 'mytilte', 'name': 'gratings', 'type': 'list', 'limits': Spectrometer.gratings}, + ] + comon_parameters_fun(is_multiaxes, axes_names, epsilon=_epsilon) + # _epsilon is the initial default value for the epsilon parameter allowing pymodaq to know if the controller reached + # the target value. It is the developer responsibility to put here a meaningful value - params = [{'title': 'Info:', 'name': 'info', 'type': 'str', 'value': ''}, - {'title': 'Grating:', 'name': 'grating', 'type': 'list', 'values': Spectrometer.gratings}, - {'title': 'Tau (ms):', 'name': 'tau', 'type': 'int', 'value': 2000},] +\ - comon_parameters_fun(is_multiaxes, axes_names) + def ini_attributes(self): + # TODO declare the type of the wrapper (and assign it to self.controller) you're going to use for easy + # autocompletion + self.controller: Spectrometer = None + + + #TODO declare here attributes you want/need to init with a default value + pass def get_actuator_value(self): """Get the current value from the hardware with scaling conversion. @@ -32,16 +49,15 @@ def get_actuator_value(self): ------- float: The position obtained after scaling conversion. """ - - pos = self.controller.get_wavelength() # when writing your own plugin replace this line + pos = DataActuator(data=self.controller.get_wavelength()) # 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_communication() + self.controller.close_communication() # when writing your own plugin replace this line - def commit_settings(self, param): + def commit_settings(self, param: Parameter): """Apply the consequences of a change of value in the detector settings Parameters @@ -49,12 +65,11 @@ def commit_settings(self, param): param: Parameter A given parameter (within detector_settings) whose value has been changed by the user """ - if param.name() == "grating": - self.controller.grating = param.value() - elif param.name() == 'tau': - self.controller.tau = param.value() / 1000 + ## TODO for your custom plugin + if param.name() == "gratings": + self.controller.grating = param.value() - def ini_stage(self, controller: Spectrometer = None): + def ini_stage(self, controller=None): """Actuator communication initialization Parameters @@ -68,16 +83,18 @@ def ini_stage(self, controller: Spectrometer = None): initialized: bool False if initialization failed otherwise True """ - self.controller = self.ini_stage_init(old_controller=controller, - new_controller=Spectrometer()) - self.controller.open_communication() - self.settings.child('info').setValue(self.controller.infos) - info = self.controller.infos - initialized = True # or False if your hardware coun't be initialized + self.controller: Spectrometer = self.ini_stage_init(old_controller=controller, + new_controller=Spectrometer()) + if self.settings['multiaxes', 'multi_status'] == 'Master': + initialized = self.controller.open_communication() + else: + initialized = True + + info = "Whatever info you want to log" return info, initialized - def move_abs(self, value): + def move_abs(self, value: DataActuator): """ Move the actuator to the absolute target defined by value Parameters @@ -86,30 +103,37 @@ def move_abs(self, value): """ value = self.check_bound(value) #if user checked bounds, the defined bounds are applied here + self.target_value = value value = self.set_position_with_scaling(value) # apply scaling if the user specified one - self.controller.set_wavelength(value, 'abs') - self.target_position = value - def move_rel(self, value): + self.controller.set_wavelength(value.value()) # when writing your own plugin replace this line + self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log'])) + + 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 value + value: (float) value of the relative target positioning """ - value = self.check_bound(self.current_position+value)-self.current_position - self.target_position = value + self.current_position - self.controller.set_wavelength(value, 'rel') + 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.set_wavelength(value.value(), 'rel') # when writing your own plugin replace this line + self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log'])) def move_home(self): """Call the reference method of the controller""" - self.controller.find_reference() + + self.controller.find_reference() # when writing your own plugin replace this line + self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log'])) def stop_motion(self): - """Stop the actuator and emits move_done signal""" - self.controller.stop() + """Stop the actuator and emits move_done signal""" + self.emit_status(ThreadCommand('Update_Status', ['Not possible to stop the motion'])) -if __name__ == '__main__': - main(__file__) +if __name__ == '__main__': + main(__file__, init=False) diff --git a/src/pymodaq_plugins_teaching/daq_move_plugins/daq_move_Monochromator2.py b/src/pymodaq_plugins_teaching/daq_move_plugins/daq_move_Monochromator2.py deleted file mode 100644 index d6c5131..0000000 --- a/src/pymodaq_plugins_teaching/daq_move_plugins/daq_move_Monochromator2.py +++ /dev/null @@ -1,144 +0,0 @@ -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 - - -from pymodaq_plugins_teaching.hardware.spectrometer import Spectrometer - -Spectrometer.gratings - -class DAQ_Move_Monochromator2(DAQ_Move_base): - """Plugin for the Template Instrument - - This object inherits all functionality to communicate with PyMoDAQ Module through inheritance via DAQ_Move_base - It then implements the particular communication with the instrument - - 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 - - """ - _controller_units = 'whatever' # TODO for your plugin: put the correct unit here - is_multiaxes = True # TODO for your plugin set to True if this plugin is controlled for a multiaxis controller - axes_names = [] # TODO for your plugin: complete the list - _epsilon = 0.1 # TODO replace this by a value that is correct depending on your controller - data_actuator_type = DataActuatorType['DataActuator'] # wether you use the new data style for actuator otherwise set this - # as DataActuatorType['float'] (or entirely remove the line) - - params = [{'title': 'mytilte', 'name': 'gratings', 'type': 'list', 'limits': Spectrometer.gratings}, - ] + comon_parameters_fun(is_multiaxes, axes_names, epsilon=_epsilon) - # _epsilon is the initial default value for the epsilon parameter allowing pymodaq to know if the controller reached - # the target value. It is the developer responsibility to put here a meaningful value - - def ini_attributes(self): - # TODO declare the type of the wrapper (and assign it to self.controller) you're going to use for easy - # autocompletion - self.controller: Spectrometer = None - - - #TODO declare here attributes you want/need to init with a default value - pass - - 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_wavelength()) # 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_communication() # when writing your own plugin replace this line - - 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 - """ - ## TODO for your custom plugin - if param.name() == "gratings": - self.controller.grating = param.value() - self.settings.child('units').setValue('Power') - 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.controller: Spectrometer = self.ini_stage_init(old_controller=controller, - new_controller=Spectrometer()) - if self.settings['multiaxes', 'multi_status'] == 'Master': - init = self.controller.open_communication() - else: - self.controller.is_init() - - info = "Whatever info you want to log" - initialized = init - 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) #if user checked bounds, the defined bounds are applied here - self.target_value = value - value = self.set_position_with_scaling(value) # apply scaling if the user specified one - ## TODO for your custom plugin - self.controller.set_wavelength(value.value()) # when writing your own plugin replace this line - self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log'])) - - 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.set_wavelength(value.value(), 'rel') # when writing your own plugin replace this line - self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log'])) - - def move_home(self): - """Call the reference method of the controller""" - - self.controller.find_reference() # when writing your own plugin replace this line - self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log'])) - - def stop_motion(self): - """Stop the actuator and emits move_done signal""" - - self.emit_status(ThreadCommand('Update_Status', ['Not possible to stop the motion'])) - - -if __name__ == '__main__': - main(__file__, init=False)