mc_rtc  2.16.0
StabilizerTask.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  *
4  * This file is inspired by Stephane's Caron original implementation as part of
5  * lipm_walking_controller <https://github.com/stephane-caron/lipm_walking_controller>
6  */
7 
8 #pragma once
9 
12 #include <mc_filter/LowPass.h>
16 #include <mc_rtc/deprecated.h>
17 #include <mc_tasks/CoMTask.h>
18 #include <mc_tasks/CoPTask.h>
19 #include <mc_tasks/MetaTask.h>
23 
24 #include <state-observation/dynamics-estimators/lipm-dcm-estimator.hpp>
25 
26 #include <Eigen/QR>
27 #include <eigen-quadprog/QuadProg.h>
28 
29 namespace mc_tasks
30 {
31 
32 namespace lipm_stabilizer
33 {
34 
42 
57 {
58  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59 
62  {
63  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
71  std::string surfaceName;
72  };
73 
87  const mc_rbdyn::Robots & realRobots,
88  unsigned int robotIndex,
89  const std::string & leftSurface,
90  const std::string & rightSurface,
91  const std::string & torsoBodyName,
92  double dt);
93 
109  const mc_rbdyn::Robots & realRobots,
110  unsigned int robotIndex,
111  double dt);
112 
113  inline void name(const std::string & name) override
114  {
115  name_ = name;
116 
117  // Rename the tasks managed by the stabilizer
118  // Doing so helps making the logs more consistent, and having a fixed name
119  // allows for predifined custom plots in the log ui.
120  const auto n = name_ + "_Tasks";
121  comTask->name(n + "_com");
122  footTasks.at(ContactState::Left)->name(n + "_cop_left");
123  footTasks.at(ContactState::Right)->name(n + "_cop_right");
124  pelvisTask->name(n + "_pelvis");
125  torsoTask->name(n + "_torso");
126  }
127 
128  using MetaTask::name;
129 
145  void reset() override;
146 
153  Eigen::VectorXd eval() const override;
154 
161  Eigen::VectorXd speed() const override;
162 
169  void enable();
170 
172  void disable();
173 
182  void configure(const StabilizerConfiguration & config);
183 
187  void commitConfig();
188 
190  void load(mc_solver::QPSolver &, const mc_rtc::Configuration & config) override;
191 
199 
209 
215  void reconfigure();
216 
221  void run();
222 
235  void setContacts(const ContactDescriptionVector & contacts);
236 
243  void setContacts(const std::vector<std::pair<ContactState, sva::PTransformd>> & contacts);
244 
252  void setContacts(const std::vector<ContactState> & contacts);
253 
261  inline const sva::PTransformd & contactAnklePose(ContactState s) const { return contacts_.at(s).anklePose(); }
262 
263  inline const std::string & footSurface(ContactState s) const { return footTasks.at(s)->surface(); }
264 
270  inline double leftFootRatio() const noexcept { return leftFootRatio_; }
271 
281 
295  void staticTarget(const Eigen::Vector3d & com, double zmpHeight = 0);
296 
317  void target(const Eigen::Vector3d & com,
318  const Eigen::Vector3d & comd,
319  const Eigen::Vector3d & comdd,
320  const Eigen::Vector3d & zmp,
321  const Eigen::Vector3d & zmpd = Eigen::Vector3d::Zero());
322 
330  inline const Eigen::Vector3d & targetCoMRaw() const noexcept { return comTargetRaw_; }
331 
339  inline const Eigen::Vector3d & targetCoM() const noexcept { return comTargetRaw_; }
340 
341  /* Return the target CoM velocity provided by \ref stabilizer_target "target()" */
342  inline const Eigen::Vector3d & targetCoMVelocity() const noexcept { return comdTarget_; }
343 
344  /* Return the target CoM acceleration provided by \ref stabilizer_target "target()" */
345  inline const Eigen::Vector3d & targetCoMAcceleration() const noexcept { return comddTarget_; }
346 
347  /* Return the target ZMP provided by \ref stabilizer_target "target()" */
348  inline const Eigen::Vector3d & targetZMP() const noexcept { return zmpTarget_; }
349 
350  /* Return the target ZMP velocity by \ref stabilizer_target "target()" */
351  inline const Eigen::Vector3d & targetZMPVelocity() const noexcept { return zmpdTarget_; }
352 
353  /* Return the current support foot */
354  inline ContactState supportFoot() const noexcept { return supportFoot_; }
355 
356  /* Set the current support foot */
357  inline void supportFoot(const ContactState & foot) noexcept { supportFoot_ = foot; }
358 
368  inline void horizonReference(const std::vector<Eigen::Vector2d> & ref, const double delta) noexcept
369  {
370  horizonZmpRef_ = ref;
371  horizonDelta_ = delta;
372  horizonCoPDistribution_ = true;
373  horizonRefUpdated_ = true;
374  }
375 
388  void setExternalWrenches(const std::vector<std::string> & surfaceNames,
389  const std::vector<sva::ForceVecd> & targetWrenches,
390  const std::vector<sva::MotionVecd> & gains);
391 
392  /* Return the current external wrenches targets
393  *
394  * \see \ref set_external_wrenches "setExternalWrenches()"
395  **/
396  inline const std::vector<ExternalWrench> & externalWrenches() const noexcept { return extWrenches_; }
397 
398  /*
399  * Return the ZMP from the wrenches distribution
400  **/
401  inline const Eigen::Vector3d & distribZMP() const noexcept { return distribZMP_; }
402 
403  inline const Eigen::Vector3d & measuredDCM() noexcept { return measuredDCM_; }
404 
405  inline const Eigen::Vector2d biasDCM() noexcept
406  {
407  if(c_.dcmBias.withDCMBias) { return dcmEstimator_.getBias(); }
408  return Eigen::Vector2d::Zero();
409  }
410 
411  inline Eigen::Vector2d filteredDCM() const noexcept
412  {
413  if(c_.dcmBias.withDCMBias) { return dcmEstimator_.getUnbiasedDCM(); }
414  return measuredDCM_.segment(0, 2);
415  }
416 
417  inline const Eigen::Vector3d & measuredZMP() noexcept { return measuredZMP_; }
418 
419  inline const Eigen::Vector3d & measuredCoM() noexcept { return measuredCoM_; }
420 
421  inline const Eigen::Vector3d & measuredCoMd() noexcept { return measuredCoMd_; }
422 
423  inline const Eigen::Vector3d & measuredFilteredNetForces() const noexcept { return fSumFilter_.eval(); }
424 
425  inline const Eigen::Vector3d & comOffsetTarget() noexcept { return comOffsetTarget_; }
426 
427  inline const Eigen::Vector3d & comOffsetMeasured() const noexcept { return comOffsetMeasured_; }
428 
429  inline double zmpCoeffMeasured() const noexcept { return zmpCoefMeasured_; }
430 
431  inline bool inContact(ContactState state) const noexcept { return contacts_.count(state); }
432 
433  inline bool inDoubleSupport() const noexcept { return contacts_.size() == 2; }
434 
435  inline const mc_rbdyn::Robot & robot() const noexcept { return robots_.robot(robotIndex_); }
436 
437  inline const mc_rbdyn::Robot & realRobot() const noexcept { return realRobots_.robot(robotIndex_); }
438 
453  inline void torsoPitch(double pitch) noexcept { c_.torsoPitch = pitch; }
454 
455  inline double omega() const { return omega_; }
456 
457  inline void torsoWeight(double weight) noexcept
458  {
459  c_.torsoWeight = weight;
460  torsoTask->weight(c_.torsoWeight);
461  }
462 
463  inline void torsoStiffness(double stiffness) noexcept
464  {
465  c_.torsoStiffness = stiffness;
466  torsoTask->stiffness(stiffness);
467  }
468 
469  inline void pelvisWeight(double weight) noexcept
470  {
471  c_.pelvisWeight = weight;
472  pelvisTask->weight(c_.pelvisWeight);
473  }
474 
475  inline void pelvisStiffness(double stiffness) noexcept
476  {
477  c_.pelvisStiffness = stiffness;
478  pelvisTask->stiffness(stiffness);
479  }
480 
481  inline void dcmGains(double p, double i, double d) noexcept
482  { dcmGains(Eigen::Vector2d::Constant(p), Eigen::Vector2d::Constant(i), Eigen::Vector2d::Constant(d)); }
483 
484  inline void dcmGains(const Eigen::Vector2d & p, const Eigen::Vector2d & i, const Eigen::Vector2d & d) noexcept
485  {
486  c_.dcmPropGain = clamp(p, 0., c_.safetyThresholds.MAX_DCM_P_GAIN);
487  c_.dcmIntegralGain = clamp(i, 0., c_.safetyThresholds.MAX_DCM_I_GAIN);
488  c_.dcmDerivGain = clamp(d, 0., c_.safetyThresholds.MAX_DCM_D_GAIN);
489  }
490 
491  inline void dcmIntegratorTimeConstant(double dcmIntegratorTimeConstant) noexcept
492  {
493  c_.dcmIntegratorTimeConstant = dcmIntegratorTimeConstant;
494  dcmIntegrator_.timeConstant(dcmIntegratorTimeConstant);
495  }
496 
497  MC_RTC_DEPRECATED inline void dcmDerivatorTimeConstant(double T) noexcept { dcmDerivatorCutoffPeriod(T); }
498 
499  inline void dcmDerivatorCutoffPeriod(double T) noexcept
500  {
501  c_.dcmDerivatorTimeConstant = T;
502  dcmDerivator_.cutoffPeriod(T);
503  }
504 
505  inline void extWrenchSumLowPassCutoffPeriod(double cutoffPeriod) noexcept
506  {
507  c_.extWrench.extWrenchSumLowPassCutoffPeriod = cutoffPeriod;
508  extWrenchSumLowPass_.cutoffPeriod(cutoffPeriod);
509  }
510 
511  inline void comOffsetLowPassCutoffPeriod(double cutoffPeriod) noexcept
512  {
513  c_.extWrench.comOffsetLowPassCutoffPeriod = cutoffPeriod;
514  comOffsetLowPass_.cutoffPeriod(cutoffPeriod);
515  }
516 
517  inline void comOffsetLowPassCoMCutoffPeriod(double cutoffPeriod) noexcept
518  {
519  c_.extWrench.comOffsetLowPassCoMCutoffPeriod = cutoffPeriod;
520  comOffsetLowPassCoM_.cutoffPeriod(cutoffPeriod);
521  }
522 
523  inline void comOffsetDerivatorTimeConstant(double timeConstant) noexcept
524  {
525  c_.extWrench.comOffsetDerivatorTimeConstant = timeConstant;
526  comOffsetDerivator_.timeConstant(timeConstant);
527  }
528 
529  inline void comWeight(double weight) noexcept
530  {
531  c_.comWeight = weight;
532  comTask->weight(weight);
533  }
534 
535  inline void comStiffness(const Eigen::Vector3d & stiffness) noexcept
536  {
537  c_.comStiffness = stiffness;
538  comTask->stiffness(stiffness);
539  }
540 
541  inline void contactWeight(double weight) noexcept
542  {
543  c_.contactWeight = weight;
544  for(auto footT : contactTasks) { footT->weight(c_.contactWeight); }
545  }
546 
547  inline void contactStiffness(const sva::MotionVecd & stiffness) noexcept
548  {
549  c_.contactStiffness = stiffness;
550  for(auto contactT : contactTasks) { contactT->stiffness(stiffness); }
551  }
552 
553  inline void contactDamping(const sva::MotionVecd & damping) noexcept
554  {
555  c_.contactDamping = damping;
556  for(auto contactT : contactTasks) { contactT->damping(damping); }
557  }
558 
559  inline void copAdmittance(const Eigen::Vector2d & copAdmittance) noexcept
560  {
561  c_.copAdmittance = clamp(copAdmittance, 0., c_.safetyThresholds.MAX_COP_ADMITTANCE);
562  for(auto contactT : contactTasks) { contactT->admittance(contactAdmittance()); }
563  }
564 
565  inline void copMaxVel(const sva::MotionVecd & copMaxVel) noexcept
566  {
567  c_.copMaxVel = copMaxVel;
568  for(const auto & footTask : footTasks)
569  {
570  footTask.second->maxLinearVel(copMaxVel.linear());
571  footTask.second->maxAngularVel(copMaxVel.angular());
572  }
573  }
574 
575  /* Set the gain of the low-pass velocity filter of the cop tasks */
576  inline void copVelFilterGain(double gain) noexcept
577  {
578  c_.copVelFilterGain = mc_filter::utils::clamp(gain, 0, 1);
579  for(auto & ft : footTasks) { ft.second->velFilterGain(gain); }
580  }
581 
582  /* Get the gain of the low-pass velocity filter of the cop tasks */
583  inline double copVelFilterGain() const noexcept { return c_.copVelFilterGain; }
584 
585  inline void vdcFrequency(double freq) noexcept { c_.vdcFrequency = clamp(freq, 0., 10.); }
586 
587  inline void vdcStiffness(double stiffness) noexcept { c_.vdcStiffness = clamp(stiffness, 0., 1e4); }
588 
589  inline void dfAdmittance(Eigen::Vector3d dfAdmittance) noexcept
590  { c_.dfAdmittance = clamp(dfAdmittance, 0., c_.safetyThresholds.MAX_DF_ADMITTANCE); }
591 
592  inline void dfDamping(Eigen::Vector3d dfDamping) noexcept
593  { c_.dfDamping = clamp(dfDamping, 0., c_.safetyThresholds.MAX_DF_DAMPING); }
594 
595  inline void fdqpWeights(const FDQPWeights & fdqp) noexcept { c_.fdqpWeights = fdqp; }
596 
606  inline void safetyThresholds(const SafetyThresholds & thresholds) noexcept
607  {
608  c_.safetyThresholds = thresholds;
609  c_.clampGains();
610  // only requried because we want to apply the new gains immediately
611  copAdmittance(c_.copAdmittance);
612  }
613 
619  inline void dcmBiasEstimatorConfiguration(const DCMBiasEstimatorConfiguration & biasConfig) noexcept
620  {
621  auto & bc = c_.dcmBias;
622  bc = biasConfig;
623  dcmEstimator_.setBiasDriftPerSecond(bc.biasDriftPerSecondStd);
624  dcmEstimator_.setDcmMeasureErrorStd(bc.dcmMeasureErrorStd);
625  dcmEstimator_.setZmpMeasureErrorStd(bc.zmpMeasureErrorStd);
626  dcmEstimator_.setBiasLimit(bc.biasLimit);
627  }
628 
630  inline const DCMBiasEstimatorConfiguration & dcmBiasEstimatorConfiguration() const noexcept { return c_.dcmBias; }
631 
637  inline void externalWrenchConfiguration(const ExternalWrenchConfiguration & extWrenchConfig) noexcept
638  {
639  c_.extWrench = extWrenchConfig;
640  extWrenchSumLowPass_.cutoffPeriod(c_.extWrench.extWrenchSumLowPassCutoffPeriod);
641  comOffsetLowPass_.cutoffPeriod(c_.extWrench.comOffsetLowPassCutoffPeriod);
642  comOffsetLowPassCoM_.cutoffPeriod(c_.extWrench.comOffsetLowPassCoMCutoffPeriod);
643  comOffsetDerivator_.timeConstant(c_.extWrench.comOffsetDerivatorTimeConstant);
644  }
645 
647  inline const ExternalWrenchConfiguration & externalWrenchConfiguration() const noexcept { return c_.extWrench; }
648 
649 private:
650  void dimWeight(const Eigen::VectorXd & dimW) override;
651  Eigen::VectorXd dimWeight() const override;
652 
653  void selectActiveJoints(mc_solver::QPSolver & solver,
654  const std::vector<std::string> & activeJointsName,
655  const std::map<std::string, std::vector<std::array<int, 2>>> & activeDofs = {}) override;
656 
657  void selectUnactiveJoints(mc_solver::QPSolver & solver,
658  const std::vector<std::string> & unactiveJointsName,
659  const std::map<std::string, std::vector<std::array<int, 2>>> & unactiveDofs = {}) override;
660 
661  void resetJointsSelector(mc_solver::QPSolver & solver) override;
662 
668  void addContact(ContactState contactState, const internal::Contact & contact);
669 
671  void checkInTheAir();
672 
676  void computeLeftFootRatio();
677 
686  void updateState(const Eigen::Vector3d & com, const Eigen::Vector3d & comd, const Eigen::Vector3d & comdd);
687 
693  void updateContacts(mc_solver::QPSolver & solver);
694 
696  sva::ForceVecd computeDesiredWrench();
697 
702  void distributeWrench(const sva::ForceVecd & desiredWrench);
703 
717  void distributeCoPonHorizon(const std::vector<Eigen::Vector2d> & zmp_ref, double delta);
718 
719  void computeCoPonHorizon(const std::vector<Eigen::Vector2d> & zmp_ref, const double delta, const double t_delay);
720 
729  void saturateWrench(const sva::ForceVecd & desiredWrench,
730  std::shared_ptr<mc_tasks::force::CoPTask> & footTask,
731  const internal::Contact & contact);
732 
734  void setSupportFootGains();
735 
746  void updateCoMTaskZMPCC();
747 
754  void updateFootForceDifferenceControl();
755 
757  void updateZMPFrame();
758 
760  inline sva::ForceVecd contactAdmittance() const noexcept
761  { return {{c_.copAdmittance.y(), c_.copAdmittance.x(), 0.}, {0., 0., 0.}}; }
762 
763  inline void zmpcc(const ZMPCCConfiguration & zmpccConfig) noexcept
764  {
765  c_.zmpcc = zmpccConfig;
766  zmpcc_.configure(zmpccConfig);
767  }
768 
777  template<sva::ForceVecd ExternalWrench::* TargetOrMeasured>
778  void computeWrenchOffsetAndCoefficient(const mc_rbdyn::Robot & robot,
779  Eigen::Vector3d & offset_gamma,
780  double & coef_kappa) const;
781 
788  template<sva::ForceVecd ExternalWrench::* TargetOrMeasured>
789  sva::ForceVecd computeExternalWrenchSum(const mc_rbdyn::Robot & robot, const Eigen::Vector3d & com) const;
790 
800  void computeExternalContact(const mc_rbdyn::Robot & robot,
801  const std::string & surfaceName,
802  const sva::ForceVecd & surfaceWrench,
803  Eigen::Vector3d & pos,
804  Eigen::Vector3d & force,
805  Eigen::Vector3d & moment) const;
806 
807  /* Task-related properties */
808 protected:
809  void addToSolver(mc_solver::QPSolver & solver) override;
810  void removeFromSolver(mc_solver::QPSolver & solver) override;
812  void update(mc_solver::QPSolver &) override;
813 
818  void addToLogger(mc_rtc::Logger &) override;
821 
829  void disable_();
830 
833 
834 protected:
843  {
844  template<typename T>
845  std::size_t operator()(T t) const
846  { return static_cast<std::size_t>(t); }
847  };
848  std::unordered_map<ContactState,
850  EnumClassHash,
851  std::equal_to<ContactState>,
852  Eigen::aligned_allocator<std::pair<const ContactState, internal::Contact>>>
854  std::vector<ContactState> addContacts_;
855  std::unordered_map<ContactState, std::shared_ptr<mc_tasks::force::CoPTask>, EnumClassHash> footTasks;
856  std::vector<std::shared_ptr<mc_tasks::force::CoPTask>> contactTasks;
857  std::vector<std::string> contactSensors;
859  std::vector<std::vector<Eigen::Vector3d>> supportPolygons_;
860  Eigen::Vector2d supportMin_ = Eigen::Vector2d::Zero();
861  Eigen::Vector2d supportMax_ = Eigen::Vector2d::Zero();
862  std::shared_ptr<mc_tasks::CoMTask> comTask;
863  std::shared_ptr<mc_tasks::OrientationTask> pelvisTask;
864  std::shared_ptr<mc_tasks::OrientationTask> torsoTask;
867  unsigned int robotIndex_;
868 
870  Eigen::Vector3d comTargetRaw_ = Eigen::Vector3d::Zero();
871  Eigen::Vector3d comTarget_ = Eigen::Vector3d::Zero();
872  Eigen::Vector3d comdTarget_ = Eigen::Vector3d::Zero();
873  Eigen::Vector3d comddTarget_ = Eigen::Vector3d::Zero();
874  Eigen::Vector3d zmpTarget_ = Eigen::Vector3d::Zero();
875  Eigen::Vector3d zmpdTarget_ = Eigen::Vector3d::Zero();
876  Eigen::Vector3d dcmTarget_ = Eigen::Vector3d::Zero();
877  double omega_ = 3.4;
878 
879  double t_ = 0.;
881 protected:
893  bool reconfigure_ = true;
894  bool enabled_ = true;
897  Eigen::Vector3d dcmAverageError_ = Eigen::Vector3d::Zero();
898  Eigen::Vector3d dcmError_ = Eigen::Vector3d::Zero();
899  Eigen::Vector3d dcmVelError_ = Eigen::Vector3d::Zero();
900  Eigen::Vector3d measuredCoM_ = Eigen::Vector3d::Zero();
901  Eigen::Vector3d measuredCoMd_ = Eigen::Vector3d::Zero();
902  Eigen::Vector3d measuredCoMdd_ = Eigen::Vector3d::Zero();
903  Eigen::Vector3d measuredZMP_ = Eigen::Vector3d::Zero();
904  Eigen::Vector3d measuredDCM_ = Eigen::Vector3d::Zero();
905  Eigen::Vector3d measuredDCMUnbiased_ = Eigen::Vector3d::Zero();
906  Eigen::Vector3d measuredCoMUnbiased_ = Eigen::Vector3d::Zero();
907  sva::ForceVecd measuredNetWrench_ = sva::ForceVecd::Zero();
908 
909  bool zmpccOnlyDS_ = true;
917  stateObservation::LipmDcmEstimator dcmEstimator_;
919  bool dcmEstimatorNeedsReset_ = true;
920 
926  std::vector<ExternalWrench> extWrenches_;
927  sva::ForceVecd extWrenchSumTarget_ = sva::ForceVecd::Zero();
928  sva::ForceVecd extWrenchSumMeasured_ = sva::ForceVecd::Zero();
929  Eigen::Vector3d comOffsetTarget_ = Eigen::Vector3d::Zero();
930  Eigen::Vector3d comOffsetMeasured_ = Eigen::Vector3d::Zero();
931  double zmpCoefTarget_ = 1;
932  double zmpCoefMeasured_ = 1;
933  Eigen::Vector3d comOffsetErr_ = Eigen::Vector3d::Zero();
934  Eigen::Vector3d comOffsetErrCoM_ = Eigen::Vector3d::Zero();
935  Eigen::Vector3d comOffsetErrZMP_ = Eigen::Vector3d::Zero();
946  bool inTheAir_ = false;
947  bool wasInTheAir_ = false;
948  bool wasEnabled_ = true;
949  Eigen::Vector3d dfForceError_ = Eigen::Vector3d::Zero();
950  Eigen::Vector3d dfError_ = Eigen::Vector3d::Zero();
951  double dt_ = 0.005;
952  double leftFootRatio_ = 0.5;
953  double mass_ = 38.;
954  double runTime_ = 0.;
955  double vdcHeightError_ = 0;
958  Eigen::Vector3d distribZMP_ =
959  Eigen::Vector3d::Zero();
962  // CoP distribution over an horizon
963  //{
964  std::vector<Eigen::Vector2d> horizonZmpRef_;
965  double horizonDelta_ = 0.05;
967  bool horizonCoPDistribution_ = false;
968  bool horizonRefUpdated_ = false;
969  Eigen::Vector2d modeledCoPLeft_ = Eigen::Vector2d::Zero();
970  Eigen::Vector2d modeledCoPRight_ = Eigen::Vector2d::Zero();
972  Eigen::Vector2d delayedTargetCoPLeft_ = Eigen::Vector2d::Zero();
973  Eigen::Vector2d delayedTargetCoPRight_ = Eigen::Vector2d::Zero();
974  double delayedTargetFzLeft_ = 0;
975  double delayedTargetFzRight_ = 0;
977  double tComputation_ = 0.;
978  double modeledFzRight_ = 0.;
979  double modeledFzLeft_ = 0.;
980  double desiredFzLeft_ = 0.;
981  double desiredFzRight_ = 0.;
982  Eigen::Vector2d QPCoPLeft_ =
983  Eigen::Vector2d::Zero();
984  Eigen::Vector2d QPCoPRight_ =
985  Eigen::Vector2d::Zero();
987  Eigen::Vector2d distribCheck_ = Eigen::Vector2d::Zero();
989  ContactState supportFoot_ = ContactState::Left;
991  //}
992 };
993 
994 extern template void StabilizerTask::computeWrenchOffsetAndCoefficient<&StabilizerTask::ExternalWrench::target>(
995  const mc_rbdyn::Robot & robot,
996  Eigen::Vector3d & offset_gamma,
997  double & coef_kappa) const;
998 extern template void StabilizerTask::computeWrenchOffsetAndCoefficient<&StabilizerTask::ExternalWrench::measured>(
999  const mc_rbdyn::Robot & robot,
1000  Eigen::Vector3d & offset_gamma,
1001  double & coef_kappa) const;
1002 
1003 extern template sva::ForceVecd StabilizerTask::computeExternalWrenchSum<&StabilizerTask::ExternalWrench::target>(
1004  const mc_rbdyn::Robot &,
1005  const Eigen::Vector3d &) const;
1006 extern template sva::ForceVecd StabilizerTask::computeExternalWrenchSum<&StabilizerTask::ExternalWrench::measured>(
1007  const mc_rbdyn::Robot &,
1008  const Eigen::Vector3d &) const;
1009 
1010 } // namespace lipm_stabilizer
1011 } // namespace mc_tasks
static ForceVec< T > Zero()
static PTransform< T > Identity()
#define MC_TASKS_DLLAPI
Definition: api.h:50
mc_control::Contact Contact
Definition: Controller.h:22
double clamp(double value, double lower, double upper)
Definition: clamp.h:29
Eigen::Vector3d MC_RBDYN_DLLAPI zmp(const sva::ForceVecd &netTotalWrench, const Eigen::Vector3d &plane_p, const Eigen::Vector3d &plane_n, double minimalNetNormalForce=1.)
Actual ZMP computation from net total wrench and the ZMP plane.
std::vector< ContactDescription, Eigen::aligned_allocator< ContactDescription > > ContactDescriptionVector
Definition: Contact.h:199
mc_rbdyn::lipm_stabilizer::SafetyThresholds SafetyThresholds
Definition: StabilizerTask.h:39
mc_rbdyn::lipm_stabilizer::ZMPCCConfiguration ZMPCCConfiguration
Definition: StabilizerTask.h:36
mc_rbdyn::lipm_stabilizer::FDQPWeights FDQPWeights
Definition: StabilizerTask.h:38
mc_rbdyn::lipm_stabilizer::ExternalWrenchConfiguration ExternalWrenchConfiguration
Definition: StabilizerTask.h:41
mc_rbdyn::lipm_stabilizer::StabilizerConfiguration StabilizerConfiguration
Definition: StabilizerTask.h:37
mc_rbdyn::lipm_stabilizer::DCMBiasEstimatorConfiguration DCMBiasEstimatorConfiguration
Definition: StabilizerTask.h:40
Definition: StabilizerStandingState.h:12
Left
Definition: types.h:148
Definition: LowPass.h:23
Definition: Robot.h:63
Definition: Robots.h:17
Definition: StabilizerConfiguration.h:168
Parameters for the external wrenches.
Definition: StabilizerConfiguration.h:261
Definition: StabilizerConfiguration.h:23
Stabilizer safety thresholds.
Definition: StabilizerConfiguration.h:99
Configuration of the LIPMStabilizer. This configuration is meant to be overriden from the RobotModule...
Definition: StabilizerConfiguration.h:429
Definition: ZMPCCConfiguration.h:15
Simplify access to values hold within a JSON file.
Definition: Configuration.h:166
Logs controller data to disk.
Definition: Logger.h:30
Definition: StateBuilder.h:28
Definition: QPSolver.h:88
Represents a generic task.
Definition: MetaTask.h:40
const std::string & name() const
Definition: MetaTask.h:67
Workaround a C++11 standard bug: no specialization of the hash functor exists for enum types....
Definition: StabilizerTask.h:843
std::size_t operator()(T t) const
Definition: StabilizerTask.h:845
External wrench.
Definition: StabilizerTask.h:62
std::string surfaceName
Name of the surface to which the external wrench is applied.
Definition: StabilizerTask.h:71
sva::ForceVecd measured
Measured external wrench.
Definition: StabilizerTask.h:67
EIGEN_MAKE_ALIGNED_OPERATOR_NEW sva::ForceVecd target
Target (expected) external wrench.
Definition: StabilizerTask.h:65
sva::MotionVecd gain
Gain of measured external wrench.
Definition: StabilizerTask.h:69
Definition: StabilizerTask.h:57
void pelvisStiffness(double stiffness) noexcept
Definition: StabilizerTask.h:475
const mc_rbdyn::Robots & realRobots_
Definition: StabilizerTask.h:866
Eigen::QuadProgDense qpSolver_
Definition: StabilizerTask.h:896
void addToLogger(mc_rtc::Logger &) override
double omega() const
Definition: StabilizerTask.h:455
std::shared_ptr< mc_tasks::CoMTask > comTask
Definition: StabilizerTask.h:862
std::vector< ExternalWrench > extWrenches_
Definition: StabilizerTask.h:926
ZMPCC zmpcc_
Definition: StabilizerTask.h:910
const Eigen::Vector3d & comOffsetTarget() noexcept
Definition: StabilizerTask.h:425
Eigen::Vector2d filteredDCM() const noexcept
Definition: StabilizerTask.h:411
void torsoStiffness(double stiffness) noexcept
Definition: StabilizerTask.h:463
void removeFromLogger(mc_rtc::Logger &) override
const sva::PTransformd & contactAnklePose(ContactState s) const
Projected pose of the ankle frame in the contact frame.
Definition: StabilizerTask.h:261
void configure_(mc_solver::QPSolver &solver)
Actual configuration of the stabilizer. Called when reconfigure_ is true.
void contactStiffness(const sva::MotionVecd &stiffness) noexcept
Definition: StabilizerTask.h:547
void removeFromSolver(mc_solver::QPSolver &solver) override
void supportFoot(const ContactState &foot) noexcept
Definition: StabilizerTask.h:357
std::shared_ptr< mc_tasks::OrientationTask > torsoTask
Definition: StabilizerTask.h:864
void setContacts(const std::vector< ContactState > &contacts)
unsigned int robotIndex_
Definition: StabilizerTask.h:867
void dcmGains(double p, double i, double d) noexcept
Definition: StabilizerTask.h:481
Eigen::VectorXd speed() const override
Returns the task velocity.
stateObservation::LipmDcmEstimator dcmEstimator_
Definition: StabilizerTask.h:917
const std::vector< ExternalWrench > & externalWrenches() const noexcept
Definition: StabilizerTask.h:396
const Eigen::Vector3d & measuredCoMd() noexcept
Definition: StabilizerTask.h:421
const Eigen::Vector3d & targetCoMRaw() const noexcept
Return the raw CoM target as provided by target().
Definition: StabilizerTask.h:330
void dcmDerivatorCutoffPeriod(double T) noexcept
Definition: StabilizerTask.h:499
const Eigen::Vector3d & comOffsetMeasured() const noexcept
Definition: StabilizerTask.h:427
void contactWeight(double weight) noexcept
Definition: StabilizerTask.h:541
void name(const std::string &name) override
Definition: StabilizerTask.h:113
void safetyThresholds(const SafetyThresholds &thresholds) noexcept
Changes the safety thresholds.
Definition: StabilizerTask.h:606
const Eigen::Vector3d & measuredZMP() noexcept
Definition: StabilizerTask.h:417
void dcmBiasEstimatorConfiguration(const DCMBiasEstimatorConfiguration &biasConfig) noexcept
Changes the parameters of the DCM bias estimator.
Definition: StabilizerTask.h:619
void removeFromGUI(mc_rtc::gui::StateBuilder &) override
bool inDoubleSupport() const noexcept
Definition: StabilizerTask.h:433
void copMaxVel(const sva::MotionVecd &copMaxVel) noexcept
Definition: StabilizerTask.h:565
StabilizerConfiguration lastConfig_
Definition: StabilizerTask.h:886
const std::string & footSurface(ContactState s) const
Definition: StabilizerTask.h:263
void update(mc_solver::QPSolver &) override
mc_filter::LowPass< sva::ForceVecd > extWrenchSumLowPass_
Definition: StabilizerTask.h:937
void addToGUI(mc_rtc::gui::StateBuilder &) override
StabilizerConfiguration defaultConfig_
Definition: StabilizerTask.h:884
void dcmGains(const Eigen::Vector2d &p, const Eigen::Vector2d &i, const Eigen::Vector2d &d) noexcept
Definition: StabilizerTask.h:484
void copAdmittance(const Eigen::Vector2d &copAdmittance) noexcept
Definition: StabilizerTask.h:559
void fdqpWeights(const FDQPWeights &fdqp) noexcept
Definition: StabilizerTask.h:595
const Eigen::Vector3d & targetCoMAcceleration() const noexcept
Definition: StabilizerTask.h:345
std::shared_ptr< mc_tasks::OrientationTask > pelvisTask
Definition: StabilizerTask.h:863
const mc_rbdyn::Robot & realRobot() const noexcept
Definition: StabilizerTask.h:437
void reset() override
Resets the stabilizer tasks and parameters to their default configuration.
mc_filter::LowPassCompose< Eigen::Vector3d > dcmDerivator_
Definition: StabilizerTask.h:945
void setContacts(const std::vector< std::pair< ContactState, sva::PTransformd >> &contacts)
Helper to set contacts with a provided target pose.
void dfAdmittance(Eigen::Vector3d dfAdmittance) noexcept
Definition: StabilizerTask.h:589
void commitConfig()
Use the current configuration as the new default.
mc_filter::LowPass< Eigen::Vector3d > fSumFilter_
Definition: StabilizerTask.h:988
void copVelFilterGain(double gain) noexcept
Definition: StabilizerTask.h:576
bool inContact(ContactState state) const noexcept
Definition: StabilizerTask.h:431
void externalWrenchConfiguration(const ExternalWrenchConfiguration &extWrenchConfig) noexcept
Changes the parameters for the external wrenches.
Definition: StabilizerTask.h:637
std::unordered_map< ContactState, std::shared_ptr< mc_tasks::force::CoPTask >, EnumClassHash > footTasks
Definition: StabilizerTask.h:855
const Eigen::Vector3d & targetCoMVelocity() const noexcept
Definition: StabilizerTask.h:342
const Eigen::Vector3d & distribZMP() const noexcept
Definition: StabilizerTask.h:401
const StabilizerConfiguration & config() const
Get current stabilizer's configuration (including changes from GUI/code)
double copVelFilterGain() const noexcept
Definition: StabilizerTask.h:583
void vdcFrequency(double freq) noexcept
Definition: StabilizerTask.h:585
void contactDamping(const sva::MotionVecd &damping) noexcept
Definition: StabilizerTask.h:553
void target(const Eigen::Vector3d &com, const Eigen::Vector3d &comd, const Eigen::Vector3d &comdd, const Eigen::Vector3d &zmp, const Eigen::Vector3d &zmpd=Eigen::Vector3d::Zero())
Provides a dynamic target to the stabilizer.
StabilizerConfiguration disableConfig_
Definition: StabilizerTask.h:888
const Eigen::Vector3d & targetCoM() const noexcept
Returns the CoM target used for stabilization.
Definition: StabilizerTask.h:339
void vdcStiffness(double stiffness) noexcept
Definition: StabilizerTask.h:587
const StabilizerConfiguration & commitedConfig() const
Get last commited configuration.
double leftFootRatio() const noexcept
Interpolation paremeter between left and right foot.
Definition: StabilizerTask.h:270
void setContacts(const ContactDescriptionVector &contacts)
double zmpCoeffMeasured() const noexcept
Definition: StabilizerTask.h:429
mc_filter::LowPass< Eigen::Vector3d > comOffsetLowPass_
Definition: StabilizerTask.h:938
void comOffsetLowPassCoMCutoffPeriod(double cutoffPeriod) noexcept
Definition: StabilizerTask.h:517
void configure(const StabilizerConfiguration &config)
const Eigen::Vector2d biasDCM() noexcept
Definition: StabilizerTask.h:405
const ExternalWrenchConfiguration & externalWrenchConfiguration() const noexcept
Get the parameters for the external wrenches.
Definition: StabilizerTask.h:647
void comOffsetDerivatorTimeConstant(double timeConstant) noexcept
Definition: StabilizerTask.h:523
StabilizerConfiguration c_
Definition: StabilizerTask.h:890
mc_filter::StationaryOffset< Eigen::Vector3d > comOffsetDerivator_
Definition: StabilizerTask.h:941
std::vector< std::string > contactSensors
Definition: StabilizerTask.h:857
void setExternalWrenches(const std::vector< std::string > &surfaceNames, const std::vector< sva::ForceVecd > &targetWrenches, const std::vector< sva::MotionVecd > &gains)
Set the wrench that the robot expects to receive from the external contacts.
void pelvisWeight(double weight) noexcept
Definition: StabilizerTask.h:469
mc_filter::ExponentialMovingAverage< Eigen::Vector3d > dcmIntegrator_
Definition: StabilizerTask.h:944
void checkConfiguration(const StabilizerConfiguration &config)
void comStiffness(const Eigen::Vector3d &stiffness) noexcept
Definition: StabilizerTask.h:535
std::unordered_map< ContactState, internal::Contact, EnumClassHash, std::equal_to< ContactState >, Eigen::aligned_allocator< std::pair< const ContactState, internal::Contact > > > contacts_
Definition: StabilizerTask.h:853
sva::PTransformd anchorFrame(const mc_rbdyn::Robot &robot) const
computes the anchorFrame compatible with the state observers (e.g KinematicInertial)
const mc_rbdyn::Robots & robots_
Definition: StabilizerTask.h:865
void dcmIntegratorTimeConstant(double dcmIntegratorTimeConstant) noexcept
Definition: StabilizerTask.h:491
std::vector< std::shared_ptr< mc_tasks::force::CoPTask > > contactTasks
Definition: StabilizerTask.h:856
void addToSolver(mc_solver::QPSolver &solver) override
mc_filter::LowPass< Eigen::Vector3d > comOffsetLowPassCoM_
Definition: StabilizerTask.h:940
StabilizerTask(const mc_rbdyn::Robots &robots, const mc_rbdyn::Robots &realRobots, unsigned int robotIndex, double dt)
Creates a stabilizer meta task.
const DCMBiasEstimatorConfiguration & dcmBiasEstimatorConfiguration() const noexcept
Get parameters of the DCM bias estimator.
Definition: StabilizerTask.h:630
const Eigen::Vector3d & measuredCoM() noexcept
Definition: StabilizerTask.h:419
std::vector< std::vector< Eigen::Vector3d > > supportPolygons_
Definition: StabilizerTask.h:859
const mc_rbdyn::Robot & robot() const noexcept
Definition: StabilizerTask.h:435
void torsoWeight(double weight) noexcept
Definition: StabilizerTask.h:457
const Eigen::Vector3d & measuredFilteredNetForces() const noexcept
Definition: StabilizerTask.h:423
void dfDamping(Eigen::Vector3d dfDamping) noexcept
Definition: StabilizerTask.h:592
Eigen::VectorXd eval() const override
Returns the task error.
void torsoPitch(double pitch) noexcept
Definition: StabilizerTask.h:453
void extWrenchSumLowPassCutoffPeriod(double cutoffPeriod) noexcept
Definition: StabilizerTask.h:505
MC_RTC_DEPRECATED void dcmDerivatorTimeConstant(double T) noexcept
Definition: StabilizerTask.h:497
void comOffsetLowPassCutoffPeriod(double cutoffPeriod) noexcept
Definition: StabilizerTask.h:511
const Eigen::Vector3d & measuredDCM() noexcept
Definition: StabilizerTask.h:403
void load(mc_solver::QPSolver &, const mc_rtc::Configuration &config) override
Load targets and contacts from configuration.
std::vector< Eigen::Vector2d > horizonZmpRef_
Definition: StabilizerTask.h:964
void staticTarget(const Eigen::Vector3d &com, double zmpHeight=0)
const Eigen::Vector3d & targetZMPVelocity() const noexcept
Definition: StabilizerTask.h:351
void horizonReference(const std::vector< Eigen::Vector2d > &ref, const double delta) noexcept
Set the reference zmp sequence to distribute between the CoP task (Only in double support)
Definition: StabilizerTask.h:368
std::vector< ContactState > addContacts_
Definition: StabilizerTask.h:854
void comWeight(double weight) noexcept
Definition: StabilizerTask.h:529
const Eigen::Vector3d & targetZMP() const noexcept
Definition: StabilizerTask.h:348
ContactState supportFoot() const noexcept
Definition: StabilizerTask.h:354
StabilizerTask(const mc_rbdyn::Robots &robots, const mc_rbdyn::Robots &realRobots, unsigned int robotIndex, const std::string &leftSurface, const std::string &rightSurface, const std::string &torsoBodyName, double dt)
Creates a stabilizer meta task.
Definition: ZMPCC.h:31