smooth_feedback
Control and estimation on Lie groups
Loading...
Searching...
No Matches
Public Member Functions | List of all members
smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT > Class Template Reference

Model-Predictive Control (MPC) on Lie groups. More...

#include <mpc.hpp>

Public Member Functions

 MPC (F &&f, CR &&cr, Eigen::Vector< double, Ncr > &&crl, Eigen::Vector< double, Ncr > &&cru, MPCParams &&prm={})
 Create an MPC instance. More...
 
 MPC (const F &f, const CR &cr, const Eigen::Vector< double, Ncr > &crl, const Eigen::Vector< double, Ncr > &cru, const MPCParams &prm={})
 Same as above but for lvalues. More...
 
 MPC ()=default
 Default constructor.
 
 MPC (const MPC &)=default
 Default copy constructor.
 
 MPC (MPC &&)=default
 Default move constructor.
 
MPCoperator= (const MPC &)=default
 Default copy assignment.
 
MPCoperator= (MPC &&)=default
 Default move assignment.
 
 ~MPC ()=default
 Default destructor.
 
std::pair< U, QPSolutionStatusoperator() (const T &t, const X &x, std::optional< std::reference_wrapper< std::vector< U > > > u_traj=std::nullopt, std::optional< std::reference_wrapper< std::vector< X > > > x_traj=std::nullopt)
 Calculate new MPC input. More...
 
void set_udes (std::function< U(T)> &&u_des)
 Set the desired input trajectory (absolute time) More...
 
void set_udes (const std::function< U(T)> &u_des)
 Set the desired input trajectory (absolute time, rvalue version) More...
 
template<typename Fun >
requires (std::is_same_v<std::invoke_result_t<Fun, Scalar<U>>, U>)
void set_udes_rel (Fun &&f, T t0=T(0))
 Set the desired input trajectory (relative time). More...
 
void set_xdes (std::function< X(T)> &&x_des, std::function< Tangent< X >(T)> &&dx_des)
 Set the desired state trajectory and velocity (absolute time) More...
 
void set_xdes (const std::function< X(T)> &x_des, const std::function< Tangent< X >(T)> &dx_des)
 Set the desired state trajectory (absolute time, rvalue version) More...
 
template<typename Fun >
requires (std::is_same_v<std::invoke_result_t<Fun, Scalar<X>>, X>)
void set_xdes_rel (Fun &&f, T t0=T(0))
 Set the desired state trajectry (relative time, automatic differentiation). More...
 
void set_weights (const MPCWeights< X, U > &weights)
 Update MPC weights. More...
 
void reset_warmstart ()
 Reset initial guess for next iteration to zero. More...
 

Detailed Description

template<Time T, LieGroup X, Manifold U, typename F, typename CR, std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
class smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >

Model-Predictive Control (MPC) on Lie groups.

Template Parameters
Ttime type, must be a std::chrono::duration-like
Xstate space LieGroup type
Uinput space Manifold type
Fcallable type that represents dynamics
CRcallable type that represents running constraints
DTdifferentiation method
Kmeshnumber of collocation points per mesh interval

This MPC class keeps and repeatedly solves an internal OCP that is updated to track a time-dependent trajectory defined via set_xdes() and set_udes().

Definition at line 380 of file mpc.hpp.

Constructor & Destructor Documentation

◆ MPC() [1/2]

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::MPC ( F &&  f,
CR &&  cr,
Eigen::Vector< double, Ncr > &&  crl,
Eigen::Vector< double, Ncr > &&  cru,
MPCParams &&  prm = {} 
)
inline

Create an MPC instance.

Parameters
fcallable object that represents dynamics \( \mathrm{d}^r x_t = f(x, u) \) as a function \( f : X \times U \rightarrow \mathbb{R}^{\dim \mathfrak{g}} \).
crcallable object that represents running constraints \( c_{rl} \leq c_r(x, u) \leq c_{ru} \) as a function \( c_r : X \times U \rightarrow \mathbb{R}^{n_{c_r}} \).
crl,crurunning constraints bounds
prmMPC parameters
Note
Allocates dynamic memory for work matrices and a sparse QP.
The functions f and cr are are linearized around the desired trajectory and must therefore be instances of first-order differentiable types. For best results, cr should be (group-)linear and f locally well approximated around \( x_{des} \) by a (group-)linear function.
Todo:
Optimization: The only time-dependent parts of the QP are the dynamics and end constraints, so only those need to be updated.

