robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
mpc_flying_trot.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_MPC_FLYING_TROT_HPP_
2#define ROBOTOC_MPC_FLYING_TROT_HPP_
3
4#include <memory>
5
6#include "Eigen/Core"
7#include "Eigen/Geometry"
8
10#include "robotoc/ocp/ocp.hpp"
32
33
34namespace robotoc {
35
41public:
48 MPCFlyingTrot(const Robot& quadruped_robot, const double T, const int N);
49
54
59
63 MPCFlyingTrot(const MPCFlyingTrot&) = default;
64
69
73 MPCFlyingTrot(MPCFlyingTrot&&) noexcept = default;
74
78 MPCFlyingTrot& operator=(MPCFlyingTrot&&) noexcept = default;
79
88 void setGaitPattern(const std::shared_ptr<ContactPlannerBase>& foot_step_planner,
89 const double swing_height, const double flying_time,
90 const double stance_time, const double swing_start_time);
91
101 void init(const double t, const Eigen::VectorXd& q, const Eigen::VectorXd& v,
102 const SolverOptions& solver_options);
103
108 void reset();
109
114 void reset(const Eigen::VectorXd& q, const Eigen::VectorXd& v);
115
120 void setSolverOptions(const SolverOptions& solver_options);
121
131 void updateSolution(const double t, const double dt, const Eigen::VectorXd& q,
132 const Eigen::VectorXd& v);
133
138 const Eigen::VectorXd& getInitialControlInput() const;
139
144 const Solution& getSolution() const;
145
151
157 ControlPolicy getControlPolicy(const double t) const {
158 return ControlPolicy(ocp_solver_, t);
159 }
160
169 double KKTError(const double t, const Eigen::VectorXd& q,
170 const Eigen::VectorXd& v);
171
177 double KKTError() const;
178
183 std::shared_ptr<CostFunction> getCostHandle();
184
189 std::shared_ptr<ConfigurationSpaceCost> getConfigCostHandle();
190
195 std::shared_ptr<ConfigurationSpaceCost> getBaseRotationCostHandle();
196
201 std::vector<std::shared_ptr<TaskSpace3DCost>> getSwingFootCostHandle();
202
207 std::shared_ptr<CoMCost> getCoMCostHandle();
208
213 std::shared_ptr<Constraints> getConstraintsHandle();
214
219 std::shared_ptr<FrictionCone> getFrictionConeHandle();
220
225 std::shared_ptr<ContactSequence> getContactSequenceHandle();
226
231 const OCPSolver& getSolver() const { return ocp_solver_; }
232
237 const std::shared_ptr<ContactSequence>& getContactSequence() const {
238 return contact_sequence_;
239 }
240
246 void setRobotProperties(const RobotProperties& properties);
247
248 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
249
250private:
251 std::shared_ptr<ContactPlannerBase> foot_step_planner_;
252 std::shared_ptr<ContactSequence> contact_sequence_;
253 std::shared_ptr<CostFunction> cost_;
254 std::shared_ptr<Constraints> constraints_;
255 OCPSolver ocp_solver_;
256 SolverOptions solver_options_;
257 ContactStatus cs_standing_, cs_lfrh_, cs_rflh_, cs_flying_;
259 double swing_height_, flying_time_, stance_time_, swing_start_time_,
260 T_, dt_, dtm_, ts_last_, eps_;
261 int N_, current_step_, predict_step_;
262
263 std::shared_ptr<ConfigurationSpaceCost> config_cost_;
264 std::shared_ptr<ConfigurationSpaceCost> base_rot_cost_;
265 std::shared_ptr<TaskSpace3DCost> LF_foot_cost_, LH_foot_cost_,
266 RF_foot_cost_, RH_foot_cost_;
267 std::shared_ptr<CoMCost> com_cost_;
268 std::shared_ptr<MPCPeriodicConfigurationRef> base_rot_ref_;
269 std::shared_ptr<MPCPeriodicSwingFootRef> LF_foot_ref_, LH_foot_ref_,
270 RF_foot_ref_, RH_foot_ref_;
271 std::shared_ptr<MPCPeriodicCoMRef> com_ref_;
272 std::shared_ptr<FrictionCone> friction_cone_;
273
274 bool addStep(const double t);
275
276 void resetContactPlacements(const double t, const Eigen::VectorXd& q,
277 const Eigen::VectorXd& v);
278
279};
280
281} // namespace robotoc
282
283#endif // ROBOTOC_MPC_FLYING_TROT_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 trot gait of quadrupeds.
Definition: mpc_flying_trot.hpp:40
MPCFlyingTrot & operator=(const MPCFlyingTrot &)=default
Default copy assign operator.
std::shared_ptr< CoMCost > getCoMCostHandle()
Gets the com cost handle.
const Eigen::VectorXd & getInitialControlInput() const
Get the initial control input.
double KKTError(const double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v)
Computes the KKT residual of the optimal control problem.
void setRobotProperties(const RobotProperties &properties)
Sets a collection of the properties for robot model in this MPC.
std::shared_ptr< ConfigurationSpaceCost > getBaseRotationCostHandle()
Gets the base rotation cost handle.
const aligned_vector< LQRPolicy > & getLQRPolicy() const
Gets of the local LQR policies over the horizon.
void reset()
Resets the optimal control problem solover via the solution computed by init().
const std::shared_ptr< ContactSequence > & getContactSequence() const
Gets the const handle of the contact sequence.
Definition: mpc_flying_trot.hpp:237
MPCFlyingTrot()
Default constructor.
void setSolverOptions(const SolverOptions &solver_options)
Sets the solver options.
const Solution & getSolution() const
Get the solution.
void setGaitPattern(const std::shared_ptr< ContactPlannerBase > &foot_step_planner, const double swing_height, const double flying_time, const double stance_time, const double swing_start_time)
Sets the gait pattern.
MPCFlyingTrot(MPCFlyingTrot &&) noexcept=default
Default move constructor.
std::vector< std::shared_ptr< TaskSpace3DCost > > getSwingFootCostHandle()
Gets the swing foot task space costs (LF, LH, RF, RH feet) handle.
void init(const double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v, const SolverOptions &solver_options)
Initializes the optimal control problem solover.
std::shared_ptr< ConfigurationSpaceCost > getConfigCostHandle()
Gets the configuration space cost handle.
MPCFlyingTrot(const Robot &quadruped_robot, const double T, const int N)
Construct MPC solver.
MPCFlyingTrot(const MPCFlyingTrot &)=default
Default copy constructor.
std::shared_ptr< Constraints > getConstraintsHandle()
Gets the constraints handle.
ControlPolicy getControlPolicy(const double t) const
Gets the control policy at the specified time.
Definition: mpc_flying_trot.hpp:157
double KKTError() const
Returns the l2-norm of the KKT residuals. MPCFlyingTrot::updateSolution() must be computed.
std::shared_ptr< ContactSequence > getContactSequenceHandle()
Gets the contact sequence handle.
std::shared_ptr< CostFunction > getCostHandle()
Gets the cost function handle.
std::shared_ptr< FrictionCone > getFrictionConeHandle()
Gets the friction cone constraints handle.
const OCPSolver & getSolver() const
Gets the const handle of the MPC solver.
Definition: mpc_flying_trot.hpp:231
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.
~MPCFlyingTrot()
Destructor.
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