Audit finding
- ID:
AUD-007
- Status: Verified defect
- Severity: High
- Confidence: High
- Audited revision:
2f479320d805a1f9f35ebe4afaaeeded48913a94
Problem
The precomputed MPC constructor accepts only H and F; referenceGainMatrix remains zero. SetReference() is still available and ComputeControl() uses that zero matrix.
Source:
|
template<typename T, std::size_t StateSize, std::size_t InputSize, std::size_t PredictionHorizon, std::size_t ControlHorizon> |
|
Mpc<T, StateSize, InputSize, PredictionHorizon, ControlHorizon>::Mpc( |
|
const HessianMatrix& precomputedH, const GradientMatrix& precomputedF, |
|
const MpcConstraints<T, InputSize>& constraints) |
|
: hessian(precomputedH) |
|
, gradientMatrix(precomputedF) |
|
, constraints(constraints) |
|
{} |
|
|
and
|
typename Mpc<T, StateSize, InputSize, PredictionHorizon, ControlHorizon>::InputVector |
|
Mpc<T, StateSize, InputSize, PredictionHorizon, ControlHorizon>::ComputeControl(const StateVector& state) |
|
{ |
|
auto g = gradientMatrix * state; |
|
if (reference) |
|
g = g - referenceGainMatrix * (*reference); |
|
auto negG = g * T(-1.0f); |
|
|
|
auto uOptimal = solvers::SolveSystem<T, TotalControlDim, 1>(hessian, negG); |
|
ApplyConstraints(uOptimal, negG); |
|
|
|
for (std::size_t k = 0; k < ControlHorizon; ++k) |
Reproduction
At zero state with reference (3,0), an online MPC returned 16.6369629; a precomputed instance built from that MPC's H and F returned zero.
Acceptance criteria
Audit finding
AUD-0072f479320d805a1f9f35ebe4afaaeeded48913a94Problem
The precomputed MPC constructor accepts only
HandF;referenceGainMatrixremains zero.SetReference()is still available andComputeControl()uses that zero matrix.Source:
numerical-toolbox-cpp/numerical/controllers/implementations/Mpc.hpp
Lines 108 to 116 in 2f47932
numerical-toolbox-cpp/numerical/controllers/implementations/Mpc.hpp
Lines 228 to 239 in 2f47932
Reproduction
At zero state with reference
(3,0), an online MPC returned16.6369629; a precomputed instance built from that MPC'sHandFreturned zero.Acceptance criteria
TEST_Fcombining the precomputed constructor withSetReference().