abstract_ddp_solver.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020, University of Edinburgh, University of Oxford
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_DDP_SOLVER_ABSTRACT_DDP_SOLVER_H_
31 #define EXOTICA_DDP_SOLVER_ABSTRACT_DDP_SOLVER_H_
32 
35 #include <exotica_core/server.h>
37 #include <exotica_ddp_solver/abstract_ddp_solver_initializer.h>
38 
39 namespace exotica
40 {
41 // \brief Base DDP Solver class that implements the forward pass.
42 // and utility functions.
44 {
45 public:
48  void Solve(Eigen::MatrixXd& solution) override;
49 
53  void SpecifyProblem(PlanningProblemPtr pointer) override;
54 
55  Eigen::VectorXd GetFeedbackControl(Eigen::VectorXdRefConst x, int t) const override;
56 
57  const std::vector<Eigen::MatrixXd>& get_Vxx() const;
58  const std::vector<Eigen::VectorXd>& get_Vx() const;
59  const std::vector<Eigen::MatrixXd>& get_Qxx() const;
60  const std::vector<Eigen::MatrixXd>& get_Qux() const;
61  const std::vector<Eigen::MatrixXd>& get_Quu() const;
62  const std::vector<Eigen::VectorXd>& get_Qx() const;
63  const std::vector<Eigen::VectorXd>& get_Qu() const;
64  const std::vector<Eigen::MatrixXd>& get_K() const;
65  const std::vector<Eigen::VectorXd>& get_k() const;
66 
67  const std::vector<Eigen::VectorXd>& get_X_try() const;
68  const std::vector<Eigen::VectorXd>& get_U_try() const;
69 
70  const std::vector<Eigen::VectorXd>& get_X_ref() const;
71  const std::vector<Eigen::VectorXd>& get_U_ref() const;
72 
73  const std::vector<Eigen::MatrixXd>& get_Quu_inv() const;
74  const std::vector<Eigen::MatrixXd>& get_fx() const;
75  const std::vector<Eigen::MatrixXd>& get_fu() const;
76 
77  std::vector<double> get_control_cost_evolution() const;
78  void set_control_cost_evolution(const int index, const double cost);
79 
80  std::vector<double> get_steplength_evolution() const;
81  // void set_steplength_evolution(const int index, const double cost);
82 
83  std::vector<double> get_regularization_evolution() const;
84  // void set_regularization_evolution(const int index, const double cost);
85 
86 protected:
89 
92  virtual void BackwardPass() = 0;
93 
99  double ForwardPass(const double alpha);
100 
101  AbstractDDPSolverInitializer base_parameters_;
102 
103  virtual void IncreaseRegularization()
104  {
105  lambda_ *= 10.;
106  }
107 
108  virtual void DecreaseRegularization()
109  {
110  lambda_ /= 10.;
111  }
112 
113  // Local variables used in the solver - copies get updated at the beginning of solve:
114  Eigen::VectorXd alpha_space_;
115  double lambda_;
116  int T_;
117  int NU_;
118  int NX_;
119  int NDX_;
120  int NV_;
121  double dt_;
122  double cost_;
123  double control_cost_;
124 
125  double cost_try_;
127 
128  double cost_prev_;
129  double alpha_best_;
131 
132  std::vector<Eigen::MatrixXd> Vxx_;
133  std::vector<Eigen::VectorXd> Vx_;
134  std::vector<Eigen::MatrixXd> Qxx_;
135  std::vector<Eigen::MatrixXd> Qux_;
136  std::vector<Eigen::MatrixXd> Quu_;
137  std::vector<Eigen::VectorXd> Qx_;
138  std::vector<Eigen::VectorXd> Qu_;
139  std::vector<Eigen::MatrixXd> K_;
140  std::vector<Eigen::VectorXd> k_;
141 
142  std::vector<Eigen::VectorXd> X_try_;
143  std::vector<Eigen::VectorXd> U_try_;
144 
145  std::vector<Eigen::VectorXd> X_ref_;
146  std::vector<Eigen::VectorXd> U_ref_;
147 
148  std::vector<Eigen::MatrixXd> Quu_inv_;
149  std::vector<Eigen::MatrixXd> fx_;
150  std::vector<Eigen::MatrixXd> fu_;
151 
152  std::vector<double> control_cost_evolution_;
153  std::vector<double> steplength_evolution_;
154  std::vector<double> regularization_evolution_;
155 };
156 
157 } // namespace exotica
158 
159 #endif // EXOTICA_DDP_SOLVER_ABSTRACT_DDP_SOLVER_H_
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)
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
Eigen::VectorXd GetFeedbackControl(Eigen::VectorXdRefConst x, int t) const override
const std::vector< Eigen::MatrixXd > & get_Qux() const
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.
unsigned int index
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.
std::shared_ptr< exotica::DynamicsSolver > DynamicsSolverPtr
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.
std::vector< Eigen::MatrixXd > Quu_inv_
Inverse of the Hessian of the Hamiltonian.
std::vector< Eigen::VectorXd > Qx_
Gradient of the Hamiltonian.
const std::vector< Eigen::VectorXd > & get_Qx() const
DynamicsSolverPtr dynamics_solver_
Shared pointer to the dynamics solver.
std::shared_ptr< exotica::DynamicTimeIndexedShootingProblem > DynamicTimeIndexedShootingProblemPtr
int NDX_
Size of tangent vector to the state vector.
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
double x
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;.
std::vector< Eigen::MatrixXd > K_
Feedback gains.
std::vector< double > get_control_cost_evolution() const


exotica_ddp_solver
Author(s): Traiko Dinev
autogenerated on Sat Apr 10 2021 02:36:21