PlanInterpolator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019, CNRS-UM LIRMM
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
30 #include <mc_rbdyn/rpy_utils.h>
31 #include <mc_rtc/GUIState.h>
32 
36 
37 namespace lipm_walking
38 {
39 
44 {
45  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
46 
47  static constexpr double DEFAULT_EXTRA_STEP_WIDTH = 0.; // [m]
48  static constexpr double IN_PLACE_EXTRA_STEP_WIDTH = 0.02; // [m]
49  static constexpr double IN_PLACE_MAX_STEP_ANGLE = 45.; // [deg]
50  static constexpr double MAX_EXTRA_STEP_WIDTH = 0.05; // [m]
51  static constexpr double MAX_LATERAL_STEP_LENGTH = 0.2; // [m]
52  static constexpr double MAX_SAGITTAL_STEP_LENGTH = 0.4; // [m]
53  static constexpr double MIN_STEP_LENGTH = 0.001; // [m]
54 
63  enum class Gait
64  {
65  Walk,
66  Shuffle,
67  Turn
68  };
69 
75  PlanInterpolator(std::shared_ptr<mc_rtc::gui::StateBuilder> gui) : gui_(gui) {}
76 
80  void addGUIElements();
81 
87  void configure(const mc_rtc::Configuration & config);
88 
92  void removeGUIElements();
93 
97  void run();
98 
102  void suggestGait();
103 
111  void updateSupportPath(const sva::PTransformd & X_0_lf, const sva::PTransformd & X_0_rf);
112 
118  std::vector<std::string> availablePlans() const
119  {
120  return plans_.keys();
121  }
122 
128  const std::string & customPlanName() const
129  {
130  return customPlan_.name;
131  }
132 
138  std::string gait() const
139  {
140  if(gait_ == Gait::Shuffle)
141  {
142  return "Shuffle";
143  }
144  else if(gait_ == Gait::Turn)
145  {
146  return "Turn";
147  }
148  else // (gait_ == Gait::Walk)
149  {
150  return "Walk";
151  }
152  }
153 
159  void gait(const std::string & dir)
160  {
161  if(dir == "Shuffle")
162  {
163  extraStepWidth_ = DEFAULT_EXTRA_STEP_WIDTH;
164  gait_ = Gait::Shuffle;
165  }
166  else if(dir == "Turn")
167  {
168  extraStepWidth_ = IN_PLACE_EXTRA_STEP_WIDTH;
169  gait_ = Gait::Turn;
170  targetPose_.x = 0.;
171  targetPose_.y = 0.;
172  }
173  else // (dir == "Walk")
174  {
175  extraStepWidth_ = DEFAULT_EXTRA_STEP_WIDTH;
176  gait_ = Gait::Walk;
177  }
178  run();
179  }
180 
186  FootstepPlan getPlan(std::string name)
187  {
188  if(name == customPlan_.name)
189  {
190  return customPlan_;
191  }
192  else // pre-defined plans
193  {
194  return plans_(name);
195  }
196  }
197 
202  {
203  gait_ = Gait::Walk;
204  targetPose_ = lastBackwardTarget_;
205  run();
206  }
207 
212  {
213  gait_ = Gait::Walk;
214  targetPose_ = lastForwardTarget_;
215  run();
216  }
217 
222  {
223  gait_ = Gait::Shuffle;
224  targetPose_ = lastLateralTarget_;
225  run();
226  }
227 
233  double stepWidth() const
234  {
235  return stepWidth_;
236  }
237 
247  void stepWidth(double stepWidth)
248  {
249  stepWidth_ = stepWidth;
250  }
251 
255  const sva::PTransformd & worldReference() const
256  {
257  return worldReference_;
258  }
259 
265  void worldReference(const sva::PTransformd & worldReference)
266  {
267  worldReference_ = worldReference;
268  }
269 
270 private:
274  void restoreDefaults();
275 
281  void runShuffling_();
282 
288  void runTurning_();
289 
295  void runWalking_();
296 
302  void updateLocalTarget_(const SE2d & target);
303 
309  void updateWorldTarget_(const Eigen::Vector3d & desired);
310 
311 public:
312  bool isShown = false;
313  unsigned nbIter = 0;
315 private:
316  FootstepPlan customPlan_;
317  Gait gait_ = Gait::Walk;
319  SE2d initPose_ = {0., 0., 0.};
320  SE2d lastBackwardTarget_ = {-0.5, 0., 0.};
321  SE2d lastForwardTarget_ = {0.5, 0., 0.};
322  SE2d lastLateralTarget_ = {0.0, 0.3, 0.};
323  SE2d targetPose_ = {0.5, 0., 0.};
324  bool startWithRightFootstep_ = true;
325  double desiredStepAngle_ = 10. * M_PI / 180.; // [rad]
326  double desiredStepLength_ = 0.2; // [m]
327  double extraStepWidth_ = 0.; // [m]
328  double outputVel_ = 0.25; // [m] / [s]
329  double stepAngle_ = 0.0; // [deg]
330  double stepLength_ = 0.2;
331  double stepWidth_ = 0.18; // [m], default value is for HRP-4
332  mc_rtc::Configuration plans_;
333  std::shared_ptr<mc_rtc::gui::StateBuilder> gui_;
334  std::vector<Eigen::Vector3d> supportPathDisplay_;
335  sva::PTransformd worldReference_;
336  unsigned nbFootsteps_ = 0;
337 };
338 
339 } // namespace lipm_walking
Hermite polynomial with Overall Uniformly-Bounded Accelerations (HOUBA).
Definition: polynomials.h:340
void removeGUIElements()
Remove GUI panel.
void addGUIElements()
Add GUI panel.
void updateSupportPath(const sva::PTransformd &X_0_lf, const sva::PTransformd &X_0_rf)
Update support path display.
std::string gait() const
Get current gait as string.
PlanInterpolator(std::shared_ptr< mc_rtc::gui::StateBuilder > gui)
Initialization just stores the GUI handle for later.
static constexpr double MAX_SAGITTAL_STEP_LENGTH
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW constexpr double DEFAULT_EXTRA_STEP_WIDTH
void configure(const mc_rtc::Configuration &config)
Read configuration from dictionary.
Footstep plan interpolator.
static constexpr double IN_PLACE_EXTRA_STEP_WIDTH
void restoreForwardTarget()
Restore last forward target.
void restoreLateralTarget()
Restore last lateral target.
void gait(const std::string &dir)
Update gait.
bool isShown
Is the footstep interpolator tab displayed?
unsigned nbIter
Number of times the interpolator was called.
void restoreBackwardTarget()
Restore last backward target.
FootstepPlan getPlan(std::string name)
Get contact plan.
double stepWidth() const
Get step width.
static constexpr double MAX_EXTRA_STEP_WIDTH
void worldReference(const sva::PTransformd &worldReference)
Set walking target in world frame.
Main controller namespace.
Definition: build.dox:1
SE2 transform.
Definition: SE2d.h:40
void run()
Generate a new footstep plan.
std::vector< std::string > availablePlans() const
List available contact plans.
void suggestGait()
Suggest gait based on local target coordinates.
Sequence of footsteps with gait parameters.
Definition: FootstepPlan.h:41
static constexpr double IN_PLACE_MAX_STEP_ANGLE
static constexpr double MIN_STEP_LENGTH
const std::string & customPlanName() const
Get name of current custom footstep plan.
void stepWidth(double stepWidth)
Set step width.
const sva::PTransformd & worldReference() const
Get walking target in world frame.
static constexpr double MAX_LATERAL_STEP_LENGTH