37 Timer planning_timer, backward_pass_timer, line_search_timer;
40 NU_ =
prob_->GetScene()->get_num_controls();
41 NX_ =
prob_->GetScene()->get_num_state();
42 NDX_ =
prob_->GetScene()->get_num_state_derivative();
43 NV_ =
prob_->GetScene()->get_num_velocities();
48 solution.resize(
T_ - 1,
NU_);
58 for (
int t = 0; t <
T_ - 1; ++t)
73 K_.assign(T_, Eigen::MatrixXd(
NU_,
NDX_));
74 k_.assign(T_, Eigen::VectorXd(
NU_));
77 X_ref_.assign(T_, Eigen::VectorXd::Zero(
NX_));
78 U_ref_.assign(T_ - 1, Eigen::VectorXd::Zero(
NU_));
79 X_try_.assign(T_, Eigen::VectorXd::Zero(
NX_));
80 U_try_.assign(T_ - 1, Eigen::VectorXd::Zero(
NU_));
81 for (
int t = 0; t <
T_; ++t)
86 for (
int t = 0; t < T_ - 1; ++t)
93 Vx_.assign(T_, Eigen::VectorXd::Zero(
NDX_));
95 Qx_.assign(T_ - 1, Eigen::VectorXd::Zero(
NDX_));
96 Qu_.assign(T_ - 1, Eigen::VectorXd::Zero(
NU_));
98 Qux_.assign(T_ - 1, Eigen::MatrixXd::Zero(
NU_,
NDX_));
99 Quu_.assign(T_ - 1, Eigen::MatrixXd::Zero(
NU_,
NU_));
101 fx_.assign(T_ - 1, Eigen::MatrixXd::Zero(
NDX_,
NDX_));
102 fu_.assign(T_ - 1, Eigen::MatrixXd::Zero(
NDX_,
NU_));
107 int last_best_iteration = 0;
120 backward_pass_timer.
Reset();
125 line_search_timer.
Reset();
135 if (rollout_cost <
cost_)
137 cost_ = rollout_cost;
139 for (
int t = 0; t < T_ - 1; ++t)
U_try_[t] =
prob_->get_U(t);
153 if (!std::isfinite(
cost_))
176 if (iteration - last_best_iteration >
base_parameters_.FunctionTolerancePatience)
193 last_best_iteration = iteration;
233 for (
int t = 0; t < T_ - 1; ++t)
235 for (
int t = 0; t <
T_; ++t)
248 prob_->OnSolverIterationEnd();
252 for (
int t = 0; t < T_ - 1; ++t)
254 solution.row(t) =
U_ref_[t].transpose();
263 if (pointer->type() !=
"exotica::DynamicTimeIndexedShootingProblem")
265 ThrowNamed(
"This DDPSolver can't solve problem of type '" << pointer->type() <<
"'!");
272 alpha_space_ = Eigen::VectorXd::LinSpaced(11, 0.0, -3.0);
286 Eigen::VectorXd u_hat(
NU_);
287 Eigen::VectorXd xdiff(
NDX_);
289 for (
int t = 0; t <
T_ - 1; ++t)
293 u_hat.noalias() += alpha *
k_[t];
294 u_hat.noalias() +=
K_[t] * xdiff;
302 prob_->Update(u_hat, t);
336 std::vector<double> ret;
352 else if (index == -1)
364 std::vector<double> ret;
376 std::vector<double> ret;
const std::vector< Eigen::VectorXd > & get_U_try() const
const std::vector< Eigen::VectorXd > & get_Qu() const
const std::vector< Eigen::VectorXd > & get_U_ref() const
std::vector< double > steplength_evolution_
Evolution of the steplength.
const std::vector< Eigen::VectorXd > & get_X_ref() const
const std::vector< Eigen::MatrixXd > & get_Quu() const
Eigen::VectorXd alpha_space_
Backtracking line-search steplengths.
const std::vector< Eigen::MatrixXd > & get_fx() const
double dt_
Integration time-step.
const std::vector< Eigen::MatrixXd > & get_fu() const
const std::vector< Eigen::MatrixXd > & get_K() const
std::vector< double > regularization_evolution_
Evolution of the regularization (xreg/ureg)
double lambda_
Regularization (Vxx, Quu)
#define WARNING_NAMED(name, x)
int NV_
Size of velocity vector (tangent vector to the configuration)
int NX_
Size of state vector.
std::vector< Eigen::MatrixXd > Quu_
Hessian of the Hamiltonian.
double cost_try_
Total cost computed by line-search procedure.
const std::vector< Eigen::VectorXd > & get_Vx() const
virtual void IncreaseRegularization()
Eigen::VectorXd GetFeedbackControl(Eigen::VectorXdRefConst x, int t) const override
const std::vector< Eigen::MatrixXd > & get_Qux() const
int GetNumberOfMaxIterations()
virtual void SpecifyProblem(PlanningProblemPtr pointer)
int NU_
Size of control vector.
std::vector< double > get_steplength_evolution() const
std::vector< Eigen::MatrixXd > fx_
Derivative of the dynamics f w.r.t. x.
void set_control_cost_evolution(const int index, const double cost)
void SpecifyProblem(PlanningProblemPtr pointer) override
Binds the solver to a specific problem which must be pre-initalised.
const std::vector< Eigen::MatrixXd > & get_Vxx() const
int T_
Length of shooting problem, i.e., state trajectory. The control trajectory has length T_-1...
std::vector< Eigen::MatrixXd > Vxx_
Hessian of the Value function.
double control_cost_
Control cost during iteration.
std::vector< double > control_cost_evolution_
Evolution of the control cost (control regularization)
std::vector< Eigen::VectorXd > k_
Feed-forward terms.
std::vector< Eigen::MatrixXd > Qxx_
Hessian of the Hamiltonian.
std::vector< Eigen::VectorXd > X_ref_
Reference state trajectory for feedback control.
double cost_
Cost during iteration.
std::vector< Eigen::MatrixXd > fu_
Derivative of the dynamics f w.r.t. u.
std::vector< Eigen::MatrixXd > Qux_
Hessian of the Hamiltonian.
double alpha_best_
Line-search step taken.
double cost_prev_
Cost during previous iteration.
std::vector< Eigen::VectorXd > U_ref_
Reference control trajectory for feedback control.
std::vector< Eigen::VectorXd > U_try_
Updated control trajectory during iteration (computed by line-search)
std::vector< Eigen::VectorXd > Vx_
Gradient of the Value function.
std::vector< double > get_regularization_evolution() const
void Solve(Eigen::MatrixXd &solution) override
Solves the problem.
double control_cost_try_
Total control cost computed by line-search procedure.
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
const std::vector< Eigen::MatrixXd > & get_Quu_inv() const
std::vector< Eigen::VectorXd > Qu_
Gradient of the Hamiltonian.
double time_taken_backward_pass_
std::vector< Eigen::MatrixXd > Quu_inv_
Inverse of the Hessian of the Hamiltonian.
std::vector< Eigen::VectorXd > Qx_
Gradient of the Hamiltonian.
virtual void DecreaseRegularization()
#define HIGHLIGHT_NAMED(name, x)
const std::vector< Eigen::VectorXd > & get_Qx() const
DynamicsSolverPtr dynamics_solver_
Shared pointer to the dynamics solver.
int NDX_
Size of tangent vector to the state vector.
double GetDuration() const
virtual void BackwardPass()=0
Computes the control gains for a the trajectory in the associated DynamicTimeIndexedProblem.
std::shared_ptr< PlanningProblem > PlanningProblemPtr
const std::vector< Eigen::VectorXd > & get_k() const
DynamicTimeIndexedShootingProblemPtr prob_
Shared pointer to the planning problem.
std::vector< Eigen::VectorXd > X_try_
Updated state trajectory during iteration (computed by line-search)
const std::vector< Eigen::VectorXd > & get_X_try() const
AbstractDDPSolverInitializer base_parameters_
const std::vector< Eigen::MatrixXd > & get_Qxx() const
double ForwardPass(const double alpha)
Forward simulates the dynamics using the gains computed in the last BackwardPass;.
double time_taken_forward_pass_
std::vector< Eigen::MatrixXd > K_
Feedback gains.
std::vector< double > get_control_cost_evolution() const