simple_casadi_mpc
GitHub
Loading...
Searching...
No Matches
simple_casadi_mpc::JITMPC Class Reference

MPC variant that JIT-compiles the solver during construction. More...

#include <simple_casadi_mpc.hpp>

Inheritance diagram for simple_casadi_mpc::JITMPC:
simple_casadi_mpc::MPC

Public Member Functions

template<class T >
 JITMPC (const std::string &prob_name, std::shared_ptr< T > prob, std::string solver_name="ipopt", casadi::Dict config=MPC::default_ipopt_config(), casadi::Dict jit_options=JITMPC::default_jit_options(), const bool verbose=false)
 Build the NLP and JIT-compile its solver in one step.
 
Eigen::VectorXd solve (Eigen::VectorXd x0, casadi::DMDict new_param_list=casadi::DMDict()) override
 Solve the NLP at the current state and return the first optimal control.
 
- Public Member Functions inherited from simple_casadi_mpc::MPC
template<class T >
 MPC (std::shared_ptr< T > prob, std::string solver_name="ipopt", casadi::Dict config=default_ipopt_config())
 Build the NLP from prob and create the underlying nlpsol.
 
casadi::MXDict casadi_prob () const
 Symbolic NLP description {x, f, g, p} constructed from the Problem.
 
const std::string & solver_name () const
 Backend name passed to CasADi nlpsol.
 
casadi::Dict solver_config () const
 Effective config forwarded to nlpsol (after consuming simple-casadi-mpc keys).
 
std::vector< casadi_int > equality_flags () const
 Per-constraint flags marking equality (true) vs inequality (false).
 

Static Public Member Functions

static casadi::Dict default_jit_options ()
 Default JIT compile options (compiler / flags / verbose) passed to CasADi.
 
- Static Public Member Functions inherited from simple_casadi_mpc::MPC
static casadi::Dict default_ipopt_config ()
 Reasonable defaults for the IPOPT backend (silent, warm-start enabled).
 
static casadi::Dict default_qpoases_config ()
 Reasonable defaults for SQP method with the qpOASES inner QP solver.
 
static casadi::Dict default_fatrop_config ()
 Reasonable defaults for the FATROP backend (auto structure detection).
 
static bool equality_required (const std::string &solver_name, const casadi::Dict &config)
 Whether the chosen backend needs an equality flag vector in the config.
 

Additional Inherited Members

- Protected Member Functions inherited from simple_casadi_mpc::MPC
void build_with_map (size_t nx, size_t nu, casadi_int N, bool mapsum_stage_cost=true, bool expand_inner_functions=true)
 
- Protected Attributes inherited from simple_casadi_mpc::MPC
std::shared_ptr< Problemprob_
 
std::string solver_name_
 
casadi::Dict config_
 
casadi::MXDict casadi_prob_
 
casadi::Function solver_
 
std::vector< casadi::MX > Xs = {}
 
std::vector< casadi::MX > Us = {}
 
casadi::DM lbw_
 
casadi::DM ubw_
 
casadi::DM lbg_
 
casadi::DM ubg_
 
std::vector< casadi::DM > param_vec_ = {}
 
std::vector< bool > equality_ = {}
 
casadi::DM w0_
 
casadi::DM lam_x0_
 
casadi::DM lam_g0_
 

Detailed Description

MPC variant that JIT-compiles the solver during construction.

Pays a one-time compile cost (cache it with ccache via default_jit_options()) in exchange for substantially faster per-iteration solve time. Behaves like MPC otherwise.

Constructor & Destructor Documentation

◆ JITMPC()

template<class T >
simple_casadi_mpc::JITMPC::JITMPC ( const std::string & prob_name,
std::shared_ptr< T > prob,
std::string solver_name = "ipopt",
casadi::Dict config = MPC::default_ipopt_config(),
casadi::Dict jit_options = JITMPC::default_jit_options(),
const bool verbose = false )
inline

Build the NLP and JIT-compile its solver in one step.

Parameters
prob_nameunique identifier embedded in the JIT artifact name.
probthe Problem to solve.
solver_nameCasADi nlpsol backend name.
confignlpsol options (same semantics as MPC::MPC).
jit_optionsinner CasADi jit_options dict; see default_jit_options.
verboseif true, print progress to stdout while compiling.

Member Function Documentation

◆ default_jit_options()

static casadi::Dict simple_casadi_mpc::JITMPC::default_jit_options ( )
inlinestatic

Default JIT compile options (compiler / flags / verbose) passed to CasADi.

The defaults are ccache gcc, -O3 -march=native, verbose=false. Override individual entries before passing the dict to the constructor:

opts["compiler"] = "clang";
opts["flags"] = "-O2";
JITMPC mpc("my_prob", prob, "ipopt", config, opts);
MPC variant that JIT-compiles the solver during construction.
Definition simple_casadi_mpc.hpp:1012
static casadi::Dict default_jit_options()
Default JIT compile options (compiler / flags / verbose) passed to CasADi.
Definition simple_casadi_mpc.hpp:1024

◆ solve()

Eigen::VectorXd simple_casadi_mpc::JITMPC::solve ( Eigen::VectorXd x0,
casadi::DMDict new_param_list = casadi::DMDict() )
inlineoverridevirtual

Solve the NLP at the current state and return the first optimal control.

Warm-starts from the previous solve (x, lam_x, lam_g are cached internally), so calling this repeatedly during closed-loop simulation benefits from incremental convergence.

Parameters
x0current measured state, shape (nx,).
new_param_listupdates to parameters declared via Problem::parameter. Keys are parameter names; values are casadi::DM of matching shape.
Returns
optimal control to apply now, u_0, shape (nu,).

Reimplemented from simple_casadi_mpc::MPC.


The documentation for this class was generated from the following file: