38 auto Fzs = ctl.robot().frame(ctl.prevContact().surfaceName).wrench().force().z();
39 auto Fzt = ctl.robot().frame(ctl.nextContact().surfaceName).wrench().force().z();
40 return Fzs >= minSupportForce_ && Fzt >= minSupportForce_ && goodInitialSupport_;
45 auto & ctl = controller();
49 ctl.plan.resetContacts(ctl.externalFootstepPlanner.plan());
50 ctl.updatePlan(
"external");
54 mc_rtc::log::warning(
"[{}] An external plan was requested for this DSP but is not available, pause walking",
56 ctl.externalFootstepPlanner.cancelRequest();
57 stopDuringThisDSP_ =
true;
58 ctl.pauseWalking =
true;
64 auto & ctl = controller();
67 double phaseDuration = ctl.doubleSupportDuration();
69 duration_ = phaseDuration;
70 initLeftFootRatio_ = ctl.leftFootRatio();
71 if(phaseDuration <= ctl.timeStep)
73 mc_rtc::log::error_and_throw<std::invalid_argument>(
"[{}] The double support phase duration cannot be "
74 "less than the controller's timestep (requested {} <= {})",
75 name(), duration_, ctl.timeStep);
79 stopDuringThisDSP_ = ctl.pauseWalking;
80 if(phaseDuration > ctl.timeStep)
86 timeSinceLastPreviewUpdate_ = 0.;
89 if(ctl.plan.name ==
"external")
94 const std::string & targetSurfaceName = ctl.targetContact().surfaceName;
95 auto actualTargetPose = ctl.controlRobot().surfacePose(targetSurfaceName);
96 ctl.plan.goToNextFootstep(actualTargetPose);
100 stopDuringThisDSP_ =
true;
103 if(ctl.prevContact().surfaceName ==
"LeftFootCenter")
105 ctl.setContacts({{ContactState::Left, ctl.prevContact().pose}, {ContactState::Right, ctl.supportContact().pose}});
106 targetLeftFootRatio_ = 0.;
110 ctl.setContacts({{ContactState::Left, ctl.supportContact().pose}, {ContactState::Right, ctl.prevContact().pose}});
111 targetLeftFootRatio_ = 1.;
114 if(!ctl.isInOpenLoopTicker() && stateTime_ <= maxAbortPercent_ * duration_ && !checkInitialSupport())
116 mc_rtc::log::warning(
"[DoubleSupport] Stepping aborted at t = {}, poor contact detected!", stateTime_);
117 mc_rtc::log::info(
"[DoubleSupport] Stopping during this DSP, remaining time: {}", remTime_);
118 stopDuringThisDSP_ =
true;
121 if(stopDuringThisDSP_)
123 targetLeftFootRatio_ = 0.5;
126 logger().addLogEntry(
"rem_phase_time", [
this]() {
return remTime_; });
127 logger().addLogEntry(
"walking_phase", []() {
return 2.; });
134 logger().removeLogEntry(
"rem_phase_time");
135 logger().removeLogEntry(
"walking_phase");
140 auto & ctl = controller();
141 double dt = ctl.timeStep;
149 double x =
clamp(remTime_ / duration_, 0., 1.);
150 ctl.leftFootRatio(x * initLeftFootRatio_ + (1. - x) * targetLeftFootRatio_);
152 ctl.preview->integrate(pendulum(), dt);
153 pendulum().completeIPM(ctl.prevContact().p(), ctl.prevContact().normal());
154 pendulum().resetCoMHeight(ctl.plan.comHeight(), ctl.prevContact().p(), ctl.prevContact().normal());
155 controller().stabilizer()->target(pendulum().com(), pendulum().comd(), pendulum().comdd(), pendulum().zmp());
159 timeSinceLastPreviewUpdate_ += dt;
164 auto & ctl = controller();
166 if(!stopDuringThisDSP_ && remTime_ < 0.)
168 output(
"SingleSupport");
171 if(stopDuringThisDSP_ && remTime_ < -0.5)
175 ctl.plan.restorePreviousFootstep();
185 auto & ctl = controller();
186 ctl.mpc().contacts(ctl.prevContact(), ctl.supportContact(), ctl.targetContact());
187 if(stopDuringThisDSP_)
189 ctl.mpc().phaseDurations(0., remTime_, 0.);
193 ctl.mpc().phaseDurations(0., remTime_, ctl.singleSupportDuration());
195 if(ctl.updatePreview())
197 timeSinceLastPreviewUpdate_ = 0.;
201 mc_rtc::log::warning(
"No capture trajectory, resuming walking");
202 stopDuringThisDSP_ =
false;
mc_tasks::lipm_stabilizer::ContactState ContactState
constexpr double PREVIEW_UPDATE_PERIOD
double clamp(double v, double vMin, double vMax)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Controller & controller()
bool checkInitialSupport()
bool checkTransitions() override
void handleExternalPlan()