fixed platform not moving problem

This commit is contained in:
2026-09-23 09:52:45 +08:00
parent f1bec62ca4
commit b3279cc2a6
21 changed files with 1200 additions and 59 deletions
+41 -3
View File
@@ -1,11 +1,13 @@
"""Unit-to-millimetre conversion.
"""Unit conversion: linear mm and rotary degrees.
The reference program carries the bench measurement in a comment::
Bench notes::
# 轴0(X)/轴1(Y) 实测: UNITS=10 时 1000用户单位 = 2mm → 每毫米 5000 脉冲
# 当量5 → 1000单位=1mm,不是100单位=1mm
# 轴2: 12500 用户单位 = 90°
# 轴3: 29500 用户单位 = 90°
These are the assertions that keep that comment honest.
These are the assertions that keep those notes honest.
"""
from __future__ import annotations
@@ -16,8 +18,12 @@ import pytest
from orisys_autocal.motion.units import (
PULSES_PER_MM,
ROTARY_UNITS_PER_90_DEG,
deg_to_user_units,
mm_to_user_units,
safe_float,
units_per_degree,
user_units_to_deg,
user_units_to_mm,
)
@@ -71,3 +77,35 @@ def test_zero_falls_back_because_it_would_divide(text):
@pytest.mark.parametrize(("text", "expected"), [("5", 5.0), (" 2.5 ", 2.5), ("-3", -3.0)])
def test_usable_entries_are_parsed(text, expected):
assert safe_float(text, 42.0) == expected
def test_rotary_bench_constants():
assert ROTARY_UNITS_PER_90_DEG[2] == 12500.0
assert ROTARY_UNITS_PER_90_DEG[3] == 29500.0
@pytest.mark.parametrize(
("axis", "user_units", "expected_deg"),
[
(2, 12500.0, 90.0),
(2, 25000.0, 180.0),
(3, 29500.0, 90.0),
(3, 14750.0, 45.0),
(2, 0.0, 0.0),
(3, -29500.0, -90.0),
],
)
def test_rotary_conversion_matches_the_bench(axis, user_units, expected_deg):
assert user_units_to_deg(axis, user_units) == pytest.approx(expected_deg)
assert deg_to_user_units(axis, expected_deg) == pytest.approx(user_units)
def test_units_per_degree_is_units_over_ninety():
assert units_per_degree(2) == pytest.approx(12500.0 / 90.0)
assert units_per_degree(3) == pytest.approx(29500.0 / 90.0)
def test_uncalibrated_rotary_axis_is_not_a_number():
assert math.isnan(units_per_degree(0))
assert math.isnan(user_units_to_deg(1, 1000.0))
assert math.isnan(deg_to_user_units(4, 90.0))