robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
mpc_jump.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_MPC_JUMP_HPP_
2#define ROBOTOC_MPC_JUMP_HPP_
3
4#include <vector>
5#include <memory>
6#include <limits>
7
8#include "Eigen/Core"
9
11#include "robotoc/ocp/ocp.hpp"
18#include "robotoc/robot/se3.hpp"
30
31
32namespace robotoc {
33
38class MPCJump {
39public:
46 MPCJump(const Robot& robot, const double T, const int N);
47
52
57
61 MPCJump(const MPCJump&) = default;
62
66 MPCJump& operator=(const MPCJump&) = default;
67
71 MPCJump(MPCJump&&) noexcept = default;
72
76 MPCJump& operator=(MPCJump&&) noexcept = default;
77
88 void setJumpPattern(const std::shared_ptr<ContactPlannerBase>& foot_step_planner,
89 const double flying_time, const double min_flying_time,
90 const double ground_time, const double min_ground_time);
91
101 void init(const double t, const Eigen::VectorXd& q, const Eigen::VectorXd& v,
102 const SolverOptions& solver_options, const bool sto=false);
103
108 void reset();
109
114 void reset(const Eigen::VectorXd& q, const Eigen::VectorXd& v);
115
127 void reset(const double t, const Eigen::VectorXd& q, const Eigen::VectorXd& v,
128 const SolverOptions& solver_options, const bool sto=false);
129
134 void setSolverOptions(const SolverOptions& solver_options);
135
145 void updateSolution(const double t, const double dt, const Eigen::VectorXd& q,
146 const Eigen::VectorXd& v);
147
152 const Eigen::VectorXd& getInitialControlInput() const;
153
158 const Solution& getSolution() const;
159
165
171 ControlPolicy getControlPolicy(const double t) const {
172 return ControlPolicy(ocp_solver_, t);
173 }
174
183 double KKTError(const double t, const Eigen::VectorXd& q,
184 const Eigen::VectorXd& v);
185
191 double KKTError() const;
192
197 std::shared_ptr<CostFunction> getCostHandle();
198
203 std::shared_ptr<ConfigurationSpaceCost> getConfigCostHandle();
204
209 std::shared_ptr<Constraints> getConstraintsHandle();
210
215 std::shared_ptr<FrictionCone> getFrictionConeHandle();
216
221 std::shared_ptr<ContactWrenchCone> getContactWrenchConeHandle();
222
227 const OCPSolver& getSolver() const { return ocp_solver_; }
228
233 const std::shared_ptr<ContactSequence>& getContactSequence() const {
234 return contact_sequence_;
235 }
236
242 void setRobotProperties(const RobotProperties& properties);
243
244 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
245
246private:
247 std::shared_ptr<ContactPlannerBase> foot_step_planner_;
248 std::shared_ptr<ContactSequence> contact_sequence_;
249 std::shared_ptr<CostFunction> cost_;
250 std::shared_ptr<Constraints> constraints_;
251 std::shared_ptr<robotoc::STOCostFunction> sto_cost_;
252 std::shared_ptr<robotoc::STOConstraints> sto_constraints_;
253 OCPSolver ocp_solver_;
254 SolverOptions solver_options_;
255 ContactStatus cs_ground_, cs_flying_;
257 double flying_time_, min_flying_time_, ground_time_, min_ground_time_,
258 T_, dt_, dtm_, t_mpc_start_, eps_;
259 int N_, current_step_;
260
261 std::shared_ptr<ConfigurationSpaceCost> config_cost_;
262 std::shared_ptr<FrictionCone> friction_cone_;
263 std::shared_ptr<ContactWrenchCone> contact_wrench_cone_;
264
265 void resetMinimumDwellTimes(const double t, const double min_dt);
266
267 void resetGoalContactPlacements(const Eigen::VectorXd& q);
268
269 void resetContactPlacements(const double t, const Eigen::VectorXd& q,
270 const Eigen::VectorXd& v);
271};
272
273} // namespace robotoc
274
275#endif // ROBOTOC_MPC_JUMP_HPP_
Base interface of contact planners.
Definition: contact_planner_base.hpp:21
Contact status of robot model.
Definition: contact_status.hpp:32
The state feedback and feedforward policy of LQR subproblem at a time stage.
Definition: lqr_policy.hpp:16
MPC solver for the jump control.
Definition: mpc_jump.hpp:38
void setJumpPattern(const std::shared_ptr< ContactPlannerBase > &foot_step_planner, const double flying_time, const double min_flying_time, const double ground_time, const double min_ground_time)
Sets the gait pattern.
std::shared_ptr< ContactWrenchCone > getContactWrenchConeHandle()
Gets the contact wrench cone constraints handle.
const Eigen::VectorXd & getInitialControlInput() const
Get the initial control input.
void setRobotProperties(const RobotProperties &properties)
Sets a collection of the properties for robot model in this MPC.
void updateSolution(const double t, const double dt, const Eigen::VectorXd &q, const Eigen::VectorXd &v)
Updates the solution by iterationg the Newton-type method.
std::shared_ptr< FrictionCone > getFrictionConeHandle()
Gets the friction cone constraints handle.
void reset()
Resets the optimal control problem solover via the solution computed by init() or reset().
const Solution & getSolution() const
Get the solution over the horizon.
void init(const double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v, const SolverOptions &solver_options, const bool sto=false)
Initializes the optimal control problem solover.
double KKTError(const double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v)
Computes the KKT residual of the optimal control problem.
std::shared_ptr< CostFunction > getCostHandle()
Gets the cost function handle.
ControlPolicy getControlPolicy(const double t) const
Gets the control policy at the specified time.
Definition: mpc_jump.hpp:171
MPCJump(const MPCJump &)=default
Default copy constructor.
double KKTError() const
Returns the l2-norm of the KKT residuals. MPCJump::updateSolution() must be computed.
const aligned_vector< LQRPolicy > & getLQRPolicy() const
Gets of the local LQR policies over the horizon.
MPCJump(MPCJump &&) noexcept=default
Default move constructor.
void setSolverOptions(const SolverOptions &solver_options)
Sets the solver options.
MPCJump()
Default constructor.
const std::shared_ptr< ContactSequence > & getContactSequence() const
Gets the const handle of the contact sequence.
Definition: mpc_jump.hpp:233
MPCJump(const Robot &robot, const double T, const int N)
Construct MPC solver.
MPCJump & operator=(const MPCJump &)=default
Default copy assign operator.
~MPCJump()
Destructor.
const OCPSolver & getSolver() const
Gets the const handle of the MPC solver.
Definition: mpc_jump.hpp:227
std::shared_ptr< Constraints > getConstraintsHandle()
Gets the constraints handle.
std::shared_ptr< ConfigurationSpaceCost > getConfigCostHandle()
Gets the configuration space cost handle.
Optimal control problem solver by Riccati recursion.
Definition: ocp_solver.hpp:41
Dynamics and kinematics model of robots. Wraps pinocchio::Model and pinocchio::Data....
Definition: robot.hpp:32
Definition: constraint_component_base.hpp:17
aligned_vector< SplitSolution > Solution
Solution to the optimal control problem.
Definition: solution.hpp:16
std::vector< T, Eigen::aligned_allocator< T > > aligned_vector
std vector with Eigen::aligned_allocator.
Definition: aligned_vector.hpp:14
Control pocily constructed for the MPC solution.
Definition: control_policy.hpp:17
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