- 3.0.2 optimal control module.
ct::optcon::example Namespace Reference

Namespaces

 tpl
 

Classes

class  ConstraintTerm1D
 A simple example with an 1d constraint. More...
 
class  ConstraintTerm2D
 A simple example with a 2d constraint. More...
 
class  DiehlSystem
 Dynamics class for the Diehl system. More...
 
class  DiehlSystemLinear
 Linear system class for the Diehl system. More...
 
class  Dynamics
 Dynamics class for the GNMS unit test, slightly nonlinear dynamics. More...
 
class  LinearizedSystem
 Linear system class for the GNMS unit test. More...
 
class  MatFilesGenerator
 
class  MIMOIntegrator
 Dynamics class for the GNMS unit test. More...
 
class  MIMOIntegratorLinear
 Linear system class for the GNMS unit test. More...
 
class  OscDms
 
class  OscillatorDms
 
class  PureStateConstraint_Example
 A pure state constraint term. More...
 
class  SpringLoadedMass
 Dynamics class for the GNMS unit test. More...
 
class  SpringLoadedMassLinear
 Linear system class for the GNMS unit test. More...
 
class  StateInputConstraint_Example
 A state input constraint term. More...
 
class  TestTerm
 

Typedefs

typedef tpl::LinearOscillator< double > LinearOscillator
 
typedef tpl::LinearOscillatorLinear< double > LinearOscillatorLinear
 

Functions

 TEST (ConstraintComparison, comparisonAnalyticAD)
 
 TEST (pureStateConstraintTest, pureStateConstraintTest)
 
 TEST (stateInputConstraintTest, stateInputConstraintTest)
 
 TEST (AD_TEST_TIME_VAR, AD_TEST_TIME_VAR)
 
template<size_t state_dim, size_t control_dim>
void compareCostFunctionOutput (CostFunctionQuadratic< state_dim, control_dim > &costFunction, CostFunctionQuadratic< state_dim, control_dim > &costFunction2)
 This method is called from different unit tests in order to compare the cost, first and second order gradients of two cost functions. More...
 
template<size_t state_dim, size_t control_dim>
void printCostFunctionOutput (CostFunctionQuadratic< state_dim, control_dim > &costFunction, CostFunctionQuadratic< state_dim, control_dim > &costFunction2)
 
 TEST (CostFunctionTest, ADQuadraticTest)
 
 TEST (CostFunctionTest, ADQuadMultTest)
 
 TEST (CostFunctionTest, TrackingTermTest)
 
 TEST (CostFunctionTest, TermSmoothAbsTest)
 
 TEST (LoadCostFromFileTest, LoadAnalyticalDirect)
 Test case: trying to load analytical cost function directly from file. More...
 
 TEST (LoadCostFromFileTest, LoadAnalyticalViaTerms)
 Test case: trying to load analytical cost terms separately and then add them cost function. More...
 
 TEST (LoadCostFromFileTest, LoadADViaTerms)
 Test case: trying to load AD cost terms separately and then add them to the cost function. More...
 
 TEST (LoadCostFromFileTest, LoadADDirect1)
 Test case: trying to load AD cost directly, but calling standard constructor first. More...
 
 TEST (LoadCostFromFileTest, LoadADDirect2)
 Test case: trying to load AD cost directly. More...
 
 TEST (DmsTest, OscDmsTest)
 
 TEST (DmsTest, OscillatorDmsTestAllVariants)
 
 TEST (LQRTest, DARETest)
 
 TEST (LQRTest, quadTest)
 
 TEST (MPCTestA, ForwardIntegratorTest)
 
 TEST (MPCTestB, NLOC_MPC_DoublePrecision)
 
 TEST (LinearSystemsSolverComparison, LinearSystemsSolverComparison)
 
 TEST (LinearSystemsTest, NLOCSolverTest)
 
 TEST (ILQRTestA, InstancesComparison)
 
 TEST (ILQRTestB, MultiThreadingTest)
 
 TEST (ILQRTestC, PolicyComparison)
 
 TEST (NLOCTest, NonlinearSystemAlgorithmComparison)
 
std::shared_ptr< CostFunctionQuadratic< state_dim, control_dim > > createCostFunction (Eigen::Vector2d &x_final)
 Create a cost function for the GNMS unit test. More...
 
void symplecticTest ()
 
 TEST (SystemInterfaceTest, ContinuousSystemInterface)
 
 TEST (SystemInterfaceTest, DiscreteSystemInterface)
 
std::shared_ptr< CostFunctionQuadratic< 1, 1 > > createDiehlCostFunction (const core::StateVector< 1 > &x_final)
 create a cost function of appropriate Dimensions for the Diehl system More...
 
template<size_t state_dim, size_t control_dim>
std::shared_ptr< CostFunctionQuadratic< state_dim, control_dim > > createMIMOIntegratorCostFunction (const core::StateVector< state_dim > &x_final)
 
std::shared_ptr< CostFunctionQuadratic< 2, 1 > > createSpringLoadedMassCostFunction (const core::StateVector< 2 > &x_final)
 

Variables

const bool verbose = true
 
const size_t state_dim = 3
 
const size_t control_dim = 3
 
const double kStiffness = 1
 

Typedef Documentation

◆ LinearOscillator

◆ LinearOscillatorLinear

Function Documentation

◆ TEST() [1/27]

ct::optcon::example::TEST ( ConstraintComparison  ,
comparisonAnalyticAD   
)

◆ TEST() [2/27]

ct::optcon::example::TEST ( pureStateConstraintTest  ,
pureStateConstraintTest   
)

References i.

◆ TEST() [3/27]

ct::optcon::example::TEST ( stateInputConstraintTest  ,
stateInputConstraintTest   
)

◆ TEST() [4/27]

ct::optcon::example::TEST ( AD_TEST_TIME_VAR  ,
AD_TEST_TIME_VAR   
)

References t, u, and x.

◆ compareCostFunctionOutput()

template<size_t state_dim, size_t control_dim>
void ct::optcon::example::compareCostFunctionOutput ( CostFunctionQuadratic< state_dim, control_dim > &  costFunction,
CostFunctionQuadratic< state_dim, control_dim > &  costFunction2 
)

◆ printCostFunctionOutput()

◆ TEST() [5/27]

◆ TEST() [6/27]

◆ TEST() [7/27]

ct::optcon::example::TEST ( CostFunctionTest  ,
TrackingTermTest   
)

◆ TEST() [8/27]

ct::optcon::example::TEST ( CostFunctionTest  ,
TermSmoothAbsTest   
)

Test the TermSmoothAbs term for first and second order derivatives

References compareCostFunctionOutput(), control_dim, i, state_dim, t, u, and x.

◆ TEST() [9/27]

ct::optcon::example::TEST ( LoadCostFromFileTest  ,
LoadAnalyticalDirect   
)

Test case: trying to load analytical cost function directly from file.

References costFunctionFile, t, and verbose.

◆ TEST() [10/27]

ct::optcon::example::TEST ( LoadCostFromFileTest  ,
LoadAnalyticalViaTerms   
)

Test case: trying to load analytical cost terms separately and then add them cost function.

References costFunctionFile, t, and verbose.

◆ TEST() [11/27]

ct::optcon::example::TEST ( LoadCostFromFileTest  ,
LoadADViaTerms   
)

Test case: trying to load AD cost terms separately and then add them to the cost function.

References costFunctionFile, t, and verbose.

◆ TEST() [12/27]

ct::optcon::example::TEST ( LoadCostFromFileTest  ,
LoadADDirect1   
)

Test case: trying to load AD cost directly, but calling standard constructor first.

References costFunctionFile, t, and verbose.

◆ TEST() [13/27]

ct::optcon::example::TEST ( LoadCostFromFileTest  ,
LoadADDirect2   
)

Test case: trying to load AD cost directly.

References costFunctionFile, t, and verbose.

◆ TEST() [14/27]

◆ TEST() [15/27]

◆ TEST() [16/27]

ct::optcon::example::TEST ( LQRTest  ,
DARETest   
)

◆ TEST() [17/27]

ct::optcon::example::TEST ( LQRTest  ,
quadTest   
)

◆ TEST() [18/27]

ct::optcon::example::TEST ( MPCTestA  ,
ForwardIntegratorTest   
)

Test the MPC forward integrator

required for this test

Run the first MPC cycle, in which the pre-integrator should not be active at all. after one mpc cycle the solution must still be the same (time horizon unchanged, state unchanged)

Test the forward integration scheme employing a 'custom controller'. In this test,

  • we select the custom controller to be equal to the previously optimized policy
  • we integrate systematically across shifting time intervals
  • the integrated solutions need to match the original trajectories with numerical accuracy.
Warning
This test is only reasonnable for dt_sim = 1, and is generally problematic since the solver's forward integration is implemented step-wise.

