30 #include <mc_rtc/GUIState.h> 32 #include <copra/LMPC.h> 33 #include <copra/PreviewSystem.h> 34 #include <copra/constraints.h> 35 #include <copra/costFunctions.h> 54 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
71 void addGUIElements(std::shared_ptr<mc_rtc::gui::StateBuilder> gui);
83 void configure(
const mc_rtc::Configuration &);
104 void phaseDurations(
double initSupportDuration,
double doubleSupportDuration,
double targetSupportDuration);
121 double omegaInv = std::sqrt(zeta);
124 1, 0, omegaInv, 0, 0, 0,
125 0, 1, 0, omegaInv, 0, 0;
127 1, 0, 0, 0, -zeta, 0,
128 0, 1, 0, 0, 0, -zeta;
155 initState_ = Eigen::VectorXd(STATE_SIZE);
156 initState_ << pendulum.
com().head<2>(), pendulum.
comd().head<2>(), pendulum.
comdd().head<2>();
171 return indexToHrep_[i];
188 return nbInitSupportSteps_;
198 return nbDoubleSupportSteps_;
232 return targetContact_;
236 void computeZMPRef();
238 void updateTerminalConstraint();
240 void updateZMPConstraint();
242 void updateJerkCost();
244 void updateVelCost();
246 void updateZMPCost();
254 using RefVector = Eigen::Matrix<double, 2 * (NB_STEPS + 1), 1>;
255 using StateMatrix = Eigen::Matrix<double, 2, STATE_SIZE>;
260 RefVector velRef_ = RefVector::Zero();
261 RefVector zmpRef_ = RefVector::Zero();
262 Eigen::Matrix<double, 2 * (NB_STEPS + 1), STATE_SIZE *(NB_STEPS + 1)> velCostMat_;
263 StateMatrix dcmFromState_ = StateMatrix::Zero();
264 StateMatrix zmpFromState_ = StateMatrix::Zero();
265 Eigen::VectorXd initState_;
267 copra::SolverFlag solver_ = copra::SolverFlag::QLD;
268 double buildAndSolveTime_ = 0.;
269 double solveTime_ = 0.;
270 std::shared_ptr<Preview> solution_ =
nullptr;
271 std::shared_ptr<copra::ControlCost> jerkCost_ =
nullptr;
272 std::shared_ptr<copra::PreviewSystem> previewSystem_ =
nullptr;
273 std::shared_ptr<copra::TrajectoryConstraint> termDCMCons_ =
nullptr;
274 std::shared_ptr<copra::TrajectoryConstraint> termZMPCons_ =
nullptr;
275 std::shared_ptr<copra::TrajectoryConstraint> zmpCons_ =
nullptr;
276 std::shared_ptr<copra::TrajectoryCost> velCost_ =
nullptr;
277 std::shared_ptr<copra::TrajectoryCost> zmpCost_ =
nullptr;
278 unsigned indexToHrep_[NB_STEPS + 1];
279 unsigned nbDoubleSupportSteps_ = 0;
281 unsigned nbInitSupportSteps_ = 0;
282 unsigned nbNextDoubleSupportSteps_ = 0;
283 unsigned nbTargetSupportSteps_ = 0;
unsigned nbInitSupportSteps() const
Number of sampling steps in the preview spent in the first single-support phase.
static constexpr unsigned INPUT_SIZE
Input is the 2D horizontal CoM jerk.
const Contact & initContact() const
Support contact in the first single-support phase.
Eigen::Vector2d velWeights
Weights of CoM velocity tracking cost.
const Contact & targetContact() const
Support contact in the second single-support phase.
const Eigen::Vector3d & comdd() const
CoM acceleration in the world frame.
State of the inverted pendulum model.
const Contact & nextContact() const
Support contact in the third single-support phase.
const Eigen::Vector3d & comd() const
CoM velocity in the world frame.
static constexpr unsigned NB_STEPS
Number of sampling steps.
double zmpWeight
Weight of reference ZMP tracking cost.
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW constexpr double SAMPLING_PERIOD
Duration of each sampling step in [s].
unsigned nbDoubleSupportSteps() const
Number of sampling steps in the preview spent in the first double-support phase.
void contacts(Contact initContact, Contact targetContact, Contact nextContact)
Reset contacts.
void initState(const Pendulum &pendulum)
Set the initial CoM state.
ModelPredictiveControl()
Initialize new problem.
static constexpr unsigned STATE_SIZE
State is the 6D stacked vector of CoM positions, velocities and accelerations.
Model predictive control problem.
double jerkWeight
Weight of CoM jerk regularization cost.
void addLogEntries(mc_rtc::Logger &logger)
Log stabilizer entries.
void configure(const mc_rtc::Configuration &)
Read configuration from dictionary.
unsigned indexToHrep(unsigned i) const
Get index of inequality constraints.
bool buildAndSolve()
Build and solve the model predictive control quadratic program.
Main controller namespace.
const Eigen::Vector3d & com() const
CoM position in the world frame.
void sole(const Sole &sole)
Set model sole properties.
std::pair< Eigen::MatrixXd, Eigen::VectorXd > HrepXd
void comHeight(double height)
Set CoM height.
void phaseDurations(double initSupportDuration, double doubleSupportDuration, double targetSupportDuration)
Set duration of the initial single-support phase.
void addGUIElements(std::shared_ptr< mc_rtc::gui::StateBuilder > gui)
Add GUI panel.
const std::shared_ptr< Preview > solution() const
Get solution vector.