Skip to content

Commit 66b81e6

Browse files
feat: add angle utilities, tridiagonal solver, friction compensation, symplectic integrators and motion profiles (#355)
* feat(math): add angle utilities (wrap, shortest difference, unwrap) Deploy roadmap item 54. WrapToPi maps into (−π, π] (both ±π → +π), WrapToTwoPi into [0, 2π) with a guard so rounding never returns 2π, AngleDifference takes the short way round and UnwrapAngle turns a wrapped measurement into a continuous signal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * refactor(filters): use math::WrapToPi in ComplementaryFilter Replace the private heading wrap with the shared angle utilities. The result changes only at exactly ±π: the estimate is now reported in (−π, π], so −π maps to +π, matching the library-wide convention. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * feat(math): add tridiagonal (Thomas) solver Deploy roadmap item 59: O(n) factor-once / solve-many solver for tridiagonal systems. Factor stores reciprocal pivots so Solve has no division, and reports a pivot with |p| <= eps * scale (or a size outside [1, MaxSize]) as failure instead of dividing by it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * feat(controllers): add friction compensation feedforward Deploy roadmap item 57: per-axis Coulomb + viscous + Stribeck friction model, smoothed through zero velocity with tanh(v/eps) and clamped to maxCompensation, to be added to a torque or current command. The spec's "torque ≈ F_s near zero velocity" check is asserted against the model's exact value at v = 10·eps (0.788237): the Stribeck term has already decayed by e^-0.04 there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * feat(solvers): add symplectic integrators for second-order systems Deploy roadmap item 58: semi-implicit Euler and velocity Verlet (kick-drift-kick) over a new SecondOrderSystem interface. For a conservative plant the energy error stays bounded instead of drifting. The second-order check compares h = 0.1 with h = 0.05 rather than the spec's unspecified small step: at h = 0.01 float32 rounding already dominates the truncation error and the error ratio reads ≈ 5, not 4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * docs: align markdown tables Apply markdown-table-formatter's layout to the tables this tier adds or edits, as suggested by MegaLinter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * feat(motion_profiles): add polynomial, trapezoidal and S-curve profiles (#356) * feat(motion_profiles): add module with polynomial point-to-point profile Deploy roadmap item 55 and create the motion_profiles module with the shared TrajectoryState / MotionLimits types. PolynomialProfile solves the closed-form cubic (position + velocity) or quintic (+ acceleration) coefficients once and samples position, velocity, acceleration and jerk by Horner evaluation, with time clamped to [0, tf]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * feat(motion_profiles): add trapezoidal (LSPB) velocity profile Deploy roadmap item 56: minimum-time trapezoid / triangle plan from (vMax, aMax), plus PlanWithDuration, which keeps aMax and lowers the cruise speed so several axes can finish together. The cruise speed uses the cancellation-free conjugate form of the smaller root, and infeasible durations return nullopt. At and after tf the profile holds the goal at rest; before t = 0 it holds the start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * feat(motion_profiles): add S-curve (jerk-limited) profile Deploy roadmap item 60: seven-phase rest-to-rest profile planned with the closed-form three-step method of Biagiotti & Melchiorri §3.4 (vMax reached; else aMax reached; else neither). The boundary states are integrated once, and each sample evaluates one constant-jerk cubic. Add math::Cbrt (generic wrapper, no ARM override), which the step-3 branch needs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * docs: align markdown tables Apply markdown-table-formatter's layout to the tables this tier adds or edits, as suggested by MegaLinter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 * fix(build): build motion_profiles tests in the QEMU presets The qemu-cortex-m4/m7 build presets list their test targets explicitly, so numerical.motion_profiles_test was registered with CTest but never built, and the QEMU jobs failed with "Could not load kernel". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q53m7MZDmHwocmKbhhd2o5 --------- Co-authored-by: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c181cd1 commit 66b81e6

74 files changed

Lines changed: 2445 additions & 1455 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ resource-constrained embedded systems. Real-time, deterministic, no heap.
5353
`analysis`, `windowing`, `control_analysis`, `controllers`, `estimators`,
5454
`filters` (active Kalman family — **not** `filters::active`), `filters::passive`, `math`,
5555
`optimization`, `regularization`, `solvers`, and new:
56-
`robust_control`, `nonlinear_control`.
56+
`robust_control`, `nonlinear_control`, `motion_profiles`.
5757

5858
## Math functions
5959

‎CMakePresets.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"numerical.filters.active_test",
143143
"numerical.filters.passive_test",
144144
"numerical.math_test",
145+
"numerical.motion_profiles_test",
145146
"numerical.nonlinear_control_test",
146147
"numerical.optimization_test",
147148
"numerical.regularization_test",
@@ -164,6 +165,7 @@
164165
"numerical.filters.active_test",
165166
"numerical.filters.passive_test",
166167
"numerical.math_test",
168+
"numerical.motion_profiles_test",
167169
"numerical.nonlinear_control_test",
168170
"numerical.optimization_test",
169171
"numerical.regularization_test",

‎README.md‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ Refer to the documentation to quickly integrate and utilize the library's signal
1414

1515
## Documentation
1616

17-
| Category | Description |
18-
|--------------------------------------------------------------------|----------------------------------------------------------------------|
19-
| [Analysis](doc/analysis/README.md) | FFT, Real-Input FFT (RFFT), Power Spectral Density, DCT, Discrete Wavelet Transform (Haar/Daubechies), Window Functions, Signal Detectors, Convolution & Correlation, Goertzel Algorithm, Decibels, Hilbert Transform / Analytic Signal, Mel Filterbank / MFCC |
20-
| [Control Analysis](doc/control_analysis/README.md) | Frequency Response, Root Locus, Controllability/Observability Matrices & Gramians, Continuous-to-Discrete, Transfer Function ↔ State Space |
21-
| [Controllers](doc/controllers/README.md) | Bang-Bang/Hysteresis, Deadbeat Control, PID, LQR, LQI (Integral/Servo State Feedback), MPC, Saturation, Rate Limiter, Slew-Limited Saturation, Feedforward/2-DOF, Gain-Scheduled Controller, Lead-Lag Compensator, Luenberger Observer |
22-
| [Estimators](doc/estimators/README.md) | Linear Regression, Polynomial Fitting, Total Least Squares, Yule-Walker (offline), Recursive Least Squares, Recursive Instrumental Variables, LMS / NLMS Adaptive Filter (online), Consistency Metrics / NEES / NIS |
17+
| Category | Description |
18+
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
19+
| [Analysis](doc/analysis/README.md) | FFT, Real-Input FFT (RFFT), Power Spectral Density, DCT, Discrete Wavelet Transform (Haar/Daubechies), Window Functions, Signal Detectors, Convolution & Correlation, Goertzel Algorithm, Decibels, Hilbert Transform / Analytic Signal, Mel Filterbank / MFCC |
20+
| [Control Analysis](doc/control_analysis/README.md) | Frequency Response, Root Locus, Controllability/Observability Matrices & Gramians, Continuous-to-Discrete, Transfer Function ↔ State Space |
21+
| [Controllers](doc/controllers/README.md) | Bang-Bang/Hysteresis, Deadbeat Control, PID, LQR, LQI (Integral/Servo State Feedback), MPC, Saturation, Rate Limiter, Slew-Limited Saturation, Feedforward/2-DOF, Gain-Scheduled Controller, Lead-Lag Compensator, Luenberger Observer, Friction Compensation (Coulomb + Viscous + Stribeck) |
22+
| [Estimators](doc/estimators/README.md) | Linear Regression, Polynomial Fitting, Total Least Squares, Yule-Walker (offline), Recursive Least Squares, Recursive Instrumental Variables, LMS / NLMS Adaptive Filter (online), Consistency Metrics / NEES / NIS |
2323
| [Filters](doc/filters/README.md) | Kalman, Extended Kalman, Unscented Kalman, Square-Root Kalman, Alpha-Beta/Alpha-Beta-Gamma, FIR, IIR, Exponential Moving Average, Moving Average, Complementary, Median Filter, CIC (Cascaded Integrator-Comb), Notch/Comb Filter, Savitzky-Golay Filter, Biquad/Second-Order-Section Cascade, IIR Filter Design (Butterworth/Chebyshev-I + Bilinear Transform), Madgwick/Mahony AHRS |
24-
| [Optimization](doc/optimization/README.md) | Gradient Descent, SGD / Adam Step Optimisers |
25-
| [Regularization](doc/regularization/README.md) | L1 (Lasso), L2 (Ridge) |
26-
| [Math](doc/math/README.md) | CORDIC, Quaternion, MatrixNorms, Step Response Metrics, MatrixExponential |
27-
| [Solvers](doc/solvers/README.md) | Gaussian Elimination, Levinson-Durbin, Durand-Kerner, Cholesky, DARE, Runge-Kutta ODE Integrators (RK4 + Dormand-Prince), Spectral Radius & Discrete Stability Margin, QR Decomposition (Householder / Givens), LU Decomposition with Partial Pivoting, Singular Value Decomposition (Golub-Kahan) |
28-
| [Nonlinear Control](doc/nonlinear_control/README.md) | Feedback Linearization, Backstepping Control, Model Reference Adaptive Control (MRAC) |
29-
| [Robust Control](doc/robust_control/README.md) | Active Disturbance Rejection Control (ADRC + ESO), Sliding Mode Control (SMC), Disturbance Observer (DOB), H∞ State-Feedback Control |
30-
| [Performance Optimization](doc/performance-optimization/README.md) | Compiler optimizations |
24+
| [Optimization](doc/optimization/README.md) | Gradient Descent, SGD / Adam Step Optimisers |
25+
| [Regularization](doc/regularization/README.md) | L1 (Lasso), L2 (Ridge) |
26+
| [Math](doc/math/README.md) | CORDIC, Quaternion, MatrixNorms, Step Response Metrics, MatrixExponential, Angle Utilities, Tridiagonal (Thomas) Solver |
27+
| [Motion Profiles](doc/motion_profiles/README.md) | Polynomial (Cubic/Quintic) Point-to-Point Profile, Trapezoidal (LSPB) Profile, S-Curve (Jerk-Limited) Profile |
28+
| [Solvers](doc/solvers/README.md) | Gaussian Elimination, Levinson-Durbin, Durand-Kerner, Cholesky, DARE, Runge-Kutta ODE Integrators (RK4 + Dormand-Prince), Spectral Radius & Discrete Stability Margin, QR Decomposition (Householder / Givens), LU Decomposition with Partial Pivoting, Singular Value Decomposition (Golub-Kahan), Symplectic Integrators (Semi-Implicit Euler, Velocity Verlet) |
29+
| [Nonlinear Control](doc/nonlinear_control/README.md) | Feedback Linearization, Backstepping Control, Model Reference Adaptive Control (MRAC) |
30+
| [Robust Control](doc/robust_control/README.md) | Active Disturbance Rejection Control (ADRC + ESO), Sliding Mode Control (SMC), Disturbance Observer (DOB), H∞ State-Feedback Control |
31+
| [Performance Optimization](doc/performance-optimization/README.md) | Compiler optimizations |
3132

3233
Each category page lists its algorithms with a brief description and links to the detailed documentation.
3334

‎ROADMAP.md‎

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,7 @@ Difficulty legend:
2626

2727
| # | Component | Target module | Difficulty |
2828
|----|-------------------------------------------------------|-------------------------|------------|
29-
| 54 | Angle utilities (wrap, shortest difference, unwrap) | `math` | ★☆☆☆☆ |
30-
| 55 | Polynomial (cubic/quintic) point-to-point profile | `motion_profiles` (new) | ★☆☆☆☆ |
31-
| 56 | Trapezoidal (LSPB) profile + duration sync | `motion_profiles` (new) | ★☆☆☆☆ |
32-
| 57 | Friction compensation (Coulomb + viscous + Stribeck) | `controllers` | ★☆☆☆☆ |
33-
| 58 | Symplectic integrators (semi-implicit Euler, Verlet) | `solvers` | ★☆☆☆☆ |
34-
| 59 | Tridiagonal (Thomas) solver | `math` | ★☆☆☆☆ |
3529
| 53 | SE(3) transform, twists, wrenches, adjoint, exp/log | `math` | ★★☆☆☆ |
36-
| 60 | S-curve (jerk-limited) profile | `motion_profiles` (new) | ★★☆☆☆ |
3730
| 61 | Cubic spline interpolation (vector-valued) | `math` | ★★☆☆☆ |
3831
| 62 | Damped pseudo-inverse + null-space projector | `solvers` | ★★☆☆☆ |
3932
| 66 | SE(2) transform, twists, exp/log, pose error | `math` | ★★☆☆☆ |
@@ -58,60 +51,6 @@ unit-test reference [`TESTING.md`](TESTING.md) depends on but which
5851
the library does not yet expose. Detailed below under
5952
[Evaluation & metrics primitives](#evaluation--metrics-primitives).
6053

61-
## Tier 1 — Trivial primitives ★☆☆☆☆
62-
63-
### 54. Angle utilities
64-
- **What:** `WrapToPi` `(−π, π]`, `WrapToTwoPi` `[0, 2π)`, shortest signed `AngleDifference`, and
65-
`UnwrapAngle` for continuous signals.
66-
- **Embedded value:** One convention for every angle consumer — heading controllers, odometry, encoder
67-
unwrapping, analytical IK; replaces `ComplementaryFilter`'s private wrap.
68-
- **Algorithm / paper:** range reduction with `fmod`; D. Goldberg, *ACM Computing Surveys*, 23(1), 1991.
69-
- **Reuses:** `math::Fmod`.
70-
- **Spec:** [roadmap/math/AngleUtilities](roadmap/math/AngleUtilities/implementation.md).
71-
72-
### 55. Polynomial point-to-point profile
73-
- **What:** Cubic (position + velocity) or quintic (+ acceleration) time law between two states over a
74-
fixed duration; defines the shared `TrajectoryState` / `MotionLimits` types of `motion_profiles`.
75-
- **Embedded value:** Coefficients solved once in closed form; each servo tick is a Horner evaluation.
76-
- **Algorithm / paper:** M. Spong, S. Hutchinson, M. Vidyasagar, *Robot Modeling and Control*, Ch. 5.
77-
- **Reuses:** Scalar templates.
78-
- **Spec:** [roadmap/motion_profiles/PolynomialProfile](roadmap/motion_profiles/PolynomialProfile/implementation.md).
79-
80-
### 56. Trapezoidal (LSPB) profile
81-
- **What:** Minimum-time velocity/acceleration-limited rest-to-rest move, triangular for short moves, plus
82-
a fixed-duration plan for multi-axis synchronization.
83-
- **Embedded value:** The standard servo-axis move (robot joints, CNC, conveyors, motor position loops).
84-
- **Algorithm / paper:** L. Biagiotti, C. Melchiorri, *Trajectory Planning for Automatic Machines and
85-
Robots* (2008), Ch. 3.
86-
- **Reuses:** Item 55 types.
87-
- **Spec:** [roadmap/motion_profiles/TrapezoidalProfile](roadmap/motion_profiles/TrapezoidalProfile/implementation.md).
88-
89-
### 57. Friction compensation
90-
- **What:** Feedforward Coulomb + viscous + Stribeck friction per axis with a `tanh` zero-crossing and an
91-
output clamp.
92-
- **Embedded value:** Removes stick-slip and tracking lag in geared drives and joints for one `exp` and one
93-
`tanh` per axis.
94-
- **Algorithm / paper:** B. Armstrong-Hélouvry, P. Dupont, C. Canudas de Wit, *Automatica*, 30(7), 1994.
95-
- **Reuses:** `math::Vector`.
96-
- **Spec:** [roadmap/controllers/FrictionCompensation](roadmap/controllers/FrictionCompensation/implementation.md).
97-
98-
### 58. Symplectic integrators
99-
- **What:** Semi-implicit Euler and velocity Verlet for second-order systems `q̈ = a(q, q̇, u)`.
100-
- **Embedded value:** Bounded energy error for simulated mechanical plants at one or two evaluations per
101-
step (RK4 needs four and still drifts).
102-
- **Algorithm / paper:** E. Hairer, C. Lubich, G. Wanner, *Geometric Numerical Integration* (2006).
103-
- **Reuses:** `math::Vector`; complements `RungeKuttaIntegrators`.
104-
- **Spec:** [roadmap/solvers/SymplecticIntegrators](roadmap/solvers/SymplecticIntegrators/implementation.md).
105-
106-
### 59. Tridiagonal solver
107-
- **What:** Thomas algorithm, factor once / solve many, pivot-failure reporting.
108-
- **Embedded value:** `O(n)` instead of `O(n³)` for splines and implicit difference schemes.
109-
- **Algorithm / paper:** L. H. Thomas (1949); G. Golub, C. Van Loan, *Matrix Computations*, §4.3.
110-
- **Reuses:** Bounded `std::array` bands.
111-
- **Spec:** [roadmap/math/TridiagonalSolver](roadmap/math/TridiagonalSolver/implementation.md).
112-
113-
---
114-
11554
## Tier 2 — Easy ★★☆☆☆
11655

11756
### 53. SE(3) transform, twists and wrenches
@@ -126,13 +65,6 @@ the library does not yet expose. Detailed below under
12665
- **Reuses:** `Geometry3D` (`RotationAboutAxis`, `SkewSymmetric`), `Quaternion`.
12766
- **Spec:** [roadmap/math/SE3Transform](roadmap/math/SE3Transform/implementation.md).
12867

129-
### 60. S-curve (jerk-limited) profile
130-
- **What:** Seven-segment jerk-bounded rest-to-rest move with all short-move cases in closed form.
131-
- **Embedded value:** Continuous acceleration — far less vibration than a trapezoid for precision axes.
132-
- **Algorithm / paper:** L. Biagiotti, C. Melchiorri (2008), §3.4.
133-
- **Reuses:** Items 55 (types) and 56 (synchronization scheme).
134-
- **Spec:** [roadmap/motion_profiles/SCurveProfile](roadmap/motion_profiles/SCurveProfile/implementation.md).
135-
13668
### 61. Cubic spline interpolation
13769
- **What:** C² vector-valued spline through `K` knots, clamped or natural ends, shared factorization across
13870
channels.

0 commit comments

Comments
 (0)