References ct::optcon::NLOptConSettings::computeK(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::configure(), ct::optcon::NLOptConSettings::discretization, ct::optcon::MPC< OPTCON_SOLVER >::doForwardIntegration(), ct::optcon::NLOptConSettings::dt, ct::optcon::MPC< OPTCON_SOLVER >::finishIteration(), ct::core::StateFeedbackController< STATE_DIM, CONTROL_DIM, SCALAR >::getFeedforwardTrajectory(), ct::core::StateFeedbackController< STATE_DIM, CONTROL_DIM, SCALAR >::getReferenceStateTrajectory(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::getSolution(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::getStateTrajectory(), i, ct::optcon::NLOptConSettings::integrator, ct::optcon::NLOptConSettings::K_sim, ct::optcon::NLOptConSettings::lqocp_solver, ct::optcon::NLOptConSettings::max_iterations, ct::optcon::NLOptConSettings::nlocp_algorithm, ct::optcon::mpc_settings::postTruncation_, ct::optcon::MPC< OPTCON_SOLVER >::prepareIteration(), ct::optcon::NLOptConSettings::printSummary, ct::optcon::MPC< OPTCON_SOLVER >::setInitialGuess(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::setInitialGuess(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::solve(), ct::optcon::mpc_settings::stateForwardIntegration_, ct::optcon::mpc_settings::stateForwardIntegration_dt_, ct::optcon::mpc_settings::stateForwardIntegratorType_, t, timeHorizon, ct::core::StateFeedbackController< STATE_DIM, CONTROL_DIM, SCALAR >::uff(), and x0.

◆ TEST() [19/27]

ct::optcon::example::TEST ( MPCTestB  ,
NLOC_MPC_DoublePrecision   
)

References ct::optcon::mpc_settings::additionalDelayUs_, ct::optcon::mpc_settings::coldStart_, ct::optcon::NLOptConSettings::computeK(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::configure(), ct::optcon::NLOptConSettings::debugPrint, ct::optcon::mpc_settings::delayMeasurementMultiplier_, ct::optcon::NLOptConSettings::discretization, ct::optcon::NLOptConSettings::dt, ct::core::DiscreteTrajectoryBase< T, Alloc, SCALAR >::eval(), ct::optcon::MPC< OPTCON_SOLVER >::finishIteration(), ct::optcon::FIXED_FINAL_TIME, ct::optcon::mpc_settings::fixedDelayUs_, ct::core::DiscreteTrajectoryBase< T, Alloc, SCALAR >::front(), ct::core::StateFeedbackController< STATE_DIM, CONTROL_DIM, SCALAR >::getReferenceStateTrajectory(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::getSolution(), i, ct::optcon::NLOptConSettings::integrator, ct::optcon::NLOptConSettings::K_shot, ct::optcon::NLOptConSettings::K_sim, ct::optcon::NLOptConSettings::lineSearchSettings, ct::optcon::NLOptConSettings::lqocp_solver, ct::optcon::NLOptConSettings::max_iterations, ct::optcon::mpc_settings::measureDelay_, ct::optcon::NLOptConSettings::min_cost_improvement, ct::optcon::mpc_settings::mpc_mode, ct::optcon::NLOptConSettings::nlocp_algorithm, ct::optcon::NLOptConSettings::nThreads, ct::optcon::NLOptConSettings::nThreadsEigen, ct::optcon::mpc_settings::postTruncation_, ct::optcon::MPC< OPTCON_SOLVER >::prepareIteration(), ct::optcon::MPC< OPTCON_SOLVER >::printMpcSummary(), ct::optcon::NLOptConSettings::printSummary, ct::optcon::MPC< OPTCON_SOLVER >::setInitialGuess(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::setInitialGuess(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::solve(), ct::optcon::mpc_settings::stateForwardIntegration_, ct::optcon::mpc_settings::stateForwardIntegration_dt_, ct::optcon::mpc_settings::stateForwardIntegratorType_, t, timeHorizon, ct::optcon::MPC< OPTCON_SOLVER >::timeHorizonReached(), ct::optcon::LineSearchSettings::type, ct::optcon::mpc_settings::useExternalTiming_, and x0.

◆ TEST() [20/27]

ct::optcon::example::TEST ( LinearSystemsSolverComparison  ,
LinearSystemsSolverComparison   
)

This unit test considers a variety of different solver/algorithm options for NLOC, and explicitly compares HPIPM and GNRiccati solvers against each other.

run two iterations to solve LQ problem

run two iterations to solve LQ problem

retrieve summaries

check that all logs from both solvers are identical

References ct::optcon::NLOptConSettings::computeK(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::configure(), control_dim, SummaryAllIterations< SCALAR >::defect_l1_norms, SummaryAllIterations< SCALAR >::defect_l2_norms, ct::optcon::NLOptConSettings::discretization, ct::optcon::NLOptConSettings::dt, ct::optcon::NLOptConSettings::epsilon, ct::optcon::NLOptConSettings::fixedHessianCorrection, ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::getBackend(), ct::optcon::NLOptConSettings::integrator, ct::optcon::NLOptConSettings::K_shot, ct::optcon::NLOptConSettings::K_sim, kStiffness, ct::optcon::NLOptConSettings::lineSearchSettings, ct::optcon::NLOptConSettings::lqocp_solver, SummaryAllIterations< SCALAR >::lu_norms, SummaryAllIterations< SCALAR >::lx_norms, SummaryAllIterations< SCALAR >::merits, ct::optcon::NLOptConSettings::nlocp_algorithm, ct::optcon::NLOptConSettings::nThreads, ct::optcon::NLOptConSettings::printSummary, ct::optcon::NLOptConSettings::recordSmallestEigenvalue, ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::runIteration(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::setInitialGuess(), state_dim, ct::optcon::LineSearchSettings::type, ct::optcon::NLOptConSettings::useSensitivityIntegrator, and x0.

◆ TEST() [21/27]

ct::optcon::example::TEST ( LinearSystemsTest  ,
NLOCSolverTest   
)

run two iterations to solve LQ problem

retrieve summary of the optimization

check that the policy improved in the first iteration

check that we are converged after the first iteration

References ct::optcon::NLOptConSettings::computeK(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::configure(), control_dim, SummaryAllIterations< SCALAR >::defect_l1_norms, SummaryAllIterations< SCALAR >::defect_l2_norms, ct::optcon::NLOptConSettings::discretization, ct::optcon::NLOptConSettings::dt, ct::optcon::NLOptConSettings::epsilon, ct::optcon::NLOptConSettings::fixedHessianCorrection, ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::getBackend(), ct::optcon::NLOptConSettings::integrator, ct::optcon::NLOptConSettings::K_shot, ct::optcon::NLOptConSettings::K_sim, kStiffness, ct::optcon::NLOptConSettings::lineSearchSettings, ct::optcon::NLOptConSettings::lqocp_solver, SummaryAllIterations< SCALAR >::lu_norms, SummaryAllIterations< SCALAR >::lx_norms, ct::optcon::NLOptConSettings::nlocp_algorithm, ct::optcon::NLOptConSettings::nThreads, ct::optcon::NLOptConSettings::printSummary, ct::optcon::NLOptConSettings::recordSmallestEigenvalue, ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::runIteration(), ct::optcon::NLOptConSolver< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS >::setInitialGuess(), state_dim, ct::optcon::LineSearchSettings::type, ct::optcon::NLOptConSettings::useSensitivityIntegrator, and x0.

◆ TEST() [22/27]

◆ TEST() [23/27]

◆ TEST() [24/27]

ct::optcon::example::TEST ( ILQRTestC  ,
PolicyComparison   
)

◆ TEST() [25/27]

◆ createCostFunction()

std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim> > ct::optcon::example::createCostFunction ( Eigen::Vector2d &  x_final)

Create a cost function for the GNMS unit test.

Examples:
SymplecticTest.h.

Referenced by symplecticTest().

◆ symplecticTest()

◆ TEST() [26/27]

◆ TEST() [27/27]

ct::optcon::example::TEST ( SystemInterfaceTest  ,
DiscreteSystemInterface   
)

◆ createDiehlCostFunction()

std::shared_ptr<CostFunctionQuadratic<1, 1> > ct::optcon::example::createDiehlCostFunction ( const core::StateVector< 1 > &  x_final)

create a cost function of appropriate Dimensions for the Diehl system

◆ createMIMOIntegratorCostFunction()

template<size_t state_dim, size_t control_dim>
std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim> > ct::optcon::example::createMIMOIntegratorCostFunction ( const core::StateVector< state_dim > &  x_final)

◆ createSpringLoadedMassCostFunction()

std::shared_ptr<CostFunctionQuadratic<2, 1> > ct::optcon::example::createSpringLoadedMassCostFunction ( const core::StateVector< 2 > &  x_final)

Referenced by TEST().

Variable Documentation

◆ verbose

◆ state_dim

◆ control_dim

◆ kStiffness