Skip to content

[AUD-007][High] Preserve reference tracking in precomputed MPC #306

Description

@gabrielsantosphilips

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

  • The precomputed API accepts all matrices required for supported reference tracking, or reference tracking is explicitly unavailable.
  • Online and precomputed controllers produce matching control for nonzero state and reference.
  • Add a parity TEST_F combining the precomputed constructor with SetReference().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions