- 3.0.2 optimal control module.
ct::optcon::MPC< OPTCON_SOLVER > Class Template Reference

Main MPC class. More...

#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
 

Detailed Description

template<typename OPTCON_SOLVER>
class ct::optcon::MPC< OPTCON_SOLVER >

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.

    Parameters
    OPTCON_SOLVERthe optimal control solver to be employed, for example SLQ or DMS
Examples:
NLOC_MPC.cpp.

Member Typedef Documentation

◆ Scalar_t

template<typename OPTCON_SOLVER>
using ct::optcon::MPC< OPTCON_SOLVER >::Scalar_t = typename OPTCON_SOLVER::Scalar_t

◆ Policy_t

template<typename OPTCON_SOLVER>
using ct::optcon::MPC< OPTCON_SOLVER >::Policy_t = typename OPTCON_SOLVER::Policy_t

◆ OptConProblem_t

template<typename OPTCON_SOLVER>
using ct::optcon::MPC< OPTCON_SOLVER >::OptConProblem_t = ContinuousOptConProblem<STATE_DIM, CONTROL_DIM, Scalar_t>

Constructor & Destructor Documentation

◆ MPC()

template<typename OPTCON_SOLVER >
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.

Parameters
problemthe optimal control problem set up by the user
solverSettingssettings class/struct for the optimal control solver of choice. Be sure to tune the solver settings such that they are suitable for MPC!
mpcsettingsmpc-specific settings, see class MpcSettings.h
customPolicyHandleruser-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.
customTimeHorizonuser-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_.

Member Function Documentation

◆ getSolver()

template<typename OPTCON_SOLVER >
OPTCON_SOLVER & ct::optcon::MPC< OPTCON_SOLVER >::getSolver ( )

Allows access to the solver member, required mainly for unit testing.

Returns
reference to the optimal control problem solver

◆ setTimeHorizonStrategy()

template<typename OPTCON_SOLVER >
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.

Parameters
timeHorizonStrategythe time horizon strategy provided by the user

◆ setInitialGuess()

template<typename OPTCON_SOLVER >
void ct::optcon::MPC< OPTCON_SOLVER >::setInitialGuess ( const Policy_t initGuess)

set a new initial guess for the policy

Parameters
initGuess

Referenced by main(), and ct::optcon::example::TEST().

◆ timeHorizonReached()

template<typename OPTCON_SOLVER >
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().

◆ timeSinceFirstSuccessfulSolve()

template<typename OPTCON_SOLVER >
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

Parameters
theexternal time stamp
Returns
time elapsed, the returned time can be used externally, for example to update cost functions

References ct::optcon::tpl::MpcTimeKeeper< SCALAR >::timeSinceFirstSuccessfulSolve().

◆ doForwardIntegration()

template<typename OPTCON_SOLVER >
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

Parameters
t_forward_starttime where forward integration starts
t_forward_stoptime where forward integration stops
x_startinitial state for forward integration, gets overwritten with forward-integrated state
forwardIntegrationController(optional) external controller for forward integration
Warning
The effect of the integration will vanish one the MPC frequency is higher than the sampling frequency

References ct::optcon::mpc_settings::stateForwardIntegration_.

Referenced by ct::optcon::MPC< OPTCON_SOLVER >::finishIteration(), and ct::optcon::example::TEST().

◆ prepareIteration()

template<typename OPTCON_SOLVER >
void ct::optcon::MPC< OPTCON_SOLVER >::prepareIteration ( const Scalar_t ext_ts)

Prepare MPC iteration

Parameters
ext_tsthe 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().

◆ finishIteration()

template<typename OPTCON_SOLVER >
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

Parameters
xcurrent system state
x_tstime stamp of the current state (external time in seconds)
newPolicythe new policy calculated based on above state, the timing info and the underlying OptConProblem
newPolicy_tstime 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.
forwardIntegrationControlleroptional 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.
Returns
true if solve was successful, false otherwise.

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().

◆ resetMpc()

template<typename OPTCON_SOLVER >
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().

◆ updateSettings()

template<typename OPTCON_SOLVER >
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

Parameters
settingsthe new mpc settings provided by the user.

References ct::optcon::mpc_settings::stateForwardIntegratorType_, and ct::optcon::tpl::MpcTimeKeeper< SCALAR >::updateSettings().

◆ printMpcSummary()

Member Data Documentation

◆ STATE_DIM

template<typename OPTCON_SOLVER>
EIGEN_MAKE_ALIGNED_OPERATOR_NEW const size_t ct::optcon::MPC< OPTCON_SOLVER >::STATE_DIM = OPTCON_SOLVER::STATE_D
static

◆ CONTROL_DIM

template<typename OPTCON_SOLVER>
const size_t ct::optcon::MPC< OPTCON_SOLVER >::CONTROL_DIM = OPTCON_SOLVER::CONTROL_D
static

◆ P_DIM

template<typename OPTCON_SOLVER>
const size_t ct::optcon::MPC< OPTCON_SOLVER >::P_DIM = OPTCON_SOLVER::POS_DIM
static

◆ V_DIM

template<typename OPTCON_SOLVER>
const size_t ct::optcon::MPC< OPTCON_SOLVER >::V_DIM = OPTCON_SOLVER::VEL_DIM
static

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