robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
ocp_solver.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_OCP_SOLVER_HPP_
2#define ROBOTOC_OCP_SOLVER_HPP_
3
4#include <vector>
5#include <memory>
6#include <iostream>
7
8#include "Eigen/Core"
9
16#include "robotoc/ocp/ocp.hpp"
33
34
35namespace robotoc {
36
41class OCPSolver {
42public:
48 OCPSolver(const OCP& ocp,
49 const SolverOptions& solver_options=SolverOptions());
50
55
59 ~OCPSolver() = default;
60
64 OCPSolver(const OCPSolver&) = default;
65
69 OCPSolver& operator=(const OCPSolver&) = default;
70
74 OCPSolver(OCPSolver&&) noexcept = default;
75
79 OCPSolver& operator=(OCPSolver&&) noexcept = default;
80
85 void setSolverOptions(const SolverOptions& solver_options);
86
91 void discretize(const double t);
92
98
111 void solve(const double t, const Eigen::VectorXd& q, const Eigen::VectorXd& v,
112 const bool init_solver=true);
113
119
124 const Solution& getSolution() const;
125
133 const SplitSolution& getSolution(const int stage) const;
134
144 std::vector<Eigen::VectorXd> getSolution(const std::string& name,
145 const std::string& option="") const;
146
152
159
164 void setSolution(const Solution& s);
165
171 void setSolution(const std::string& name, const Eigen::VectorXd& value);
172
183 double KKTError(const double t, const Eigen::VectorXd& q,
184 const Eigen::VectorXd& v);
185
191 double KKTError() const;
192
198
204 void setRobotProperties(const RobotProperties& properties);
205
209 void disp(std::ostream& os) const;
210
211 friend std::ostream& operator<<(std::ostream& os,
212 const OCPSolver& ocp_solver);
213
214private:
215 aligned_vector<Robot> robots_;
216 std::shared_ptr<ContactSequence> contact_sequence_;
217 TimeDiscretization time_discretization_;
220 RiccatiRecursion riccati_recursion_;
221 LineSearch line_search_;
222 OCP ocp_;
223 KKTMatrix kkt_matrix_;
224 KKTResidual kkt_residual_;
225 Solution s_;
226 Direction d_;
227 RiccatiFactorization riccati_factorization_;
228 SolutionInterpolator solution_interpolator_;
229 SolverOptions solver_options_;
230 SolverStatistics solver_statistics_;
231 Timer timer_;
232
241 void updateSolution(const double t, const Eigen::VectorXd& q,
242 const Eigen::VectorXd& v);
243
244 void resizeData();
245
246};
247
248} // namespace robotoc
249
250#endif // ROBOTOC_OCP_SOLVER_HPP_
The sequence of contact status and discrete events (impact and lift).
Definition: contact_sequence.hpp:23
Direct multiple shooting method of the optimal control problems.
Definition: direct_multiple_shooting.hpp:32
The state feedback and feedforward policy of LQR subproblem at a time stage.
Definition: lqr_policy.hpp:16
Line search for optimal control problems.
Definition: line_search.hpp:25
Optimal control problem solver by Riccati recursion.
Definition: ocp_solver.hpp:41
const RiccatiFactorization & getRiccatiFactorization() const
Gets the Riccati factorizations. This can be interpreted as locally approximated cost-to-go functions...
OCPSolver(OCPSolver &&) noexcept=default
Default move constructor.
double KKTError() const
Returns the l2-norm of the KKT residuals using the results of OCPsolver::updateSolution() or OCPsolve...
const Solution & getSolution() const
Get the solution over the horizon.
const TimeDiscretization & getTimeDiscretization() const
Gets the discretization.
OCPSolver()
Default constructor.
OCPSolver & operator=(const OCPSolver &)=default
Default copy assign operator.
const aligned_vector< LQRPolicy > & getLQRPolicy() const
Gets of the local LQR policies over the horizon.
void setRobotProperties(const RobotProperties &properties)
Sets a collection of the properties for robot model in this solver.
~OCPSolver()=default
Default destructor.
void disp(std::ostream &os) const
Displays the optimal control problem solver onto a ostream.
const SolverStatistics & getSolverStatistics() const
Gets the solver statistics.
OCPSolver(const OCP &ocp, const SolverOptions &solver_options=SolverOptions())
Construct optimal control problem solver.
void setSolution(const Solution &s)
Sets the solution guess over the horizon.
void setSolverOptions(const SolverOptions &solver_options)
Sets the solver option.
void solve(const double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v, const bool init_solver=true)
Solves the optimal control problem. Internally calls updateSolutio() and discretize().
void discretize(const double t)
Discretizes the problem and reiszes the data structures.
void initConstraints()
Initializes the priaml-dual interior point method for inequality constraints.
OCPSolver(const OCPSolver &)=default
Default copy constructor.
Riccati recursion solver for optimal control problems. Solves the KKT system in linear time complexit...
Definition: riccati_recursion.hpp:26
Dynamics and kinematics model of robots. Wraps pinocchio::Model and pinocchio::Data....
Definition: robot.hpp:32
Solution interpolator.
Definition: solution_interpolator.hpp:17
Solution to the optimal control problem split into a time stage.
Definition: split_solution.hpp:20
The switching time optimization (STO) problem.
Definition: switching_time_optimization.hpp:24
Time discretization of the optimal control problem.
Definition: time_discretization.hpp:20
A timer class to take benchmarks.
Definition: timer.hpp:12
Definition: constraint_component_base.hpp:17
aligned_vector< SplitKKTMatrix > KKTMatrix
The KKT matrix of the optimal control problem.
Definition: kkt_matrix.hpp:16
aligned_vector< SplitSolution > Solution
Solution to the optimal control problem.
Definition: solution.hpp:16
aligned_vector< SplitDirection > Direction
Newton direction of the solution to the optimal control problem.
Definition: direction.hpp:16
std::vector< T, Eigen::aligned_allocator< T > > aligned_vector
std vector with Eigen::aligned_allocator.
Definition: aligned_vector.hpp:14
aligned_vector< SplitKKTResidual > KKTResidual
The KKT residual of the optimal control problem.
Definition: kkt_residual.hpp:16
aligned_vector< SplitRiccatiFactorization > RiccatiFactorization
Riccati factorization matices of the LQR subproblem.
Definition: riccati_factorization.hpp:16
The optimal control problem.
Definition: ocp.hpp:22
Collection of the robot properties, which can change after constructing robot models.
Definition: robot_properties.hpp:30
Options of optimal control solvers.
Definition: solver_options.hpp:17
Statistics of optimal control solvers.
Definition: solver_statistics.hpp:17