Definition at line 405 of file mpc.hpp.

◆ MPC() [2/2]

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::MPC ( const F &  f,
const CR &  cr,
const Eigen::Vector< double, Ncr > &  crl,
const Eigen::Vector< double, Ncr > &  cru,
const MPCParams prm = {} 
)
inline

Same as above but for lvalues.

Definition at line 427 of file mpc.hpp.

Member Function Documentation

◆ operator()()

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
std::pair< U, QPSolutionStatus > smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::operator() ( const T &  t,
const X &  x,
std::optional< std::reference_wrapper< std::vector< U > > >  u_traj = std::nullopt,
std::optional< std::reference_wrapper< std::vector< X > > >  x_traj = std::nullopt 
)
inline

Calculate new MPC input.

Parameters
[in]tcurrent time
[in]xcurrent state
[out]u_traj(optional) return MPC input solution \( [u_0, u_1, \ldots, u_{K - 1}] \)
[out]x_traj(optional) return MPC state solution \( [x_0, x_1, \ldots, x_K] \)
Returns
{u, code}

Definition at line 458 of file mpc.hpp.

◆ reset_warmstart()

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
void smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::reset_warmstart ( )
inline

Reset initial guess for next iteration to zero.

Definition at line 603 of file mpc.hpp.

◆ set_udes() [1/2]

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
void smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::set_udes ( const std::function< U(T)> &  u_des)
inline

Set the desired input trajectory (absolute time, rvalue version)

Definition at line 529 of file mpc.hpp.

◆ set_udes() [2/2]

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
void smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::set_udes ( std::function< U(T)> &&  u_des)
inline

Set the desired input trajectory (absolute time)

Definition at line 524 of file mpc.hpp.

◆ set_udes_rel()

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
template<typename Fun >
requires (std::is_same_v<std::invoke_result_t<Fun, Scalar<U>>, U>)
void smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::set_udes_rel ( Fun &&  f,
t0 = T(0) 
)
inline

Set the desired input trajectory (relative time).

Parameters
ffunction double -> U<double> s.t. u_des(t) = f(t - t0)
t0absolute zero time for the desired trajectory

Definition at line 539 of file mpc.hpp.

◆ set_weights()

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
void smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::set_weights ( const MPCWeights< X, U > &  weights)
inline

Update MPC weights.

Definition at line 593 of file mpc.hpp.

◆ set_xdes() [1/2]

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
void smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::set_xdes ( const std::function< X(T)> &  x_des,
const std::function< Tangent< X >(T)> &  dx_des 
)
inline

Set the desired state trajectory (absolute time, rvalue version)

Definition at line 559 of file mpc.hpp.

◆ set_xdes() [2/2]

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
void smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::set_xdes ( std::function< X(T)> &&  x_des,
std::function< Tangent< X >(T)> &&  dx_des 
)
inline

Set the desired state trajectory and velocity (absolute time)

Definition at line 550 of file mpc.hpp.

◆ set_xdes_rel()

template<Time T, LieGroup X, Manifold U, typename F , typename CR , std::size_t Kmesh = 4, diff::Type DT = diff::Type::Default>
template<typename Fun >
requires (std::is_same_v<std::invoke_result_t<Fun, Scalar<X>>, X>)
void smooth::feedback::MPC< T, X, U, F, CR, Kmesh, DT >::set_xdes_rel ( Fun &&  f,
t0 = T(0) 
)
inline

Set the desired state trajectry (relative time, automatic differentiation).

Instead of providing {x(t), dx(t)} of the desired trajectory, this function differentiates a function x(t) so that the derivative does not need to be specified.

Parameters
ffunction s.t. desired trajectory is x(t) = f(t - t0)
t0absolute zero time for the desired trajectory

Definition at line 575 of file mpc.hpp.


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