Skip to content

Commit ed2b462

Browse files
committed
feat: add unit tests for TMC movement functionality
1 parent ad35f70 commit ed2b462

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

.github/workflows/micropython_test.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,3 @@ jobs:
1717
- name: Test MicroPython Installation
1818
run: |
1919
micropython tests_micropython/test.py
20-
# - name: Set up Python
21-
# with:
22-
# python-version: "3.13"
23-
# uses: actions/setup-python@v6
24-
# - name: Install dependencies
25-
# run: |
26-
# python -m pip install --upgrade pip
27-
# pip install coverage
28-
# pip install gpiozero
29-
# pip install python-periphery
30-
# pip install RPi.GPIO
31-
# pip install Mock.GPIO
32-
# pip install pyserial
33-
# pip install spidev
34-
# pip install pyftdi
35-
# - name: Run unittests
36-
# run: |
37-
# python -m coverage run -m unittest discover

tests_micropython/test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,49 @@
22

33
print(sys.version)
44
print(sys.implementation)
5+
6+
7+
import unittest
8+
from src.tmc_driver import (
9+
Tmc2209,
10+
TmcEnableControlPin,
11+
TmcMotionControlStepDir,
12+
MovementAbsRel,
13+
)
14+
15+
16+
class TestTMCMove(unittest.TestCase):
17+
"""TestTMCMove"""
18+
19+
def setUp(self):
20+
"""setUp"""
21+
self.tmc = Tmc2209(TmcEnableControlPin(1), TmcMotionControlStepDir(2, 3))
22+
23+
# these values are normally set by reading the driver
24+
self.tmc.mres = 2
25+
26+
self.tmc.acceleration_fullstep = 100000
27+
self.tmc.max_speed_fullstep = 10000
28+
self.tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
29+
30+
def tearDown(self):
31+
"""tearDown"""
32+
33+
def test_run_to_position_steps(self):
34+
"""test_run_to_position_steps"""
35+
36+
self.tmc.run_to_position_steps(400, MovementAbsRel.RELATIVE)
37+
pos = self.tmc.tmc_mc.current_pos
38+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
39+
40+
self.tmc.run_to_position_steps(-200, MovementAbsRel.RELATIVE)
41+
pos = self.tmc.tmc_mc.current_pos
42+
self.assertEqual(pos, 200, f"actual position: {pos}, expected position: 200")
43+
44+
self.tmc.run_to_position_steps(400)
45+
pos = self.tmc.tmc_mc.current_pos
46+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
47+
48+
49+
if __name__ == "__main__":
50+
unittest.main()

0 commit comments

Comments
 (0)