Exotica
ilqg_solver.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019, University of Edinburgh
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_ILQG_SOLVER_ILQG_SOLVER_H_
31 #define EXOTICA_ILQG_SOLVER_ILQG_SOLVER_H_
32 
35 #include <exotica_core/server.h>
36 #include <Eigen/Eigenvalues>
37 
38 #include <exotica_ilqg_solver/ilqg_solver_initializer.h>
39 
40 namespace exotica
41 {
42 // This code is based on:
43 // E. Todorov, W. Li A generalized iterative LQG method for locally-optimal feedback
44 // control of constrained nonlinear stochastic systems
45 // http://maeresearch.ucsd.edu/skelton/publications/weiwei_ilqg_CDC43.pdf
46 class ILQGSolver : public FeedbackMotionSolver, public Instantiable<ILQGSolverInitializer>
47 {
48 public:
51  void Solve(Eigen::MatrixXd& solution) override;
52 
56  void SpecifyProblem(PlanningProblemPtr pointer) override;
57 
58  Eigen::VectorXd GetFeedbackControl(Eigen::VectorXdRefConst x, int t) const override;
59 
60 private:
63  std::vector<Eigen::MatrixXd> l_gains_, L_gains_;
64 
65  Eigen::MatrixXd best_ref_x_, best_ref_u_;
66 
69  void BackwardPass();
70 
76  double ForwardPass(const double alpha, Eigen::MatrixXdRefConst ref_x, Eigen::MatrixXdRefConst ref_u);
77 };
78 } // namespace exotica
79 
80 #endif // EXOTICA_ILQG_SOLVER_ILQG_SOLVER_H_
dynamic_time_indexed_shooting_problem.h
exotica::ILQGSolver::L_gains_
std::vector< Eigen::MatrixXd > L_gains_
Definition: ilqg_solver.h:63
exotica::ILQGSolver::dynamics_solver_
DynamicsSolverPtr dynamics_solver_
!< Shared pointer to the planning problem.
Definition: ilqg_solver.h:62
exotica::ILQGSolver::BackwardPass
void BackwardPass()
!< Reference trajectory for feedback control.
exotica::FeedbackMotionSolver
Definition: feedback_motion_solver.h:37
exotica::DynamicsSolverPtr
std::shared_ptr< exotica::DynamicsSolver > DynamicsSolverPtr
Definition: dynamics_solver.h:269
exotica::Instantiable
Definition: property.h:110
exotica
Definition: cartpole_dynamics_solver.h:38
exotica::ILQGSolver::best_ref_u_
Eigen::MatrixXd best_ref_u_
Definition: ilqg_solver.h:65
exotica::ILQGSolver::l_gains_
std::vector< Eigen::MatrixXd > l_gains_
!< Shared pointer to the dynamics solver.
Definition: ilqg_solver.h:63
Eigen::VectorXdRefConst
const typedef Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
Definition: conversions.h:52
exotica::ILQGSolver::prob_
DynamicTimeIndexedShootingProblemPtr prob_
Definition: ilqg_solver.h:61
Eigen::MatrixXdRefConst
const typedef Eigen::Ref< const Eigen::MatrixXd > & MatrixXdRefConst
Definition: conversions.h:53
exotica::ILQGSolver::SpecifyProblem
void SpecifyProblem(PlanningProblemPtr pointer) override
Binds the solver to a specific problem which must be pre-initalised.
exotica::DynamicTimeIndexedShootingProblemPtr
std::shared_ptr< exotica::DynamicTimeIndexedShootingProblem > DynamicTimeIndexedShootingProblemPtr
Definition: dynamic_time_indexed_shooting_problem.h:231
exotica::ILQGSolver::GetFeedbackControl
Eigen::VectorXd GetFeedbackControl(Eigen::VectorXdRefConst x, int t) const override
exotica::PlanningProblemPtr
std::shared_ptr< PlanningProblem > PlanningProblemPtr
Definition: planning_problem.h:116
exotica::ILQGSolver
Definition: ilqg_solver.h:46
exotica::ILQGSolver::Solve
void Solve(Eigen::MatrixXd &solution) override
Solves the problem.
feedback_motion_solver.h
exotica::ILQGSolver::ForwardPass
double ForwardPass(const double alpha, Eigen::MatrixXdRefConst ref_x, Eigen::MatrixXdRefConst ref_u)
Forward simulates the dynamics using the gains computed in the last BackwardPass;.
server.h
exotica::ILQGSolver::best_ref_x_
Eigen::MatrixXd best_ref_x_
!< Control gains.
Definition: ilqg_solver.h:65