11 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
15 : Base(problem, settings)
19 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
24 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
26 const typename optConProblem_t::DynamicsPtr_t& dyn)
29 throw std::runtime_error(
"system dynamics are nullptr");
33 this->
systems_.at(
i) =
typename optConProblem_t::DynamicsPtr_t(dyn->clone());
38 discretizers_.at(
i)->initialize();
41 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
43 const typename optConProblem_t::LinearPtr_t& lin)
46 throw std::runtime_error(
"linear system dynamics are nullptr");
50 this->
linearSystems_.at(
i) =
typename optConProblem_t::LinearPtr_t(lin->clone());
55 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
75 discretizers_.at(
i)->initialize();
80 this->settings_.integrator != ct::core::IntegrationType::EULERCT &&
81 this->settings_.integrator != ct::core::IntegrationType::RK4 &&
82 this->settings_.integrator != ct::core::IntegrationType::RK4CT &&
83 this->settings_.integrator != ct::core::IntegrationType::EULER_SYM)
84 throw std::runtime_error(
"sensitivity integrator only available for Euler and RK4 integrators");
100 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
104 if (settings.nThreads != this->settings_.nThreads)
106 throw std::runtime_error(
"Number of threads cannot be changed after instance has been created.");
108 if (settings.integrator != this->settings_.integrator)
110 throw std::runtime_error(
"Cannot change integration type.");
114 for (
int i = 0;
i < settings.nThreads + 1;
i++)
116 if (!sensitivity_[
i])
119 sensitivity_[
i]->setApproximation(settings.discretization);
121 if (settings.useSensitivityIntegrator)
122 sensitivity_[
i]->setTimeDiscretization(settings.getSimulationTimestep());
124 sensitivity_[
i]->setTimeDiscretization(settings.dt);
126 discretizers_[
i]->setParameters(settings.dt, settings.K_sim);
132 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
138 const size_t threadId)
141 discretizers_[threadId]->propagateControlledDynamics(state, n, control, stateNext);
144 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
147 const size_t threadId)
149 subStepsX = discretizers_[threadId]->getSubstates();
152 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
155 const size_t threadId)
157 subStepsU = discretizers_[threadId]->getSubcontrols();
160 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
164 const size_t threadId)
166 sensitivity_[threadId]->setSubstepTrajectoryReference(xSubsteps.get(), uSubsteps.get());
169 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR>
177 const size_t threadId)
179 sensitivity_[threadId]->getAandB(x, u, x_next, n, subSteps, A, B);
Base::optConProblem_t optConProblem_t
Definition: OptconContinuousSystemInterface.h:58
virtual void changeNumStages(const int numStages) override
set the number of stages/time steps
Definition: OptconContinuousSystemInterface-impl.h:20
std::shared_ptr< Sensitivity_t > SensitivityPtr
Definition: OptconContinuousSystemInterface.h:51
std::vector< ConstantControllerPtr, Eigen::aligned_allocator< ConstantControllerPtr > > controller_
Definition: OptconSystemInterface.h:123
Base::StateVectorArrayPtr StateVectorArrayPtr
Definition: OptconContinuousSystemInterface.h:53
Base::ControlVectorArrayPtr ControlVectorArrayPtr
Definition: OptconContinuousSystemInterface.h:55
std::vector< typename optConProblem_t::DynamicsPtr_t > systems_
Definition: OptconSystemInterface.h:111
double dt
Eigenvalue correction factor for Hessian regularization.
Definition: NLOptConSettings.hpp:262
std::vector< typename optConProblem_t::LinearPtr_t > linearSystems_
Definition: OptconSystemInterface.h:119
virtual void setSubstepTrajectoryReference(const StateSubstepsPtr &xSubsteps, const ControlSubstepsPtr &uSubsteps, const size_t threadId) override
Definition: OptconContinuousSystemInterface-impl.h:161
const LinearPtr_t getLinearSystem() const
Definition: OptConProblemBase-impl.h:151
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
virtual void changeLinearSystem(const typename optConProblem_t::LinearPtr_t &lin) override
Definition: OptconContinuousSystemInterface-impl.h:42
virtual void getSubcontrols(ControlVectorArrayPtr &subStepsU, const size_t threadId) override
Definition: OptconContinuousSystemInterface-impl.h:153
settings_t settings_
instance of the optconProblem
Definition: OptconSystemInterface.h:127
const DynamicsPtr_t getNonlinearSystem() const
Definition: OptConProblemBase-impl.h:138
virtual void getAandB(const state_vector_t &x, const control_vector_t &u, const state_vector_t &x_next, const int n, size_t subSteps, state_matrix_t &A, state_control_matrix_t &B, const size_t threadId) override
retrieve discrete-time linear system matrices A and B.
Definition: OptconContinuousSystemInterface-impl.h:170
double getSimulationTimestep() const
compute the simulation timestep
Definition: NLOptConSettings.hpp:300
virtual void initialize() override
perform necessary setup work
Definition: OptconContinuousSystemInterface-impl.h:56
std::shared_ptr< discretizer_t > system_discretizer_ptr_t
Definition: OptconContinuousSystemInterface.h:48
Base::settings_t settings_t
Definition: OptconContinuousSystemInterface.h:59
bool useSensitivityIntegrator
Definition: NLOptConSettings.hpp:279
ct::core::SystemDiscretizer< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR > discretizer_t
Definition: OptconContinuousSystemInterface.h:47
for i
Definition: mpc_unittest_plotting.m:14
APPROXIMATION discretization
which integrator to use during the NLOptCon forward rollout
Definition: NLOptConSettings.hpp:256
int K_sim
sampling time for the control input (seconds)
Definition: NLOptConSettings.hpp:263
optConProblem_t optConProblem_
the constant controller for forward-integration during one time-step
Definition: OptconSystemInterface.h:125
bool timeVaryingDiscretization
Definition: NLOptConSettings.hpp:257
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
Base::control_vector_t control_vector_t
Definition: OptconContinuousSystemInterface.h:42
virtual void changeNonlinearSystem(const typename optConProblem_t::DynamicsPtr_t &dyn) override
Definition: OptconContinuousSystemInterface-impl.h:25
Base::state_vector_t state_vector_t
Definition: OptconContinuousSystemInterface.h:43
ct::core::IntegrationType integrator
Definition: NLOptConSettings.hpp:255
virtual void getSubstates(StateVectorArrayPtr &subStepsX, const size_t threadId) override
Definition: OptconContinuousSystemInterface-impl.h:145
int nThreads
save the smallest eigenvalue of the Hessian
Definition: NLOptConSettings.hpp:272
Base::state_matrix_t state_matrix_t
Definition: OptconContinuousSystemInterface.h:44
Base::ControlSubstepsPtr ControlSubstepsPtr
Definition: OptconContinuousSystemInterface.h:56
Base::state_control_matrix_t state_control_matrix_t
Definition: OptconContinuousSystemInterface.h:45
virtual void configure(const settings_t &settings) override
Definition: OptconContinuousSystemInterface-impl.h:101
Base::StateSubstepsPtr StateSubstepsPtr
Definition: OptconContinuousSystemInterface.h:54
OptconContinuousSystemInterface(const optConProblem_t &problem, const settings_t &settings)
constructor
Definition: OptconContinuousSystemInterface-impl.h:12
virtual void propagateControlledDynamics(const state_vector_t &state, const time_t n, const control_vector_t &control, state_vector_t &stateNext, const size_t threadId) override
propagate discrete-time dynamics
Definition: OptconContinuousSystemInterface-impl.h:133