nicolapiccinelli / libmpc

libmpc++ is a C++ header-only library to solve linear and non-linear MPC
https://altairlab.gitlab.io/optcontrol/libmpc/
MIT License
138 stars 21 forks source link

Future variables for NLMPC #8

Closed Veng97 closed 1 year ago

Veng97 commented 1 year ago

For my task i need to be able to specify online parameters in some way within the model itself. Specifically i need the ability to set the curvature for a cross-track-error model. This requires adding an additional horizon variable, e.g:

auto stateEq = [&](mpc::cvec<Tnx>& dx,
                   mpc::cvec<Tnx> x,
                   mpc::cvec<Tnu> u,
                  mpc::cvec<Tnv> v) {
...
};

The new variable, v, can be used for online parameter settings along the entire prediction horizon. This would also allow updating parameters with online estimates of disturbances or model parameters.

nicolapiccinelli commented 1 year ago

Hello @Veng97 and happy new year, sorry but I just saw your request! However, this is something that is currently not available, but for further expansion, it could be possible to provide the index of the current horizon step as a parameter of the function handle.

In this way, you can refer to any disturbance or parameter needed. IMO with respect to the LMPC in this case we don't need to clearly defined disturbances, references, parameters etc. I would say, it's something that must be delegated to the implementation of the lambdas.

Something like that:

auto stateEq = [&](
                    mpc::cvec<TVAR(num_states)>& dx,
                    mpc::cvec<TVAR(num_states)> x,
                    mpc::cvec<TVAR(num_inputs)> u, size_t p) {
    dx(0) = ((1.0 - (x(1) * x(1))) * x(0)) - x(1) + u(0);
    dx(1) = x(0);
};

where p is the horizon step.

nicolapiccinelli commented 1 year ago

The solution mentioned above will be available in the next release, cheers!

nicolapiccinelli commented 1 year ago

See release 0.2.0