diff --git a/README.md b/README.md index f5ab85d8..a7c1b96e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Refer to the documentation to quickly integrate and utilize the library's signal |--------------------------------------------------------------------|----------------------------------------------------------------------| | [Analysis](doc/analysis/README.md) | FFT, Power Spectral Density, DCT, Window Functions, Signal Detectors | | [Control Analysis](doc/control_analysis/README.md) | Frequency Response, Root Locus | -| [Controllers](doc/controllers/README.md) | Bang-Bang/Hysteresis, PID, LQR, MPC, Saturation, Rate Limiter, Slew-Limited Saturation | +| [Controllers](doc/controllers/README.md) | Bang-Bang/Hysteresis, PID, LQR, MPC, Saturation, Rate Limiter, Slew-Limited Saturation, Feedforward/2-DOF | | [Dynamics](doc/dynamics/README.md) | Euler-Lagrange, Newton-Euler, Recursive Newton-Euler, ABA | | [Estimators](doc/estimators/README.md) | Linear Regression, Yule-Walker (offline), Recursive Least Squares (online) | | [Filters](doc/filters/README.md) | Kalman, Extended Kalman, Unscented Kalman, FIR, IIR, Exponential Moving Average, Moving Average, Median Filter | diff --git a/ROADMAP.md b/ROADMAP.md index 5d83f72c..6314a0e0 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -27,7 +27,6 @@ Difficulty legend: | # | Component | Target module | Difficulty | |----|------------------------------------------------------|---------------------------|------------| -| 7 | Feedforward / 2-DOF controller | `controllers` | ★★☆☆☆ | | 8 | Alpha-beta / alpha-beta-gamma filter | `filters/active` | ★★☆☆☆ | | 9 | Complementary filter | `filters/active` | ★★☆☆☆ | | 10 | Gain-scheduled controller | `controllers` | ★★☆☆☆ | @@ -101,12 +100,6 @@ Difficulty legend: ## Tier 2 — Easy ★★☆☆☆ -### 7. Feedforward / 2-DOF controller -- **What:** Adds a reference/disturbance feedforward path to an existing feedback loop (two-degree-of-freedom structure). -- **Embedded value:** Improves tracking and disturbance rejection without sacrificing feedback stability margins. -- **Algorithm / paper:** Åström & Murray, *Feedback Systems*, Ch. 12 (Feedforward and 2-DOF design). -- **Reuses:** Existing controller interfaces; composable wrapper. - ### 8. Alpha-beta / alpha-beta-gamma filter - **What:** Fixed-gain steady-state tracker for position/velocity(/acceleration) states. - **Embedded value:** Delivers most of the benefit of a Kalman filter at a fraction of the cost — no online covariance propagation. diff --git a/doc/controllers/Feedforward2Dof.md b/doc/controllers/Feedforward2Dof.md new file mode 100644 index 00000000..e6eea376 --- /dev/null +++ b/doc/controllers/Feedforward2Dof.md @@ -0,0 +1,83 @@ +# Feedforward / 2-DOF Controller + +## Overview & Motivation + +A single feedback loop must balance two competing demands: fast reference tracking and robust rejection of disturbances. Tightening the feedback gains for faster tracking reduces stability margins; relaxing them for robustness slows the response. The two-degree-of-freedom (2-DOF) structure resolves this conflict by separating the two tasks into independent paths. A feedforward path shapes how the output follows the reference, while the feedback path corrects errors and rejects disturbances. Because the feedforward term is open-loop, it can be tuned for tracking without affecting the closed-loop stability margins at all. + +## Mathematical Theory + +### Signal Flow + +Let $r$ be the reference, $y$ the plant output, and $u$ the actuator command. The 2-DOF law is: + +$$u = \text{sat}\!\left(u_{ff}(r) + u_{fb}(r - y),\; u_{min},\; u_{max}\right)$$ + +where: +- $u_{ff}(r)$ is the feedforward map evaluated on the reference alone (open-loop), +- $u_{fb}(e) = u_{fb}(r - y)$ is the feedback law driven by the tracking error, +- $\text{sat}(\cdot)$ clips the combined command to the actuator range $[u_{min}, u_{max}]$. + +### Feedforward Design + +The ideal feedforward is an inverse of the plant model. For a linear plant $P(z)$, the ideal map is $u_{ff}(r) = P^{-1}(z)\, r$, yielding perfect steady-state tracking. A simpler approximation is a scalar gain $K_{ff}$ tuned to match the DC plant gain: $u_{ff}(r) = K_{ff} \cdot r$. Non-minimum-phase plants require a causal approximation since the exact inverse is non-causal. + +### Feedback Design (Independence) + +The closed-loop characteristic equation depends only on the feedback law and the plant; $u_{ff}$ does not appear in it. Stability margins, bandwidth, and disturbance rejection are therefore set entirely by $u_{fb}$. This decoupling is the defining property of the 2-DOF structure. + +### Saturation + +The output clamp $\text{sat}(u, u_{min}, u_{max})$ acts on the combined command to protect the actuator. When the sum saturates, both the feedforward and feedback contributions are implicitly reduced. + +## Complexity Analysis + +| Case | Time | Space | Notes | +|---------|--------|--------|----------------------------------------------| +| Best | $O(1)$ | $O(1)$ | Wrapper adds one addition and one clamp | +| Average | $O(1)$ | $O(1)$ | Cost dominated by the injected components | +| Worst | $O(1)$ | $O(1)$ | State lives entirely inside injected objects | + +## Step-by-Step Walkthrough + +Given $r = 0.5$, $y = 0.1$, feedforward gain $K_{ff} = 0.6$, and a proportional feedback with gain $K_p = 0.5$, clamped to $[-1, 1]$: + +1. $u_{ff} = K_{ff} \cdot r = 0.6 \times 0.5 = 0.3$ +2. $e = r - y = 0.5 - 0.1 = 0.4$ +3. $u_{fb} = K_p \cdot e = 0.5 \times 0.4 = 0.2$ +4. $u_{raw} = u_{ff} + u_{fb} = 0.3 + 0.2 = 0.5$ +5. $u = \text{sat}(0.5, -1, 1) = 0.5$ + +If the system were already tracking perfectly ($y = r = 0.5$), then $e = 0$, $u_{fb} = 0$, and the feedforward alone supplies the command: $u = K_{ff} \cdot 0.5 = 0.3$. + +## Pitfalls & Edge Cases + +- **Saturation interacts with both terms.** When the actuator saturates, the feedback integrator (if used) can wind up. Anti-windup logic in the feedback law is recommended. +- **Feedforward does not aid disturbance rejection.** If $u_{ff}$ is tuned for tracking and a disturbance enters the plant, only $u_{fb}$ responds. +- **Inverse-plant feedforward for non-minimum-phase systems** is non-causal; use a truncated or approximate inverse. +- **Sign convention.** The error passed to feedback is $r - y$, not $y - r$. Swapping signs destabilises positive-gain plants. + +## Variants & Generalizations + +- **Gain-only feedforward:** $u_{ff} = K_{ff} \cdot r$ — the simplest form, requiring only a scalar. +- **Filter-based feedforward:** a low-pass or derivative filter applied to $r$ before multiplication; smooths the command for actuators with bandwidth limits. +- **Inverse-plant feedforward:** uses a model of the plant to produce the exact command required; maximises tracking performance at the cost of model accuracy sensitivity. +- **Model-reference 2-DOF:** the feedforward block is an explicit reference model; the feedback corrects deviations from the model response rather than from the raw reference. + +## Applications + +- Motion control: hitting aggressive position or velocity trajectories while maintaining stability against load disturbances. +- Process control: tracking ramp set-points in temperature or flow loops where a simple P or PI controller lags behind. +- Robotics: feed-forward gravity/inertia compensation combined with joint-level PD feedback. +- Power electronics: duty-cycle feedforward in DC-DC converters to cancel input voltage disturbances before the voltage-mode feedback acts. + +## Connections to Other Algorithms + +- **PID / PidIncremental** is a natural choice for the injected feedback law. The incremental (velocity) form avoids integrator wind-up issues at start-up. +- **SaturationRateLimiter** can replace or augment the output clamp to add slew-rate limiting on the command. +- **Gain-scheduled controller** extends the 2-DOF concept by varying feedforward and feedback gains across operating points. +- **LQR / LQG** provides an optimal state-feedback law for the feedback path; the feedforward term then handles reference shaping independently. + +## References & Further Reading + +- K. J. Åström and R. M. Murray, *Feedback Systems: An Introduction for Scientists and Engineers*, Princeton University Press, 2008, Ch. 12 (Feedforward and 2-DOF Design). +- G. F. Franklin, J. D. Powell, and A. Emami-Naeini, *Feedback Control of Dynamic Systems*, 8th ed., Pearson, 2019, Ch. 4. diff --git a/doc/controllers/README.md b/doc/controllers/README.md index 06a446b0..408b740a 100644 --- a/doc/controllers/README.md +++ b/doc/controllers/README.md @@ -12,3 +12,4 @@ Feedback control algorithms for regulating dynamic systems in real time. | [LQG Controller](Lqg.md) | Linear Quadratic Gaussian — output-feedback optimal control via LQR + Kalman Filter | | [MPC Controller](Mpc.md) | Model Predictive Controller — receding-horizon optimal control with constraint handling | | [Linear Time-Invariant Model](LinearTimeInvariant.md) | Discrete-time state-space plant model (A, B, C, D) shared across controllers and filters | +| [Feedforward / 2-DOF Controller](Feedforward2Dof.md) | Feedforward + feedback wrapper for decoupled reference tracking and disturbance rejection | diff --git a/numerical/controllers/implementations/CMakeLists.txt b/numerical/controllers/implementations/CMakeLists.txt index 6d303f8b..6068d607 100644 --- a/numerical/controllers/implementations/CMakeLists.txt +++ b/numerical/controllers/implementations/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(numerical.controllers.implementations ${NUMERICAL_VISIBILI target_sources(numerical.controllers.implementations PRIVATE BangBangHysteresis.hpp + Feedforward2Dof.hpp Lqg.hpp Lqr.hpp Mpc.hpp @@ -22,6 +23,7 @@ target_sources(numerical.controllers.implementations PRIVATE numerical_add_coverage_sources(numerical.controllers.implementations BangBangHysteresis.cpp + Feedforward2Dof.cpp Lqg.cpp Lqr.cpp Mpc.cpp diff --git a/numerical/controllers/implementations/Feedforward2Dof.cpp b/numerical/controllers/implementations/Feedforward2Dof.cpp new file mode 100644 index 00000000..619d2f8f --- /dev/null +++ b/numerical/controllers/implementations/Feedforward2Dof.cpp @@ -0,0 +1,6 @@ +#include "numerical/controllers/implementations/Feedforward2Dof.hpp" + +namespace controllers +{ + template class Feedforward2Dof; +} diff --git a/numerical/controllers/implementations/Feedforward2Dof.hpp b/numerical/controllers/implementations/Feedforward2Dof.hpp new file mode 100644 index 00000000..1e9d7c7e --- /dev/null +++ b/numerical/controllers/implementations/Feedforward2Dof.hpp @@ -0,0 +1,77 @@ +#pragma once + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC optimize("O3", "fast-math") +#endif + +#include "numerical/controllers/implementations/SaturationRateLimiter.hpp" +#include "numerical/math/CompilerOptimizations.hpp" +#include + +namespace controllers +{ + template + class Feedforward + { + public: + static_assert(std::is_floating_point_v, "Feedforward supports floating-point types"); + + virtual ~Feedforward() = default; + virtual T Evaluate(T reference) const = 0; + }; + + template + class FeedbackLaw + { + public: + static_assert(std::is_floating_point_v, "FeedbackLaw supports floating-point types"); + + virtual ~FeedbackLaw() = default; + virtual T Process(T error) = 0; + virtual void Reset() = 0; + }; + + template + class Feedforward2Dof + { + public: + static_assert(std::is_floating_point_v, "Feedforward2Dof supports floating-point types"); + + Feedforward2Dof(Feedforward& ff, FeedbackLaw& fb, Saturation clamp); + + OPTIMIZE_FOR_SPEED T Compute(T reference, T measurement); + void Reset(); + + private: + Feedforward& feedforward; + FeedbackLaw& feedback; + Saturation outputClamp; + }; + + template + Feedforward2Dof::Feedforward2Dof(Feedforward& ff, FeedbackLaw& fb, Saturation clamp) + : feedforward{ ff } + , feedback{ fb } + , outputClamp{ clamp } + { + } + + template + OPTIMIZE_FOR_SPEED T Feedforward2Dof::Compute(T reference, T measurement) + { + T uFeedforward{ feedforward.Evaluate(reference) }; + T error{ reference - measurement }; + T uFeedback{ feedback.Process(error) }; + return outputClamp.Clamp(uFeedforward + uFeedback); + } + + template + void Feedforward2Dof::Reset() + { + feedback.Reset(); + } + +#ifdef NUMERICAL_TOOLBOX_COVERAGE_BUILD + extern template class Feedforward2Dof; +#endif +} diff --git a/numerical/controllers/implementations/test/CMakeLists.txt b/numerical/controllers/implementations/test/CMakeLists.txt index ff2ece7c..67646f43 100644 --- a/numerical/controllers/implementations/test/CMakeLists.txt +++ b/numerical/controllers/implementations/test/CMakeLists.txt @@ -10,6 +10,7 @@ target_link_libraries(numerical.controllers_test PUBLIC target_sources(numerical.controllers_test PRIVATE TestBangBangHysteresis.cpp + TestFeedforward2Dof.cpp TestLqg.cpp TestLqr.cpp TestMpc.cpp diff --git a/numerical/controllers/implementations/test/TestFeedforward2Dof.cpp b/numerical/controllers/implementations/test/TestFeedforward2Dof.cpp new file mode 100644 index 00000000..11966479 --- /dev/null +++ b/numerical/controllers/implementations/test/TestFeedforward2Dof.cpp @@ -0,0 +1,105 @@ +#include "numerical/controllers/implementations/Feedforward2Dof.hpp" +#include "numerical/math/Tolerance.hpp" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace +{ + class MockFeedforward + : public controllers::Feedforward + { + public: + MOCK_METHOD(float, Evaluate, (float), (const, override)); + }; + + class MockFeedbackLaw + : public controllers::FeedbackLaw + { + public: + MOCK_METHOD(float, Process, (float), (override)); + MOCK_METHOD(void, Reset, (), (override)); + }; + + class TestFeedforward2Dof + : public ::testing::Test + { + public: + testing::StrictMock ff; + testing::StrictMock fb; + controllers::Saturation clamp{ -1.0f, 1.0f }; + controllers::Feedforward2Dof controller{ ff, fb, clamp }; + }; +} + +TEST_F(TestFeedforward2Dof, sums_feedforward_and_feedback) +{ + EXPECT_CALL(ff, Evaluate(0.5f)).WillOnce(testing::Return(0.3f)); + EXPECT_CALL(fb, Process(0.4f)).WillOnce(testing::Return(0.2f)); + + float result{ controller.Compute(0.5f, 0.1f) }; + + EXPECT_NEAR(result, 0.5f, math::Tolerance()); +} + +TEST_F(TestFeedforward2Dof, passes_correct_error_to_feedback) +{ + EXPECT_CALL(ff, Evaluate(0.4f)).WillOnce(testing::Return(0.0f)); + EXPECT_CALL(fb, Process(0.3f)).WillOnce(testing::Return(0.3f)); + + controller.Compute(0.4f, 0.1f); +} + +TEST_F(TestFeedforward2Dof, passes_reference_to_feedforward) +{ + EXPECT_CALL(ff, Evaluate(0.6f)).WillOnce(testing::Return(0.0f)); + EXPECT_CALL(fb, Process(testing::_)).WillOnce(testing::Return(0.0f)); + + controller.Compute(0.6f, 0.0f); +} + +TEST_F(TestFeedforward2Dof, zero_feedforward_reduces_to_feedback) +{ + EXPECT_CALL(ff, Evaluate(testing::_)).WillOnce(testing::Return(0.0f)); + EXPECT_CALL(fb, Process(testing::_)).WillOnce(testing::Return(0.4f)); + + float result{ controller.Compute(0.5f, 0.1f) }; + + EXPECT_NEAR(result, 0.4f, math::Tolerance()); +} + +TEST_F(TestFeedforward2Dof, output_is_clamped) +{ + EXPECT_CALL(ff, Evaluate(testing::_)).WillOnce(testing::Return(0.9f)); + EXPECT_CALL(fb, Process(testing::_)).WillOnce(testing::Return(0.9f)); + + float result{ controller.Compute(1.0f, 0.0f) }; + + EXPECT_NEAR(result, 1.0f, math::Tolerance()); +} + +TEST_F(TestFeedforward2Dof, perfect_feedforward_zero_error) +{ + EXPECT_CALL(ff, Evaluate(0.7f)).WillOnce(testing::Return(0.7f)); + EXPECT_CALL(fb, Process(0.0f)).WillOnce(testing::Return(0.0f)); + + float result{ controller.Compute(0.7f, 0.7f) }; + + EXPECT_NEAR(result, 0.7f, math::Tolerance()); +} + +TEST_F(TestFeedforward2Dof, reset_delegates_to_feedback) +{ + EXPECT_CALL(fb, Reset()).Times(1); + + controller.Reset(); +} + +TEST_F(TestFeedforward2Dof, negative_reference_handled) +{ + EXPECT_CALL(ff, Evaluate(-0.3f)).WillOnce(testing::Return(-0.2f)); + EXPECT_CALL(fb, Process(testing::_)).WillOnce(testing::Return(-0.1f)); + + float result{ controller.Compute(-0.3f, 0.0f) }; + + EXPECT_NEAR(result, -0.3f, math::Tolerance()); +} diff --git a/roadmap/controllers/Feedforward2Dof/explanation.md b/roadmap/controllers/Feedforward2Dof/explanation.md deleted file mode 100644 index 146fd543..00000000 --- a/roadmap/controllers/Feedforward2Dof/explanation.md +++ /dev/null @@ -1,30 +0,0 @@ -# Feedforward / 2-DOF Controller — Overview - -## What it is -A wrapper that adds a **feedforward path** alongside an existing feedback controller, creating a -two-degree-of-freedom (2-DOF) structure. One "degree" (feedforward) shapes how the system follows -the reference; the other (feedback) rejects errors and disturbances. - -## Why it matters (embedded) -A single feedback loop must compromise between fast reference tracking and robust disturbance -rejection — pushing one degrades the other. The feedforward term is open-loop, so it improves -tracking **without touching the feedback gains or stability margins**. This is how motion -controllers hit aggressive trajectories while staying stable. - -## How it works (intuition) -The feedforward block predicts the command needed to follow the reference (ideally an -inverse-plant model, or just a gain). The feedback block then only has to correct the small -residual error. Because the two paths add, they can be designed and tuned independently: pick the -feedback for stability/robustness first, then add feedforward for tracking performance. - -## Key parameters -- **feedforward map** — reference-to-command model (gain, filter, or inverse plant), injected. -- **feedback law** — the existing error-driven controller (e.g. PID), injected. -- **output clamp** — actuator saturation applied to the combined command. - -## Reference -K. J. Åström, R. M. Murray, *Feedback Systems* (2008), Ch. 12 (feedforward and 2-DOF design). - -## See also -`PidIncremental` (a typical injected feedback law); `SaturationRateLimiter` (the output clamp); -`GainScheduledController` (varying the feedforward/feedback across operating points). diff --git a/roadmap/controllers/Feedforward2Dof/implementation.md b/roadmap/controllers/Feedforward2Dof/implementation.md deleted file mode 100644 index ca483716..00000000 --- a/roadmap/controllers/Feedforward2Dof/implementation.md +++ /dev/null @@ -1,70 +0,0 @@ -# Feedforward / 2-DOF Controller — Implementation Pseudocode - -> Roadmap ref: #7 (Tier 2) · Target: `numerical/controllers` · Namespace `controllers` · Type: `float` (templated on `T`, instantiated for `float` only) - -## Data structures - -``` -template -interface Feedforward: # injected map r -> u_ff - T Evaluate(T reference) const - -template -interface FeedbackLaw: # injected e -> u_fb - T Process(T error) - -template # static_assert(std::is_floating_point_v); instantiated for float -class Feedforward2Dof: - Feedforward& feedforward # constructor-injected - FeedbackLaw& feedback # constructor-injected - Saturation outputClamp # actuator bound on the summed command -``` - -## Interface - -``` -Feedforward2Dof(Feedforward& ff, FeedbackLaw& fb, Saturation clamp) -T Compute(T reference, T measurement) # hot path -void Reset() -``` - -## Algorithm (pseudocode) - -``` -function Compute(r, y): # OPTIMIZE_FOR_SPEED - # Two degrees of freedom: shape response (ff) and reject error (fb) - uFeedforward = feedforward.Evaluate(r) # model-based, open-loop term - error = r - y - uFeedback = feedback.Process(error) # closed-loop correction - return outputClamp.Clamp(uFeedforward + uFeedback) -``` - -## Complexity & memory - -- Time: `O(1)` in the wrapper, plus the cost of the injected feedforward and feedback blocks. -- Memory: `O(1)` in the wrapper; all state lives inside the injected components. - -## Numerical / embedded notes - -- **Dependency inversion:** the wrapper owns neither the feedforward map nor the feedback law — - both arrive by reference (constructor injection), so any `Feedforward`/`FeedbackLaw` - implementation composes without edits (Open/Closed). -- The feedforward term is open-loop: it does not affect loop stability margins, so it can be tuned - for tracking independently of the feedback tuning. -- A static/gain feedforward (`u_ff = Kff·r`) is the trivial `Feedforward` implementation; an - inverse-plant model is the high-performance one. -- Float-only: `static_assert(std::is_floating_point_v)`; the generic `T` signature keeps a - `Q15`/`Q31` specialisation cheap to add later. - -## Deployment - -- Header: `numerical/controllers/implementations/Feedforward2Dof.hpp` — `#pragma once` → - `#pragma GCC optimize("O3","fast-math")`, `OPTIMIZE_FOR_SPEED` on `Compute`, and - `extern template class Feedforward2Dof;` under `#ifdef NUMERICAL_TOOLBOX_COVERAGE_BUILD`. -- Coverage: `numerical/controllers/implementations/Feedforward2Dof.cpp` → - `template class Feedforward2Dof;` -- Test: `numerical/controllers/implementations/test/TestFeedforward2Dof.cpp` -- Doc: `doc/controllers/Feedforward2Dof.md` (expand to follow `doc/TEMPLATE.md`) -- CMake: `.hpp` → `target_sources`; `.cpp` → `numerical_add_coverage_sources`; - `TestFeedforward2Dof.cpp` → the `_test` target. -- Generic pattern: see `roadmap/DEPLOYMENT.md`. diff --git a/roadmap/controllers/Feedforward2Dof/tests.md b/roadmap/controllers/Feedforward2Dof/tests.md deleted file mode 100644 index 8035e2f9..00000000 --- a/roadmap/controllers/Feedforward2Dof/tests.md +++ /dev/null @@ -1,67 +0,0 @@ -# Feedforward / 2-DOF Controller — Unit Test Plan (Pseudocode) - -> GoogleTest · `TEST_F` (`float`) · `StrictMock` only · no heap. - -## Fixture - -``` -class MockFeedforward : public Feedforward: - MOCK_METHOD(float, Evaluate, (float), (const, override)) - -class MockFeedbackLaw : public FeedbackLaw: - MOCK_METHOD(float, Process, (float), (override)) - -class TestFeedforward2Dof : public ::testing::Test: - StrictMock ff - StrictMock fb - Saturation clamp{ -1.0f, 1.0f } - Feedforward2Dof controller{ ff, fb, clamp } -# each case below is a TEST_F(TestFeedforward2Dof, ) -``` - -## Test cases (Arrange / Act / Assert) - -``` -sums_feedforward_and_feedback: - Arrange: EXPECT ff.Evaluate(r) -> 0.3, fb.Process(r-y) -> 0.2 - Act: Compute(r=0.5, y=0.1) - Assert: result ≈ 0.5 - -passes_correct_error_to_feedback: - Arrange: r = 0.4, y = 0.1 - Assert: fb.Process called with 0.3 (= r - y) - -passes_reference_to_feedforward: - Arrange: r = 0.6 - Assert: ff.Evaluate called with 0.6 (the reference, not the error) - -zero_feedforward_reduces_to_feedback: - Arrange: ff.Evaluate -> 0 - Assert: output equals the feedback term alone - -output_is_clamped: - Arrange: ff -> 0.9, fb -> 0.9 (sum 1.8), clamp [-1,1] - Assert: result == 1.0 - -perfect_feedforward_zero_error: - Arrange: y == r so error 0, fb.Process(0) -> 0, ff -> u* - Assert: output == u* (feedforward carries the command) - -reset_delegates_to_feedback: - Arrange: Reset() - Assert: feedback state cleared (next error processed fresh) - -negative_reference_handled: - Arrange: r = -0.3, ff -> -0.2, fb -> -0.1 - Assert: result ≈ -0.3 -``` - -## Reference vectors - -- `u = Kff·r + fb(r−y)`; with `Kff = 0` the 2-DOF law collapses to pure feedback. -- With an exact inverse-plant feedforward and `y = r`, feedback contributes zero. - -## Edge cases - -- Saturation acts on the summed command (not on each term separately). -- StrictMock verifies feedforward sees `r` while feedback sees `r − y` (no argument mix-up).