- 3.0.2 optimal control module.
|
#include <MPC.h>
Public Types | |
using | Scalar_t = typename OPTCON_SOLVER::Scalar_t |
using | Policy_t = typename OPTCON_SOLVER::Policy_t |
using | OptConProblem_t = ContinuousOptConProblem< STATE_DIM, CONTROL_DIM, Scalar_t > |
Public Member Functions | |
MPC (const OptConProblem_t &problem, const typename OPTCON_SOLVER::Settings_t &solverSettings, const mpc_settings &mpcsettings=mpc_settings(), std::shared_ptr< PolicyHandler< Policy_t, STATE_DIM, CONTROL_DIM, Scalar_t >> customPolicyHandler=nullptr, std::shared_ptr< tpl::MpcTimeHorizon< Scalar_t >> customTimeHorizon=nullptr) | |
MPC solver constructor. More... | |
OPTCON_SOLVER & | getSolver () |
Allows access to the solver member, required mainly for unit testing. More... | |
void | setTimeHorizonStrategy (std::shared_ptr< tpl::MpcTimeHorizon< Scalar_t >> timeHorizonStrategy) |
Additional method to insert a custom time horizon strategy, independent from the constructor. More... | |
void | setInitialGuess (const Policy_t &initGuess) |
set a new initial guess for the policy More... | |
bool | timeHorizonReached () |
Check if final time horizon for this task was reached. More... | |
const Scalar_t | timeSinceFirstSuccessfulSolve (const Scalar_t &extTime) |
retrieve the time that elapsed since the first successful solve() call to an Optimal Control Problem More... | |
void | doForwardIntegration (const Scalar_t &t_forward_start, const Scalar_t &t_forward_stop, core::StateVector< STATE_DIM, Scalar_t > &x_start, const std::shared_ptr< core::Controller< STATE_DIM, CONTROL_DIM, Scalar_t >> forwardIntegrationController=nullptr) |
perform forward integration of the measured system state, to compensate for expected or already occurred time lags More... | |
void | prepareIteration (const Scalar_t &ext_ts) |
bool | finishIteration (const core::StateVector< STATE_DIM, Scalar_t > &x, const Scalar_t x_ts, Policy_t &newPolicy, Scalar_t &newPolicy_ts, const std::shared_ptr< core::Controller< STATE_DIM, CONTROL_DIM, Scalar_t >> forwardIntegrationController=nullptr) |
finish MPC iteration More... | |
void | resetMpc (const Scalar_t &newTimeHorizon) |
reset the mpc problem and provide new problem time horizon (mandatory) More... | |
void | updateSettings (const mpc_settings &settings) |
update the mpc settings in all instances (main class, time keeper class, etc) More... | |
void | printMpcSummary () |
printout simple statistical data More... | |
Static Public Attributes | |
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW const size_t | STATE_DIM = OPTCON_SOLVER::STATE_D |
static const size_t | CONTROL_DIM = OPTCON_SOLVER::CONTROL_D |
static const size_t | P_DIM = OPTCON_SOLVER::POS_DIM |
static const size_t | V_DIM = OPTCON_SOLVER::VEL_DIM |
Main MPC class.
This MPC class allows to use any solver that derives from the OptConSolver base class in Model-Predictive-Control fashion. MPC will automatically construct the solver
Main assumptions: This MPC class is deliberately designed such that the time-keeping is managed by itself. The main assumption is that the controller which is designed here, gets applied to the system instantaneously after the run() call is executed. Furthermore, we assume that all Optimal Control Problems start at time zero. This also applies to the cost- and the constraint functionals which are to be provided by the user.
Sidenotes: between the calls to run(), the user can arbitrarily modify his cost-functions, etc. in order to change the problem.
OPTCON_SOLVER | the optimal control solver to be employed, for example SLQ or DMS |
using ct::optcon::MPC< OPTCON_SOLVER >::Scalar_t = typename OPTCON_SOLVER::Scalar_t |
using ct::optcon::MPC< OPTCON_SOLVER >::Policy_t = typename OPTCON_SOLVER::Policy_t |
using ct::optcon::MPC< OPTCON_SOLVER >::OptConProblem_t = ContinuousOptConProblem<STATE_DIM, CONTROL_DIM, Scalar_t> |
ct::optcon::MPC< OPTCON_SOLVER >::MPC | ( | const OptConProblem_t & | problem, |
const typename OPTCON_SOLVER::Settings_t & | solverSettings, | ||
const mpc_settings & | mpcsettings = mpc_settings() , |
||
std::shared_ptr< PolicyHandler< Policy_t, STATE_DIM, CONTROL_DIM, Scalar_t >> | customPolicyHandler = nullptr , |
||
std::shared_ptr< tpl::MpcTimeHorizon< Scalar_t >> | customTimeHorizon = nullptr |
||
) |
MPC solver constructor.
problem | the optimal control problem set up by the user |
solverSettings | settings class/struct for the optimal control solver of choice. Be sure to tune the solver settings such that they are suitable for MPC! |
mpcsettings | mpc-specific settings, see class MpcSettings.h |
customPolicyHandler | user-provided custom policy handler, which derives from base class 'PolicyHandler'. If not specified, MPC will use one of its default implementations or throw an error if there is no default match. |
customTimeHorizon | user-provided custom time horizon strategy, which derives from base class 'MpcTimeHorizon'. If not specified, MPC will use one of its default implementations or throw an error if there is no default match. |
References ct::optcon::mpc_settings::coldStart_.
OPTCON_SOLVER & ct::optcon::MPC< OPTCON_SOLVER >::getSolver | ( | ) |
Allows access to the solver member, required mainly for unit testing.
void ct::optcon::MPC< OPTCON_SOLVER >::setTimeHorizonStrategy | ( | std::shared_ptr< tpl::MpcTimeHorizon< Scalar_t >> | timeHorizonStrategy | ) |
Additional method to insert a custom time horizon strategy, independent from the constructor.
timeHorizonStrategy | the time horizon strategy provided by the user |
void ct::optcon::MPC< OPTCON_SOLVER >::setInitialGuess | ( | const Policy_t & | initGuess | ) |
set a new initial guess for the policy
initGuess |
Referenced by main(), and ct::optcon::example::TEST().
bool ct::optcon::MPC< OPTCON_SOLVER >::timeHorizonReached | ( | ) |
Check if final time horizon for this task was reached.
References ct::optcon::tpl::MpcTimeKeeper< SCALAR >::finalPointReached().
Referenced by main(), and ct::optcon::example::TEST().
const MPC< OPTCON_SOLVER >::Scalar_t ct::optcon::MPC< OPTCON_SOLVER >::timeSinceFirstSuccessfulSolve | ( | const Scalar_t & | extTime | ) |
retrieve the time that elapsed since the first successful solve() call to an Optimal Control Problem
the | external time stamp |
References ct::optcon::tpl::MpcTimeKeeper< SCALAR >::timeSinceFirstSuccessfulSolve().
void ct::optcon::MPC< OPTCON_SOLVER >::doForwardIntegration | ( | const Scalar_t & | t_forward_start, |
const Scalar_t & | t_forward_stop, | ||
core::StateVector< STATE_DIM, Scalar_t > & | x_start, | ||
const std::shared_ptr< core::Controller< STATE_DIM, CONTROL_DIM, Scalar_t >> | forwardIntegrationController = nullptr |
||
) |
perform forward integration of the measured system state, to compensate for expected or already occurred time lags
State forward integration
t_forward_start | time where forward integration starts |
t_forward_stop | time where forward integration stops |
x_start | initial state for forward integration, gets overwritten with forward-integrated state |
forwardIntegrationController | (optional) external controller for forward integration |
References ct::optcon::mpc_settings::stateForwardIntegration_.
Referenced by ct::optcon::MPC< OPTCON_SOLVER >::finishIteration(), and ct::optcon::example::TEST().
void ct::optcon::MPC< OPTCON_SOLVER >::prepareIteration | ( | const Scalar_t & | ext_ts | ) |
Prepare MPC iteration
ext_ts | the current external time |
re-initialize the OptConSolver and solve the optimal control problem.
References ct::optcon::tpl::MpcTimeKeeper< SCALAR >::computeNewTimings(), and ct::optcon::tpl::MpcTimeKeeper< SCALAR >::initialize().
Referenced by main(), and ct::optcon::example::TEST().
bool ct::optcon::MPC< OPTCON_SOLVER >::finishIteration | ( | const core::StateVector< STATE_DIM, Scalar_t > & | x, |
const Scalar_t | x_ts, | ||
Policy_t & | newPolicy, | ||
Scalar_t & | newPolicy_ts, | ||
const std::shared_ptr< core::Controller< STATE_DIM, CONTROL_DIM, Scalar_t >> | forwardIntegrationController = nullptr |
||
) |
finish MPC iteration
x | current system state |
x_ts | time stamp of the current state (external time in seconds) |
newPolicy | the new policy calculated based on above state, the timing info and the underlying OptConProblem |
newPolicy_ts | time stamp of the resulting policy. This indicates when the policy is supposed to start being applied, relative to the user-provided state-timestamp x_ts. |
forwardIntegrationController | optional input: in some scenarios, we wish to use a different kind controller for forward integrating the system than the one we are optimizing Such a controller can be handed over here as additional argument. If set to empty, MPC uses its own optimized controller from the last iteration, thus assuming perfect control trajectory tracking. |
References ct::optcon::MPC< OPTCON_SOLVER >::doForwardIntegration(), ct::optcon::tpl::MpcTimeKeeper< SCALAR >::getMeasuredDelay(), ct::optcon::mpc_settings::postTruncation_, ct::optcon::tpl::MpcTimeKeeper< SCALAR >::startDelayMeasurement(), ct::optcon::tpl::MpcTimeKeeper< SCALAR >::stopDelayMeasurement(), ct::optcon::tpl::MpcTimeKeeper< SCALAR >::timeSincePreviousSuccessfulSolve(), and x.
Referenced by main(), and ct::optcon::example::TEST().
void ct::optcon::MPC< OPTCON_SOLVER >::resetMpc | ( | const Scalar_t & | newTimeHorizon | ) |
reset the mpc problem and provide new problem time horizon (mandatory)
References ct::optcon::tpl::MpcTimeKeeper< SCALAR >::initialize().
void ct::optcon::MPC< OPTCON_SOLVER >::updateSettings | ( | const mpc_settings & | settings | ) |
update the mpc settings in all instances (main class, time keeper class, etc)
update the mpc settings in all instances
settings | the new mpc settings provided by the user. |
References ct::optcon::mpc_settings::stateForwardIntegratorType_, and ct::optcon::tpl::MpcTimeKeeper< SCALAR >::updateSettings().
void ct::optcon::MPC< OPTCON_SOLVER >::printMpcSummary | ( | ) |
printout simple statistical data
References ct::optcon::mpc_settings::fixedDelayUs_, ct::optcon::tpl::MpcTimeKeeper< SCALAR >::getMaxMeasuredDelay(), ct::optcon::tpl::MpcTimeKeeper< SCALAR >::getMinMeasuredDelay(), ct::optcon::tpl::MpcTimeKeeper< SCALAR >::getSummedDelay(), ct::core::Integrator< STATE_DIM, SCALAR >::integrate_n_steps(), ct::optcon::mpc_settings::measureDelay_, ct::optcon::mpc_settings::stateForwardIntegration_dt_, and ct::optcon::mpc_settings::useExternalTiming_.
Referenced by main(), and ct::optcon::example::TEST().
|
static |
|
static |
|
static |
|
static |