Skip to content
Merged
98 changes: 39 additions & 59 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,46 +1,26 @@
pymodaq_plugins_template
########################
pymodaq_plugins_owis
####################

.. the following must be adapted to your developed package, links to pypi, github description...

.. image:: https://img.shields.io/pypi/v/pymodaq_plugins_template.svg
:target: https://pypi.org/project/pymodaq_plugins_template/
.. image:: https://img.shields.io/pypi/v/pymodaq_plugins_owis.svg
:target: https://pypi.org/project/pymodaq_plugins_owis/
:alt: Latest Version

.. image:: https://readthedocs.org/projects/pymodaq/badge/?version=latest
:target: https://pymodaq.readthedocs.io/en/stable/?badge=latest
:alt: Documentation Status

.. image:: https://github.com/PyMoDAQ/pymodaq_plugins_template/workflows/Upload%20Python%20Package/badge.svg
:target: https://github.com/PyMoDAQ/pymodaq_plugins_template
:alt: Publication Status

.. image:: https://github.com/PyMoDAQ/pymodaq_plugins_template/actions/workflows/Test.yml/badge.svg
:target: https://github.com/PyMoDAQ/pymodaq_plugins_template/actions/workflows/Test.yml
.. image:: https://github.com/jerlfan/pymodaq_plugins_owis/actions/workflows/Test.yml/badge.svg
:target: https://github.com/jerlfan/pymodaq_plugins_owis/actions/workflows/Test.yml


Use this template to create a repository on your account and start the development of your own PyMoDAQ plugin!
PyMoDAQ plugin for OWIS positioning units driven by PS 10 control units, chained on their CANopen bus.

This branch targets **PyMoDAQ 5.3.x** (Python 3.10 to 3.13). Use the branch matching your PyMoDAQ version.
This branch targets **PyMoDAQ 5.3.x** (Python 3.10 to 3.13).

Authors
=======

* First Author (myemail@xxx.org)
* Other author (myotheremail@xxx.org)

.. if needed use this field

Contributors
============

* First Contributor
* Other Contributors

.. if needed use this field

Depending on the plugin type, delete/complete the fields below

* Jérémie Margueritat (jeremie.margueritat@univ-lyon1.fr)

Instruments
===========
Expand All @@ -50,50 +30,50 @@ Below is the list of instruments included in this plugin
Actuators
+++++++++

* **yyy**: control of yyy actuators
* **xxx**: control of xxx actuators

Viewer0D
++++++++
* **OWIS_PS10**: OWIS stages driven by PS 10 control units, one axis per unit, the units being chained on their
CANopen bus (tested with HVM100N-30-HiSM, LTM60-25-HSM and DMT65-DM6-HSM stages)

* **yyy**: control of yyy 0D detector
* **xxx**: control of xxx 0D detector

Viewer1D
++++++++

* **yyy**: control of yyy 1D detector
* **xxx**: control of xxx 1D detector


Viewer2D
++++++++

* **yyy**: control of yyy 2D detector
* **xxx**: control of xxx 2D detector
Installation instructions
=========================

* Tested with PyMoDAQ 5.3.10, Python 3.12, Windows 11.
* Install the USB driver of the PS 10, supplied by OWIS with OWISoft.
* Configure each stage once with OWISoft (currents, limit and reference switches, reference velocities): the plugin
uses the parameters stored in the units. Close OWISoft before using the plugin, both use the same serial port.

PID Models
==========

Configuration
=============

Extensions
==========
The serial port and the axes are read from the configuration of the plugin. Describe your setup in your local
configuration file (``config_owis.toml`` in the ``config`` folder of your PyMoDAQ user directory), with
PyMoDAQ closed, since PyMoDAQ rewrites this file when it closes. Each ``[[ps10.axes]]`` block describes one unit,
with the values shown by OWISoft in *Control > Define positioning unit*::

[ps10]
port = 'COM8' # MOCK to simulate the units

Installation instructions
=========================
[[ps10.axes]]
name = 'X'
stage = 'LTM60-25-HSM'
slave_id = 'master' # else the slave ID of the unit on the CANopen bus
units = 'mm' # 'degree' for a rotation stage
pitch = 1.0
gear_ratio = 1.0
fullsteps_per_revolution = 200
microsteps = 50
home_position = 12.5 # position reached after the reference run

* PyMoDAQ’s version.
* Operating system’s version.
* What manufacturer’s drivers should be installed to make this plugin run?
The axes of the local file replace those of the template. *Home* runs the reference run of the PS 10 (mode 4:
approach the reference switch, release it, set the position to 0), then moves the axis to its ``home_position``.


Development
===========

* Install your plugin in editable mode: ``pip install -e .``
* Check it, without any hardware: ``check_plugin`` (and ``pytest``)
* Check it, without any hardware: ``check_plugin`` and ``pytest tests``
* If you use an AI coding assistant, point it to ``AGENTS.md``: it describes the patterns to follow for instrument
plugins, Dashboard extensions (``CustomExt``, whenever instruments are involved) and standalone apps
(``CustomApp``, only if no instruments are needed).
(``CustomApp``, only if no instruments are needed).
135 changes: 135 additions & 0 deletions src/pymodaq_plugins_owis/daq_move_plugins/daq_move_OWIS_PS10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
from pymodaq.control_modules.move_utility_classes import (DAQ_Move_base, comon_parameters_fun,
main, DataActuatorType, DataActuator)
from pymodaq_utils.config import GlobalConfig
from pymodaq_utils.utils import ThreadCommand
from pymodaq_gui.parameter import Parameter
from qtpy import QtCore


from pymodaq_plugins_owis.hardware.ps10 import MockPS10Bus, PS10Axis, PS10Bus, PS10Error, slave_id_from_config

config = GlobalConfig()
AXES = config('owis', 'ps10', 'axes')


class DAQ_Move_OWIS_PS10(DAQ_Move_base):
"""Actuator plugin for OWIS positioning units driven by PS 10 control units.

Each PS 10 drives one axis; several units are chained on their CANopen bus, the first one (master) being
connected by USB. One module per axis: the master module opens the bus, the others (same Controller ID, slave)
share it. The axes, their PS 10 slave ID and their mechanical data (as shown by OWISoft in
Control > Define positioning unit) are described in the [[ps10.axes]] blocks of the configuration file.

Tested with four PS 10-32 units (firmware PS10-V3.0-181010) driving HVM100N-30-HiSM, LTM60-25-HSM and
DMT65-DM6-HSM stages, on Windows 11, Python 3.12, PyMoDAQ 5.3.10. Moves, stop and the reference run (mode 4)
were tested on the hardware; the MOCK port simulates the bus for development and tests.

Installation: the USB driver of the PS 10 (supplied by OWIS with OWISoft) must be installed. The parameters of
the stages (currents, limit and reference switches, reference velocities) are those stored in the units:
configure each axis once with OWISoft. Close OWISoft before using the plugin, both use the same serial port.
"""

is_multiaxes = True
_axis_names = [axis['name'] for axis in AXES]
_controller_units = [axis['units'] for axis in AXES]
_epsilons = 0.001 # mm or deg, about ten microsteps of the stages of the default configuration

data_actuator_type = DataActuatorType.DataActuator

params = [
{'title': 'Port:', 'name': 'port', 'type': 'str', 'value': config('owis', 'ps10', 'port')},
] + comon_parameters_fun(axis_names=_axis_names)

def ini_attributes(self):
self.controller: PS10Bus | MockPS10Bus | None = None
self.axis: PS10Axis | None = None
self._home_timer = QtCore.QTimer()
self._home_timer.setInterval(100)
self._home_timer.timeout.connect(self._check_home)
self._returning_home = False

def ini_stage(self, controller=None):
"""Open the bus (master module) or reuse the one of the master, then switch the chosen axis on."""
if self.is_master:
port = self.settings['port']
if port == 'MOCK':
self.controller = MockPS10Bus(slave_ids=[slave_id_from_config(axis['slave_id']) for axis in AXES])
else:
self.controller = PS10Bus(port)
else:
self.controller = controller
self._set_axis()
state = self.axis.state()
return f"{self.axis_name}: {AXES[self.axis_index_key]['stage']}, {state.name}", True

def _set_axis(self):
"""Create the PS10Axis of the axis chosen in the settings and switch it on."""
self.axis = PS10Axis.from_config(self.controller, AXES[self.axis_index_key])
self.axis.init()

def close(self):
"""Close the bus, only from the master module that opened it."""
if self.is_master and self.controller is not None:
self.controller.close()

def get_actuator_value(self) -> DataActuator:
"""Position of the axis, read from the counter of its PS 10."""
position = DataActuator(data=self.axis.get_position(), units=self.axis_unit)
return self.get_position_with_scaling(position)

def move_abs(self, value: DataActuator):
"""Start a move to the absolute target value; PyMoDAQ then polls the position."""
value = self.check_bound(value)
self.target_value = value
value = self.set_position_with_scaling(value)
self.axis.move_abs(value.value(self.axis_unit))

def move_rel(self, value: DataActuator):
"""Start a move by value, as an absolute move to the current position plus value."""
value = self.check_bound(self.current_value + value) - self.current_value
self.target_value = value + self.current_value
target = self.set_position_with_scaling(self.target_value)
self.axis.move_abs(target.value(self.axis_unit))

def move_home(self):
"""Reference run of the axis (REF1=4), then move to the home_position of the configuration.

PyMoDAQ does not poll the position after move_home: _check_home calls move_done at the end.
"""
self._returning_home = False
self.axis.reference()
self._home_timer.start()

def _check_home(self):
"""Called every 100 ms during move_home: chain the reference run and the move to home_position."""
if self.axis.is_moving():
return
if not self._returning_home:
if not self.axis.is_referenced():
self._home_timer.stop()
self.emit_status(ThreadCommand('Update_Status',
[f'reference run of {self.axis_name} failed: {self.axis.state().name}']))
self.move_done()
return
home_position = AXES[self.axis_index_key].get('home_position', 0.)
if home_position != 0.:
self._returning_home = True
self.axis.move_abs(home_position)
return
self._home_timer.stop()
self.move_done()

def stop_motion(self):
"""Stop the axis and tell PyMoDAQ that the move is over."""
self._home_timer.stop()
self.axis.stop()
self.move_done()

def commit_settings(self, param: Parameter):
"""Apply a change of the settings."""
if param.name() == 'axis':
self._set_axis()


if __name__ == '__main__':
main(__file__)
Loading
Loading