Skip to content

Commit eda501d

Browse files
authored
Merge pull request #16 from PyMoDAQ/feature/MCS2_cleaning
Feature/mcs2 cleaning
2 parents 04b7b57 + 8d71717 commit eda501d

File tree

9 files changed

+1844
-45
lines changed

9 files changed

+1844
-45
lines changed

src/pymodaq_plugins_smaract/daq_move_plugins/daq_move_SmarActMCS2.py

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
from pymodaq.control_modules.move_utility_classes import DAQ_Move_base, comon_parameters_fun, main # common set of parameters for all actuators
2-
from pymodaq_utils.utils import ThreadCommand, getLineInfo # object used to send info back to the main thread
1+
2+
3+
from pymodaq.control_modules.move_utility_classes import (DAQ_Move_base, comon_parameters_fun,
4+
main, DataActuatorType, DataActuator) # common set of parameters for all actuators
5+
from pymodaq_utils.utils import ThreadCommand, getLineInfo
6+
37
from pymodaq_gui.parameter import Parameter
48

59
from pymodaq_plugins_smaract.hardware.smaract.smaract_MCS2_wrapper import SmarActMCS2Wrapper
610
from pymodaq_plugins_smaract.hardware.smaract.smaract_MCS2_wrapper import get_controller_locators
711

812

9-
1013
"""This plugin handles SmarAct MCS2 controller with LINEAR positioners with the
1114
S option (which means that an encoder is present and give a feedback on the
1215
current position).
@@ -35,17 +38,14 @@ class DAQ_Move_SmarActMCS2(DAQ_Move_base):
3538
is_multiaxes = True # we suppose a have a MCS2 controller with a sensor
3639
# module for 3 channels (stages).
3740

38-
axes_names= {'Axis 1': 0, 'Axis 2': 1, 'Axis 3': 2} # be careful that the channel index starts at 0
41+
axis_names= {'Axis 1': 0, 'Axis 2': 1, 'Axis 3': 2} # be careful that the channel index starts at 0
3942
# and not at 1 has is done in MCS2ServiceTool
4043

41-
# bounds corresponding to the SLC-24180. Will be used at default if user doesn't provide other ones.
42-
min_bound = -61500 # µm
43-
max_bound = +61500 # µm
44-
45-
offset = 0 # µm
44+
data_actuator_type = DataActuatorType.DataActuator
4645

4746
_epsilon = 0.005 # µm precision tolerance for movement
4847

48+
4949
params = [
5050
{'title': 'group parameter:',
5151
'name': 'group_parameter',
@@ -60,23 +60,22 @@ class DAQ_Move_SmarActMCS2(DAQ_Move_base):
6060
'name': 'controller_locator', 'type': 'list',
6161
'limits': controller_locators},
6262
]}
63-
] + comon_parameters_fun(is_multiaxes, axes_names, epsilon=_epsilon)
63+
] + comon_parameters_fun(axis_names=axis_names, epsilon=_epsilon)
6464

6565
def ini_attributes(self):
6666
self.controller: SmarActMCS2Wrapper = None
6767

68-
def get_actuator_value(self):
68+
def get_actuator_value(self) -> DataActuator:
6969
"""Get the current value from the hardware with scaling conversion.
7070
7171
Returns
7272
-------
7373
float: The position obtained after scaling conversion.
7474
"""
75-
pos = self.controller.get_position(
76-
self.settings.child('multiaxes', 'axis').value())
77-
pos = float(pos) / 1e6 # the position given by the
78-
# controller is in picometers, we convert in micrometers
75+
pos = self.controller.get_position(self.axis_value)
76+
pos = DataActuator(data=pos, units='pm').units_as(self.axis_unit)
7977
pos = self.get_position_with_scaling(pos)
78+
# the position given by the controller is in picometers, we convert in plugin units
8079
return pos
8180

8281
def close(self):
@@ -108,27 +107,23 @@ def ini_stage(self, controller=None):
108107
initialized: bool
109108
False if initialization failed otherwise True
110109
"""
111-
112-
self.ini_stage_init(old_controller=controller,
113-
new_controller=SmarActMCS2Wrapper())
110+
if self.is_master:
111+
self.controller = SmarActMCS2Wrapper()
112+
self.controller.init_communication(
113+
self.settings['group_parameter', 'controller_locator'])
114+
else:
115+
self.controller = controller
114116

115117
# min and max bounds will depend on which positionner is plugged.
116118
self.settings.child('bounds', 'is_bounds').setValue(True)
117-
if self.settings.child('bounds', 'min_bound').value() == 0:
118-
self.settings.child('bounds', 'min_bound').setValue(self.min_bound)
119-
120-
if self.settings.child('bounds', 'max_bound').value() == 1:
121-
self.settings.child('bounds', 'max_bound').setValue(self.max_bound)
119+
self.settings.child('bounds', 'min_bound').setValue(self.min_bound)
120+
self.settings.child('bounds', 'max_bound').setValue(self.max_bound)
122121

123-
if self.settings['multiaxes', 'multi_status'] == "Master":
124-
self.controller.init_communication(
125-
self.settings.child('group_parameter',
126-
'controller_locator').value())
127122
initialized = True
128123
info = "Smaract stage initialized"
129124
return info, initialized
130125

131-
def move_abs(self, value):
126+
def move_abs(self, value: DataActuator):
132127
""" Move the actuator to the absolute target defined by value
133128
134129
Parameters
@@ -139,11 +134,10 @@ def move_abs(self, value):
139134
value = self.check_bound(value) # if user checked bounds, the defined bounds are applied here
140135
self.target_value = value
141136
value = self.set_position_with_scaling(value) # apply scaling if the user specified one
142-
value = int(value * 1e6)
143-
self.controller.absolute_move(self.settings['multiaxes', 'axis'], value)
144-
self.emit_status(ThreadCommand('Update_Status', [f'Moving to {self.target_value}']))
137+
value = int(value.units_as('pm').value())
138+
self.controller.absolute_move(self.axis_value, value)
145139

146-
def move_rel(self, value):
140+
def move_rel(self, value: DataActuator):
147141
""" Move the actuator to the relative target actuator value defined by value
148142
149143
Parameters
@@ -155,22 +149,19 @@ def move_rel(self, value):
155149
relative_move = self.set_position_relative_with_scaling(value)
156150

157151
# convert relative_move in picometers
158-
relative_move = int(relative_move*1e6)
152+
relative_move = int(relative_move.units_as('pm').value())
159153

160-
self.controller.relative_move(self.settings['multiaxes', 'axis'], relative_move)
161-
self.emit_status(ThreadCommand('Update_Status', [f'Moving to {self.target_value}']))
154+
self.controller.relative_move(self.axis_value, relative_move)
162155

163156
def move_home(self):
164157
"""Move to the physical reference and reset position to 0
165158
"""
166-
self.controller.find_reference(self.settings['multiaxes', 'axis'])
167-
self.emit_status(ThreadCommand('Update_Status',
168-
['The positioner has been referenced']))
159+
self.controller.find_reference(self.axis_value)
169160

170161
def stop_motion(self):
171162
"""Stop the actuator and emits move_done signal"""
172-
self.controller.stop(self.settings['multiaxes', 'axis'])
173-
self.emit_status(ThreadCommand('Update_Status', ['The positioner has been stopped']))
163+
self.controller.stop(self.axis_value)
164+
174165

175166

176167
if __name__ == '__main__':

0 commit comments

Comments
 (0)