From 3f01f9f2a97b5c9a33216ecec3e0f72ba64858b3 Mon Sep 17 00:00:00 2001 From: rpartzsch Date: Fri, 25 Oct 2024 10:21:38 +0200 Subject: [PATCH 1/2] GIT: pre-commit workflow --- .github/pre-commit.yml | 14 ++++++++++++++ .pre-commit-config.yaml | 11 +++++++++++ README.md | 14 +++++++------- motor_stage_ui/configuration.yaml | 6 +++--- motor_stage_ui/motor_stage_gui.py | 9 ++++++--- motor_stage_ui/motor_stage_terminal.py | 3 ++- setup.py | 9 +-------- 7 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 .github/pre-commit.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/pre-commit.yml b/.github/pre-commit.yml new file mode 100644 index 0000000..2b11178 --- /dev/null +++ b/.github/pre-commit.yml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..48ee030 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/psf/black + rev: 22.10.0 + hooks: + - id: black diff --git a/README.md b/README.md index d6cf699..1212bdf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Motor stage UI [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) -Offers both a terminal and graphical user interface for the Mercury motor controller. +Offers both a terminal and graphical user interface for the Mercury motor controller. Motor stages can be arranged in daisy chains. ## Installation @@ -14,8 +14,8 @@ pip install -e . ## Usage -Configure your specific stage setup in ```motor_stage_ui/configuration.yaml```. -Check the baud rate, address, USB connection, and any potential logic active low settings for the individual motor stage controller. +Configure your specific stage setup in ```motor_stage_ui/configuration.yaml```. +Check the baud rate, address, USB connection, and any potential logic active low settings for the individual motor stage controller. Set a motor stage name (e.g., ```x_axis```), type, and step size according to the hardware specifications of the motor stage. Start the motor stage GUI: @@ -26,8 +26,8 @@ or control the stage through the terminal: ```bash motor COMMAND arguments ``` -The ```COMMAND``` can be ```move``` or ```stop```, and the arguments consist of a move value and the motor stage name. -The motor stage UI accepts move values in various units (mm, cm, deg, rad, etc.) and converts them automatically. +The ```COMMAND``` can be ```move``` or ```stop```, and the arguments consist of a move value and the motor stage name. +The motor stage UI accepts move values in various units (mm, cm, deg, rad, etc.) and converts them automatically. The motor stage velocity is set during the initialization step. To avoid unwanted behavior (especially if the default motor speed is too slow), ensure to initialize the motor stage even when using the terminal. @@ -51,9 +51,9 @@ motor init MOTORNAME | Terminal Command | GUI Command | Description | First Argument | Second Argument | |---------|-------------|-----------|-----------|-----------| | `init` | `Init.` | Initialize motor stage. Powering and resetting the motor. Set motor move speed in the PIStageInterface.py function.| motor_name (str): name of the motorstage | - | -| `move` | `Input rel.` | Moves the motor stage a relative amount, positive values for ahead, negatives for back. Accepts string inputs with units (4cm, -2mm...). If no unit is given, the motor moves the default unit amount. | motor_name (str): name of the motorstage | a (str): Move amount | +| `move` | `Input rel.` | Moves the motor stage a relative amount, positive values for ahead, negatives for back. Accepts string inputs with units (4cm, -2mm...). If no unit is given, the motor moves the default unit amount. | motor_name (str): name of the motorstage | a (str): Move amount | | `moveto` | `input abs.` | Moves the motor stage to a absolut position. Accepts string inputs with units (4cm, -2mm...). If no unit is given, the motor moves to the default position unit. | motor_name (str): name of the motorstage |a (str): Move to position | | `pos` | - | Logs the current position of the motor stage.| motor_name (str): name of the motorstage | -| | `stop` | `Stop` | Immediately stops all movement of the stage | motor_name (str): name of the motorstage | - | | `sethome` | `Set Zero` | Sets the current position of the stage as new origin | motor_name (str): name of the motorstage | - | -| `gohome` | `MV. Zero` | Goes to origin of the stage | motor_name (str): name of the motorstage | - | \ No newline at end of file +| `gohome` | `MV. Zero` | Goes to origin of the stage | motor_name (str): name of the motorstage | - | diff --git a/motor_stage_ui/configuration.yaml b/motor_stage_ui/configuration.yaml index 427a629..b6a4b85 100644 --- a/motor_stage_ui/configuration.yaml +++ b/motor_stage_ui/configuration.yaml @@ -4,12 +4,12 @@ # name: # stage: define stage typus 'rotation', 'translation' # address: set with dip switches -# step_size: depends on the design specifics of the hardware (stage and powering), check 'Design resolution' in e.g.: +# step_size: depends on the design specifics of the hardware (stage and powering), check 'Design resolution' in e.g.: # https://www.pi-usa.us/fileadmin/user_upload/physik_instrumente/files/CAT/PI-CAT132E-Precision-Positioning-and-Motion-Control-Web.pdf # set in um for translation stage and in deg for rotational stage # M-038.DG rotational stage: step_size=0.59 urad / 34*10**(-6) deg # M-403.6DG translation stage: step_size=0.018 um -# unit: set output unit and default input unit +# unit: set output unit and default input unit x_axis: stage_type: translation @@ -33,4 +33,4 @@ rot: step_size: 34e-06 unit: deg port: '/dev/ttyUSB0' - baud_rate: '9600' \ No newline at end of file + baud_rate: '9600' diff --git a/motor_stage_ui/motor_stage_gui.py b/motor_stage_ui/motor_stage_gui.py index 8bc794d..a46fa53 100644 --- a/motor_stage_ui/motor_stage_gui.py +++ b/motor_stage_ui/motor_stage_gui.py @@ -10,7 +10,7 @@ import os """ - + GUI for the motor stage """ @@ -33,7 +33,8 @@ def __init__(self, config_path): for index, motor in enumerate(self.conf): self.motor.append( PIStagesInterface( - port=self.conf[motor]["port"], baud_rate=self.conf[motor]["baud_rate"] + port=self.conf[motor]["port"], + baud_rate=self.conf[motor]["baud_rate"], ) ) stage = self.conf[motor]["stage_type"] @@ -65,7 +66,9 @@ def __init__(self, config_path): self.get_position_clicked( self.conf[list(self.conf.keys())[i]]["address"], unit=self.conf[list(self.conf.keys())[i]]["unit"], - stage=self.conf[list(self.conf.keys())[i]]["stage_type"], + stage=self.conf[list(self.conf.keys())[i]][ + "stage_type" + ], step_size=eval( str( self.conf[list(self.conf.keys())[i]][ diff --git a/motor_stage_ui/motor_stage_terminal.py b/motor_stage_ui/motor_stage_terminal.py index 9a2285a..499e515 100644 --- a/motor_stage_ui/motor_stage_terminal.py +++ b/motor_stage_ui/motor_stage_terminal.py @@ -7,10 +7,11 @@ """ -Terminal control UI. +Terminal control UI. """ + @click.group() @click.pass_context def motor(conf): diff --git a/setup.py b/setup.py index 1667cf8..eed77bf 100644 --- a/setup.py +++ b/setup.py @@ -10,14 +10,7 @@ "": ["motor_stage_ui/configuration.yaml"], }, include_package_data=True, - install_requires=[ - "Click", - "pint", - "coloredlogs", - "PyQt5", - "pyserial", - "pyyaml" - ], + install_requires=["Click", "pint", "coloredlogs", "PyQt5", "pyserial", "pyyaml"], entry_points={ "console_scripts": [ "motor = motor_stage_ui.motor_stage_terminal:motor", From 3b2287c0092251731778cfa06c9448b16cbaad9c Mon Sep 17 00:00:00 2001 From: rpartzsch Date: Fri, 25 Oct 2024 10:39:37 +0200 Subject: [PATCH 2/2] GIT: improved workflow + DOC: small change in README --- .github/pre-commit.yml | 11 +++++++++++ README.md | 1 + 2 files changed, 12 insertions(+) diff --git a/.github/pre-commit.yml b/.github/pre-commit.yml index 2b11178..950473b 100644 --- a/.github/pre-commit.yml +++ b/.github/pre-commit.yml @@ -12,3 +12,14 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - uses: pre-commit/action@v3.0.1 + with: + extra_args: flake8 --all-files + + installation: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - name: Install dependencies + run: | + pip install -e . diff --git a/README.md b/README.md index 1212bdf..8f8d66b 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ motor init MOTORNAME ``` ### Configuration +The step size of a specific stage is given in um for translation stages and deg for rotation stages and can be obtained from the 'Design resolution' in e.g. [PI precision position and motion control](https://www.pi-usa.us/fileadmin/user_upload/physik_instrumente/files/CAT/PI-CAT132E-Precision-Positioning-and-Motion-Control-Web.pdf). | Configuration | Description | Type | |-----------|-------------|------|