Skip to content

added: custom linear inequality constraints for LinMPC and NonLinMPC#310

Open
franckgaga wants to merge 32 commits intomainfrom
custom_linconstraint
Open

added: custom linear inequality constraints for LinMPC and NonLinMPC#310
franckgaga wants to merge 32 commits intomainfrom
custom_linconstraint

Conversation

@franckgaga
Copy link
Member

@franckgaga franckgaga commented Feb 4, 2026

This PR introduces custom nonlinear inequality constraints for LinMPC and NonLinMPC objects. The constructor of both objects now accepts 4 new keyword arguments:

  • Wy=nothing : custom linear constraint matrix for output.
  • Wu=nothing : custom linear constraint matrix for manipulated input.
  • Wd=nothing : custom linear constraint matrix for meas. disturbance.
  • Wr=nothing : custom linear constraint matrix for output setpoint.

and the setconstraint! method now accept these keyword arguments:

  • wmin=fill(-Inf,nw) / wmax=fill(+Inf,nw) : custom linear constraint bound $\mathbf{w_{min/max}}$
  • c_wmin=fill(1.0,nw) / c_wmax=fill(1.0,nw) : wmin / wmax softness weight $\mathbf{c_{w_{min/max}}}$
  • the keyword arguments above but with a first capital letter, e.g. Wmax or C_wmin: for time-varying constraints

The custom nonlinear inequality constraints are defined as a linear combination of the output prediction $\mathbf{\hat{y}}$, manipulated input $\mathbf{u}$, measured disturbance prediction $\mathbf{\hat{d}}$ and setpoint prediction $\mathbf{\hat{r}_y}$, as described in the extended help section of setconstraint! :

image

I chose to incorporate the output prediction $\mathbf{\hat{y}}$ instead of state prediction $\mathbf{\hat{x}}$ in them mainly because its associated prediction matrices are already constructed and available inside LinMPC and NonLinMPC objects. This is non-limiting in practice since you can always output the states that are needed by modifying the state-space $\mathbf{C}$ and $\mathbf{D_d}$ matrices, and adjusting the i_ym argument of the state estimator if these states are not measured.

Note that C code generation is not supported for now but I will add the support in the following PR.

This is the letter that has the lowest amount of confusion. It is used in the MHE/KF but only with a hat.
It is not supported for now, I will add the support in a following PR.
The error message is clearer if the tests do not pass.
@codecov-commenter
Copy link

codecov-commenter commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 99.19355% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.33%. Comparing base (40bbb53) to head (0e7fa09).

Files with missing lines Patch % Lines
src/controller/construct.jl 99.22% 1 Missing ⚠️
src/controller/transcription.jl 98.27% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main     #310    +/-   ##
========================================
  Coverage   98.33%   98.33%            
========================================
  Files          29       29            
  Lines        5155     5295   +140     
========================================
+ Hits         5069     5207   +138     
- Misses         86       88     +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants