Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version 0.5.3 #76

Merged
merged 5 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .github/workflows/markdownlint.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/pylint.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Test

on: [push, pull_request]

jobs:
markdownlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DavidAnson/markdownlint-cli2-action@v14
with:
globs: |
README.md
CHANGELOG.md
docs/*.md

pylint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.9", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install gpiozero
pip install RPi.GPIO
pip install Mock.GPIO
pip install mock
pip install pyserial
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=C0103 --disable=W0511 --extension-pkg-whitelist=RPi

unittest:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.9", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install gpiozero
pip install RPi.GPIO
pip install Mock.GPIO
pip install pyserial
- name: Run unittests
run: |
python -m unittest
26 changes: 0 additions & 26 deletions .github/workflows/unittest.yml

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## version 0.5.3

- added math function constrain
- added function set_speed
- added function set_speed_fullstep
- added demo_script_11_continous_movement
- reworked github actions pipeline (one multi-staged-pipeline)

## version 0.5.2

- added extra error handling for when the UART serial is not set
Expand Down
142 changes: 142 additions & 0 deletions demo/demo_script_11_continous_movement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#pylint: disable=wildcard-import
#pylint: disable=unused-wildcard-import
#pylint: disable=unused-import
#pylint: disable=duplicate-code
"""
test file for testing basic movement
"""

import time
try:
from src.TMC_2209.TMC_2209_StepperDriver import *
from src.TMC_2209._TMC_2209_GPIO_board import Board
except ModuleNotFoundError:
from TMC_2209.TMC_2209_StepperDriver import *
from TMC_2209._TMC_2209_GPIO_board import Board


print("---")
print("SCRIPT START")
print("---")





#-----------------------------------------------------------------------
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
if BOARD == Board.RASPBERRY_PI:
tmc = TMC_2209(21, 16, 20, loglevel=Loglevel.DEBUG)
elif BOARD == Board.RASPBERRY_PI5:
tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0", loglevel=Loglevel.DEBUG)
elif BOARD == Board.NVIDIA_JETSON:
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", loglevel=Loglevel.DEBUG)
else:
# just in case
tmc = TMC_2209(21, 16, 20, loglevel=Loglevel.DEBUG)






#-----------------------------------------------------------------------
# set the loglevel of the libary (currently only printed)
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)





#-----------------------------------------------------------------------
# these functions change settings in the TMC register
#-----------------------------------------------------------------------
tmc.set_direction_reg(False)
tmc.set_current(300)
tmc.set_interpolation(True)
tmc.set_spreadcycle(False)
tmc.set_microstepping_resolution(2)
tmc.set_internal_rsense(False)


print("---\n---")





#-----------------------------------------------------------------------
# these functions read and print the current settings in the TMC register
#-----------------------------------------------------------------------
tmc.read_ioin()
tmc.read_chopconf()
tmc.read_drv_status()
tmc.read_gconf()

print("---\n---")







#-----------------------------------------------------------------------
# set the max Speed and Speed in fullsteps
#-----------------------------------------------------------------------
tmc.set_max_speed_fullstep(200)
tmc.set_speed_fullstep(100)







#-----------------------------------------------------------------------
# activate the motor current output
#-----------------------------------------------------------------------
tmc.set_motor_enabled(True)





#-----------------------------------------------------------------------
# move the motor 4 seconds
#-----------------------------------------------------------------------
time_start = time.time()

while time.time() < time_start + 4:
tmc.run_speed()






#-----------------------------------------------------------------------
# deactivate the motor current output
#-----------------------------------------------------------------------
tmc.set_motor_enabled(False)

print("---\n---")





#-----------------------------------------------------------------------
# deinitiate the TMC_2209 class
#-----------------------------------------------------------------------
del tmc

print("---")
print("SCRIPT FINISHED")
print("---")
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = TMC_2209_Raspberry_Pi
version = 0.5.2
version = 0.5.3
author = Christian Köhlke
author_email = christian@koehlke.de
description = this is a Python libary to drive a stepper motor with a Trinamic TMC2209 stepper driver and a Raspberry Pi
Expand Down
8 changes: 4 additions & 4 deletions src/TMC_2209/TMC_2209_StepperDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class TMC_2209:
)

from ._TMC_2209_move import (
set_movement_abs_rel, get_current_position, set_current_position, set_max_speed,
set_max_speed_fullstep, get_max_speed, set_acceleration, set_acceleration_fullstep,
get_acceleration, stop, get_movement_phase, run_to_position_steps,
run_to_position_revolutions, run_to_position_steps_threaded,
set_movement_abs_rel, get_current_position, set_current_position, set_speed,
set_speed_fullstep, set_max_speed, set_max_speed_fullstep, get_max_speed,
set_acceleration, set_acceleration_fullstep, get_acceleration, stop, get_movement_phase,
run_to_position_steps, run_to_position_revolutions, run_to_position_steps_threaded,
run_to_position_revolutions_threaded, wait_for_movement_finished_threaded, run,
distance_to_go, compute_new_speed, run_speed, make_a_step
)
Expand Down
18 changes: 18 additions & 0 deletions src/TMC_2209/_TMC_2209_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,21 @@ def steps_to_tstep(steps, msres):
tstep (int): time per step
"""
return int(round(12000000 / (steps * 256 / msres)))


def constrain(val, min_val, max_val):
"""constrains a value between a min and a max

Args:
val (int): value that should be constrained
min_val (int): minimum value
max_val (int): maximum value

Returns:
int: constrained value
"""
if val < min_val:
return min_val
if val > max_val:
return max_val
return val
31 changes: 31 additions & 0 deletions src/TMC_2209/_TMC_2209_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import threading
from ._TMC_2209_GPIO_board import TMC_gpio, Gpio
from ._TMC_2209_logger import Loglevel
from . import _TMC_2209_math as tmc_math



Expand Down Expand Up @@ -74,6 +75,36 @@ def set_current_position(self, new_pos):
self._current_pos = new_pos


def set_speed(self, speed):
"""sets the motor speed in steps per second

Args:
speed (int): speed in steps/sec
"""
if speed == self._speed:
return
speed = tmc_math.constrain(speed, -self._max_speed, self._max_speed)
if speed == 0.0:
self._step_interval = 0
else:
self._step_interval = abs(1000000.0 / speed)
if speed > 0:
self.set_direction_pin_or_reg(1)
self.tmc_logger.log("going CW", Loglevel.MOVEMENT)
else:
self.set_direction_pin_or_reg(0)
self.tmc_logger.log("going CCW", Loglevel.MOVEMENT)
self._speed = speed


def set_speed_fullstep(self, speed):
"""sets the motor speed in fullsteps per second

Args:
speed (int): speed in fullsteps/sec
"""
self.set_speed(speed*self.get_microstepping_resolution())


def set_max_speed(self, speed):
"""sets the maximum motor speed in µsteps per second
Expand Down
Loading
Loading