robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
mpc_biped_walk.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_MPC_BIPED_WALK_HPP_
2#define ROBOTOC_MPC_BIPED_WALK_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 MPCBipedWalk(const Robot& biped_robot, const double T, const int N);
49
54
59
63 MPCBipedWalk(const MPCBipedWalk&) = default;
64
69
73 MPCBipedWalk(MPCBipedWalk&&) noexcept = default;
74
78 MPCBipedWalk& operator=(MPCBipedWalk&&) noexcept = default;
79
88 void setGaitPattern(const std::shared_ptr<ContactPlannerBase>& foot_step_planner,
89 const double swing_height, const double swing_time,
90 const double double_support_time,
91 const double swing_start_time);
92
102 void init(const double t, const Eigen::VectorXd& q, const Eigen::VectorXd& v,
103 const SolverOptions& solver_options);
104
109 void reset();
110
117 void reset(const Eigen::VectorXd& q, const Eigen::VectorXd& v);
118
123 void setSolverOptions(const SolverOptions& solver_options);
124
134 void updateSolution(const double t, const double dt, const Eigen::VectorXd& q,
135 const Eigen::VectorXd& v);
136
141 const Eigen::VectorXd& getInitialControlInput() const;
142
147 const Solution& getSolution() const;
148
154
160 ControlPolicy getControlPolicy(const double t) const {
161 return ControlPolicy(ocp_solver_, t);
162 }
163
172 double KKTError(const double t, const Eigen::VectorXd& q,
173 const Eigen::VectorXd& v);
174
180 double KKTError() const;
181
186 std::shared_ptr<CostFunction> getCostHandle();
187
192 std::shared_ptr<ConfigurationSpaceCost> getConfigCostHandle();
193
198 std::shared_ptr<ConfigurationSpaceCost> getBaseRotationCostHandle();
199
204 std::vector<std::shared_ptr<TaskSpace3DCost>> getSwingFootCostHandle();
205
210 std::shared_ptr<CoMCost> getCoMCostHandle();
211
216 std::shared_ptr<Constraints> getConstraintsHandle();
217
222 std::shared_ptr<ContactWrenchCone> getContactWrenchConeHandle();
223
228 std::shared_ptr<ImpactWrenchCone> getImpactWrenchConeHandle();
229
234 const OCPSolver& getSolver() const { return ocp_solver_; }
235
240 const std::shared_ptr<ContactSequence>& getContactSequence() const {
241 return contact_sequence_;
242 }
243
249 void setRobotProperties(const RobotProperties& properties);
250
251 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
252
253private:
254 std::shared_ptr<ContactPlannerBase> foot_step_planner_;
255 std::shared_ptr<ContactSequence> contact_sequence_;
256 std::shared_ptr<CostFunction> cost_;
257 std::shared_ptr<Constraints> constraints_;
258 OCPSolver ocp_solver_;
259 SolverOptions solver_options_;
260 ContactStatus cs_standing_, cs_right_swing_, cs_left_swing_;
262 double step_height_, swing_time_, double_support_time_, swing_start_time_,
263 T_, dt_, dtm_, ts_last_, eps_;
264 int N_, current_step_, predict_step_;
265 bool enable_double_support_phase_;
266
267 std::shared_ptr<ConfigurationSpaceCost> config_cost_;
268 std::shared_ptr<ConfigurationSpaceCost> base_rot_cost_;
269 std::shared_ptr<TaskSpace3DCost> L_foot_cost_, R_foot_cost_;
270 std::shared_ptr<CoMCost> com_cost_;
271 std::shared_ptr<MPCPeriodicConfigurationRef> base_rot_ref_;
272 std::shared_ptr<MPCPeriodicSwingFootRef> L_foot_ref_, R_foot_ref_;
273 std::shared_ptr<MPCPeriodicCoMRef> com_ref_;
274 std::shared_ptr<ContactWrenchCone> contact_wrench_cone_;
275 std::shared_ptr<ImpactWrenchCone> impact_wrench_cone_;
276
277 bool addStep(const double t);
278
279 void resetContactPlacements(const double t, const Eigen::VectorXd& q,
280 const Eigen::VectorXd& v);
281
282};
283
284} // namespace robotoc
285
286#endif // ROBOTOC_MPC_BIPED_WALK_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 bipedal robot walk.
Definition: mpc_biped_walk.hpp:40
void setGaitPattern(const std::shared_ptr< ContactPlannerBase > &foot_step_planner, const double swing_height, const double swing_time, const double double_support_time, const double swing_start_time)
Sets the gait pattern.
std::shared_ptr< ConfigurationSpaceCost > getBaseRotationCostHandle()
Gets the base rotation cost handle.
std::shared_ptr< ContactWrenchCone > getContactWrenchConeHandle()
Gets the contact wrench cone constraints handle.
void setSolverOptions(const SolverOptions &solver_options)
Sets the solver options.
std::shared_ptr< CostFunction > getCostHandle()
Gets the cost function handle.
MPCBipedWalk(const MPCBipedWalk &)=default
Default copy constructor.
const Eigen::VectorXd & getInitialControlInput() const
Get the initial control input.
void reset()
Resets the optimal control problem solover via the solution computed by init().
double KKTError() const
Returns the l2-norm of the KKT residuals. MPCBipedWalk::updateSolution() must be computed.
const OCPSolver & getSolver() const
Gets the const handle of the MPC solver.
Definition: mpc_biped_walk.hpp:234
std::shared_ptr< Constraints > getConstraintsHandle()
Gets the constraints handle.
const std::shared_ptr< ContactSequence > & getContactSequence() const
Gets the const handle of the contact sequence.
Definition: mpc_biped_walk.hpp:240
double KKTError(const double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v)
Computes the KKT residual of the optimal control problem.
ControlPolicy getControlPolicy(const double t) const
Gets the control policy at the specified time.
Definition: mpc_biped_walk.hpp:160
MPCBipedWalk(const Robot &biped_robot, const double T, const int N)
Construct MPC solver.
const aligned_vector< LQRPolicy > & getLQRPolicy() const
Gets of the local LQR policies over the horizon.
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.
void init(const double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v, const SolverOptions &solver_options)
Initializes the optimal control problem solover.
MPCBipedWalk(MPCBipedWalk &&) noexcept=default
Default move constructor.
~MPCBipedWalk()
Destructor.
void setRobotProperties(const RobotProperties &properties)
Sets a collection of the properties for robot model in this MPC.
const Solution & getSolution() const
Get the solution over the horizon.
std::vector< std::shared_ptr< TaskSpace3DCost > > getSwingFootCostHandle()
Gets the swing foot task space costs (LF, LH, RF, RH feet) handle.
std::shared_ptr< ImpactWrenchCone > getImpactWrenchConeHandle()
Gets the impact wrench cone constraints handle.
MPCBipedWalk & operator=(const MPCBipedWalk &)=default
Default copy assign operator.
MPCBipedWalk()
Default constructor.
std::shared_ptr< ConfigurationSpaceCost > getConfigCostHandle()
Gets the configuration space cost handle.
std::shared_ptr< CoMCost > getCoMCostHandle()
Gets the com 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