Exotica
ilqr_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_ILQR_SOLVER_ILQR_SOLVER_H_
31 #define EXOTICA_ILQR_SOLVER_ILQR_SOLVER_H_
32 
35 #include <exotica_core/server.h>
36 
37 #include <exotica_ilqr_solver/ilqr_solver_initializer.h>
38 
39 namespace exotica
40 {
41 // This code is based on:
42 // W. Li, E. Todorov, Iterative Linear Quadratic Regulator Design for Nonlinear Biological Movement Systems
43 // https://homes.cs.washington.edu/~todorov/papers/LiICINCO04.pdf
44 class ILQRSolver : public FeedbackMotionSolver, public Instantiable<ILQRSolverInitializer>
45 {
46 public:
49  void Solve(Eigen::MatrixXd& solution) override;
50 
54  void SpecifyProblem(PlanningProblemPtr pointer) override;
55 
56  Eigen::VectorXd GetFeedbackControl(Eigen::VectorXdRefConst x, int t) const override;
57 
58 private:
61  std::vector<Eigen::MatrixXd> K_gains_, Ku_gains_, Kv_gains_, vk_gains_;
62 
63  Eigen::MatrixXd best_ref_x_, best_ref_u_;
64 
67  void BackwardPass();
68 
74  double ForwardPass(const double alpha, Eigen::MatrixXdRefConst ref_x, Eigen::MatrixXdRefConst ref_u);
75 };
76 } // namespace exotica
77 
78 #endif // EXOTICA_ILQR_SOLVER_ILQR_SOLVER_H_
exotica::ILQRSolver::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;.
dynamic_time_indexed_shooting_problem.h
exotica::ILQRSolver::Solve
void Solve(Eigen::MatrixXd &solution) override
Solves the problem.
exotica::ILQRSolver::SpecifyProblem
void SpecifyProblem(PlanningProblemPtr pointer) override
Binds the solver to a specific problem which must be pre-initalised.
exotica::ILQRSolver::K_gains_
std::vector< Eigen::MatrixXd > K_gains_
!< Shared pointer to the dynamics solver.
Definition: ilqr_solver.h:61
exotica::ILQRSolver::dynamics_solver_
DynamicsSolverPtr dynamics_solver_
!< Shared pointer to the planning problem.
Definition: ilqr_solver.h:60
exotica::FeedbackMotionSolver
Definition: feedback_motion_solver.h:37
exotica::DynamicsSolverPtr
std::shared_ptr< exotica::DynamicsSolver > DynamicsSolverPtr
Definition: dynamics_solver.h:269
exotica::ILQRSolver::Ku_gains_
std::vector< Eigen::MatrixXd > Ku_gains_
Definition: ilqr_solver.h:61
exotica::Instantiable
Definition: property.h:110
exotica
Definition: cartpole_dynamics_solver.h:38
exotica::ILQRSolver
Definition: ilqr_solver.h:44
exotica::ILQRSolver::BackwardPass
void BackwardPass()
!< Reference trajectory for feedback control.
exotica::ILQRSolver::GetFeedbackControl
Eigen::VectorXd GetFeedbackControl(Eigen::VectorXdRefConst x, int t) const override
exotica::ILQRSolver::prob_
DynamicTimeIndexedShootingProblemPtr prob_
Definition: ilqr_solver.h:59
Eigen::VectorXdRefConst
const typedef Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
Definition: conversions.h:52
exotica::ILQRSolver::vk_gains_
std::vector< Eigen::MatrixXd > vk_gains_
Definition: ilqr_solver.h:61
Eigen::MatrixXdRefConst
const typedef Eigen::Ref< const Eigen::MatrixXd > & MatrixXdRefConst
Definition: conversions.h:53
exotica::DynamicTimeIndexedShootingProblemPtr
std::shared_ptr< exotica::DynamicTimeIndexedShootingProblem > DynamicTimeIndexedShootingProblemPtr
Definition: dynamic_time_indexed_shooting_problem.h:231
exotica::ILQRSolver::best_ref_u_
Eigen::MatrixXd best_ref_u_
Definition: ilqr_solver.h:63
exotica::PlanningProblemPtr
std::shared_ptr< PlanningProblem > PlanningProblemPtr
Definition: planning_problem.h:116
feedback_motion_solver.h
server.h
exotica::ILQRSolver::best_ref_x_
Eigen::MatrixXd best_ref_x_
!< Control gains.
Definition: ilqr_solver.h:63
exotica::ILQRSolver::Kv_gains_
std::vector< Eigen::MatrixXd > Kv_gains_
Definition: ilqr_solver.h:61