8 #include <gtest/gtest.h> 29 using std::shared_ptr;
54 vDot(0) = control(0) - kStiffness * p(0) * p(0);
66 state_control_matrix_t B_;
71 const double t = 0.0)
override 79 const double t = 0.0)
override 89 std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim>>
createCostFunction(Eigen::Vector2d& x_final)
94 Eigen::Matrix<double, 1, 1> R;
97 Eigen::Vector2d x_nominal = Eigen::Vector2d::Zero();
98 Eigen::Matrix<double, 1, 1> u_nominal = Eigen::Matrix<double, 1, 1>::Zero();
100 Eigen::Matrix2d Q_final;
101 Q_final << 10, 0, 0, 10;
103 std::shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> quadraticCostFunction(
106 return quadraticCostFunction;
112 std::cout <<
"setting up problem " << std::endl;
116 Eigen::Vector2d x_final;
126 gnms_settings.
dt = 0.05;
127 gnms_settings.
K_sim = 50;
129 gnms_settings.
integrator = ct::core::IntegrationType::EULER_SYM;
132 gnms_settings.
nlocp_algorithm = NLOptConSettings::NLOCP_ALGORITHM::GNMS;
133 gnms_settings.
lqocp_solver = NLOptConSettings::LQOCP_SOLVER::GNRICCATI_SOLVER;
140 ilqr_settings.
nlocp_algorithm = NLOptConSettings::NLOCP_ALGORITHM::ILQR;
144 shared_ptr<ControlledSystem<state_dim, control_dim>> nonlinearSystem(
new Dynamics);
145 shared_ptr<LinearSystem<state_dim, control_dim>> analyticLinearSystem(
new LinearizedSystem);
146 shared_ptr<CostFunctionQuadratic<state_dim, control_dim>> costFunction =
createCostFunction(x_final);
150 size_t nSteps = std::round(tf / gnms_settings.
dt);
157 uff << kStiffness * initState(0) * initState(0);
159 for (
size_t i = 0;
i < nSteps + 1;
i++)
171 tf, x0[0], nonlinearSystem, costFunction, analyticLinearSystem);
187 size_t numIterations = 0;
189 while (numIterations < 50)
LineSearchSettings lineSearchSettings
number of threads for eigen parallelization (applies both to MP and ST) Note. in order to activate Ei...
Definition: NLOptConSettings.hpp:275
virtual const core::StateTrajectory< STATE_DIM, SCALAR > getStateTrajectory() const override
Definition: NLOptConSolver-impl.hpp:152
void symplecticTest()
Definition: SymplecticTest.h:110
LQOCP_SOLVER lqocp_solver
which nonlinear optimal control algorithm is to be used
Definition: NLOptConSettings.hpp:259
Dynamics class for the GNMS unit test, slightly nonlinear dynamics.
Definition: DiehlSystem.h:20
bool printSummary
Definition: NLOptConSettings.hpp:278
std::string loggingPrefix
the solver for the linear-quadratic optimal control problem
Definition: NLOptConSettings.hpp:260
virtual void computeVdot(const StateVector< 2 > &x, const StateVector< 1 > &p, const ControlVector< 1 > &control, StateVector< 1 > &vDot) override
Definition: SymplecticTest.h:49
double dt
Eigenvalue correction factor for Hessian regularization.
Definition: NLOptConSettings.hpp:262
TYPE type
Definition: NLOptConSettings.hpp:58
virtual const core::ControlTrajectory< CONTROL_DIM, SCALAR > getControlTrajectory() const override
Definition: NLOptConSolver-impl.hpp:160
std::shared_ptr< CostFunctionQuadratic< state_dim, control_dim > > createCostFunction(Eigen::Vector2d &x_final)
Create a cost function for the GNMS unit test.
Definition: SymplecticTest.h:89
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
const size_t state_dim
Definition: ConstraintComparison.h:20
double epsilon
the prefix to be stored before the matfile name for logging
Definition: NLOptConSettings.hpp:261
A simple quadratic cost function.
Definition: CostFunctionQuadraticSimple.hpp:23
NLOCAlgorithm_t::Policy_t Policy_t
Definition: NLOptConSolver.hpp:62
void configure(const Settings_t &settings) override
Definition: NLOptConSolver-impl.hpp:62
double min_cost_improvement
duration of a shot as an integer multiple of dt
Definition: NLOptConSettings.hpp:265
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
void setInitialGuess(const Policy_t &initialGuess) override
Definition: NLOptConSolver-impl.hpp:118
NLOCP_ALGORITHM nlocp_algorithm
Definition: NLOptConSettings.hpp:258
Dynamics * clone() const override
Definition: SymplecticTest.h:57
bool useSensitivityIntegrator
Definition: NLOptConSettings.hpp:279
Settings for the NLOptCon algorithm.
Definition: NLOptConSettings.hpp:198
LinearizedSystem * clone() const override
Definition: SymplecticTest.h:85
const double kStiffness
Definition: SymplecticTest.h:34
for i
Definition: mpc_unittest_plotting.m:14
bool fixedHessianCorrection
the maximum admissible number of NLOptCon main iterations
Definition: NLOptConSettings.hpp:270
int K_sim
sampling time for the control input (seconds)
Definition: NLOptConSettings.hpp:263
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
virtual bool runIteration() override
Definition: NLOptConSolver-impl.hpp:102
Dynamics()
Definition: SymplecticTest.h:40
int max_iterations
trade off between external (general and path) constraint violation and cost
Definition: NLOptConSettings.hpp:269
void computePdot(const StateVector< 2 > &x, const StateVector< 1 > &v, const ControlVector< 1 > &control, StateVector< 1 > &pDot) override
Definition: SymplecticTest.h:41
Linear system class for the GNMS unit test.
Definition: DiehlSystem.h:37
bool recordSmallestEigenvalue
perform Hessian regularization by incrementing the eigenvalues by epsilon.
Definition: NLOptConSettings.hpp:271
const state_matrix_t & getDerivativeState(const StateVector< state_dim > &x, const ControlVector< control_dim > &u, const double t=0.0) override
Definition: SymplecticTest.h:69
Eigen::Matrix< double, nStates, nStates > state_matrix_t
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
ct::core::IntegrationType integrator
Definition: NLOptConSettings.hpp:255
int nThreads
save the smallest eigenvalue of the Hessian
Definition: NLOptConSettings.hpp:272
int K_shot
number of sub-integration-steps
Definition: NLOptConSettings.hpp:264
Definition: NLOptConSolver.hpp:29
const state_control_matrix_t & getDerivativeControl(const StateVector< state_dim > &x, const ControlVector< control_dim > &u, const double t=0.0) override
Definition: SymplecticTest.h:77
Definition: OptConProblemBase.h:40
const size_t control_dim
Definition: ConstraintComparison.h:21
Definition: exampleDir.h:9