From c62d3a14727f51f6ed2c6fe369aa615c8302a0e0 Mon Sep 17 00:00:00 2001 From: David Vo Date: Wed, 16 Jul 2025 00:33:45 +1000 Subject: [PATCH 1/5] wpimath: Fix semiwrap error (new in semiwrap 0.1.3) --- .../robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml b/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml index 3d70fcebe..adaef7e8a 100644 --- a/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml +++ b/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml @@ -77,7 +77,8 @@ classes: maxAcceleration_: name: maxAcceleration default: '0' - template_inline_code: | + inline_code: | + ; { std::string clsNameCopy = clsName; From e11ee6ec4584f7d7889bd54097669c9f59f1d8b8 Mon Sep 17 00:00:00 2001 From: David Vo Date: Wed, 16 Jul 2025 01:14:03 +1000 Subject: [PATCH 2/5] Fix TrapezoidProfile::Constraints constructor param defaults --- .../robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml b/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml index adaef7e8a..407900aac 100644 --- a/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml +++ b/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml @@ -71,11 +71,9 @@ classes: ignore: true Velocity_t, Acceleration_t: param_override: - maxVelocity_: - name: maxVelocity + maxVelocity: default: '0' - maxAcceleration_: - name: maxAcceleration + maxAcceleration: default: '0' inline_code: | ; From 91a2ad59a3e1ace430a5df6608c9f0285d589b0a Mon Sep 17 00:00:00 2001 From: David Vo Date: Wed, 16 Jul 2025 01:14:36 +1000 Subject: [PATCH 3/5] Add tests for TrapezoidProfile.Constraints --- .../tests/test_trapezoid_profile.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py diff --git a/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py b/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py new file mode 100644 index 000000000..5cfbb5220 --- /dev/null +++ b/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py @@ -0,0 +1,16 @@ +import pytest + +from wpimath import trajectory + +trapezoid_profile_types = [ + trajectory.TrapezoidProfile, + trajectory.TrapezoidProfileRadians, +] + + +@pytest.mark.parametrize("TrapezoidProfile", trapezoid_profile_types) +def test_constraints_repr(TrapezoidProfile): + expected_qualname = f"{TrapezoidProfile.__name__}.Constraints" + constraints = TrapezoidProfile.Constraints() + + assert repr(constraints).startswith(f"{expected_qualname}(maxVelocity=0.") From e52c8eae51ca60d3379c70986750090fa67aa472 Mon Sep 17 00:00:00 2001 From: David Vo Date: Wed, 16 Jul 2025 01:17:44 +1000 Subject: [PATCH 4/5] Add test for TrapezoidProfile.State repr --- .../robotpy-wpimath/tests/test_trapezoid_profile.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py b/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py index 5cfbb5220..e28c55c95 100644 --- a/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py +++ b/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py @@ -14,3 +14,11 @@ def test_constraints_repr(TrapezoidProfile): constraints = TrapezoidProfile.Constraints() assert repr(constraints).startswith(f"{expected_qualname}(maxVelocity=0.") + + +@pytest.mark.parametrize("TrapezoidProfile", trapezoid_profile_types) +def test_state_repr(TrapezoidProfile): + expected_qualname = f"{TrapezoidProfile.__name__}.State" + constraints = TrapezoidProfile.State() + + assert repr(constraints).startswith(f"{expected_qualname}(position=0.") From 320d480f2da728256c3ff76f74a761b2210735b6 Mon Sep 17 00:00:00 2001 From: David Vo Date: Wed, 16 Jul 2025 01:21:09 +1000 Subject: [PATCH 5/5] Copy the TrapezoidProfile class name only once --- .../semiwrap/controls/TrapezoidProfile.yml | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml b/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml index 407900aac..0796f4da1 100644 --- a/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml +++ b/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml @@ -48,6 +48,13 @@ classes: { std::string clsNameCopy = clsName; + cls_Constraints + .def("__repr__", [clsNameCopy](const Constraints &self) { + return clsNameCopy + ".Constraints(" + "maxVelocity=" + std::to_string(self.maxVelocity()) + ", " + "maxAcceleration=" + std::to_string(self.maxAcceleration()) + ")"; + }); + cls_State .def( py::init(), @@ -75,18 +82,6 @@ classes: default: '0' maxAcceleration: default: '0' - inline_code: | - ; - { - std::string clsNameCopy = clsName; - - cls_Constraints - .def("__repr__", [clsNameCopy](const Constraints &self) { - return clsNameCopy + ".Constraints(" - "maxVelocity=" + std::to_string(self.maxVelocity()) + ", " - "maxAcceleration=" + std::to_string(self.maxAcceleration()) + ")"; - }); - } frc::TrapezoidProfile::State: force_no_default_constructor: true attributes: