Skip to content

Commit

Permalink
updated the move example from right template
Browse files Browse the repository at this point in the history
  • Loading branch information
seb5g committed Nov 8, 2023
1 parent 6bcdbd6 commit 4894689
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 182 deletions.
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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.
Expand All @@ -32,29 +49,27 @@ 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
----------
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
Expand All @@ -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
Expand All @@ -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)

This file was deleted.

0 comments on commit 4894689

Please sign in to comment.