FootstepPlan.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 <lipm_walking/Contact.h>
31 #include <lipm_walking/Sole.h>
33 #include <string>
34 
35 namespace mc_rtc
36 {
37 namespace gui
38 {
39 struct StateBuilder;
40 }
41 } // namespace mc_rtc
42 
43 namespace lipm_walking
44 {
45 
50 {
51  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
52 
58  void complete(const Sole & sole);
59 
65  sva::PTransformd computeInitialTransform(const mc_rbdyn::Robot & robot) const;
66 
70  void goToNextFootstep();
71 
78  void goToNextFootstep(const sva::PTransformd & actualTargetPose);
79 
85  void load(const mc_rtc::Configuration & config);
86 
92  void reset(unsigned startIndex);
93 
100 
106  void save(mc_rtc::Configuration & config) const;
107 
117  void updateInitialTransform(const sva::PTransformd & X_0_lf, const sva::PTransformd & X_0_rf, double initHeight);
118 
123  {
124  contacts_.push_back(step);
125  }
126 
130  double comHeight() const
131  {
132  return comHeight_;
133  }
134 
138  void comHeight(double height)
139  {
140  comHeight_ = clamp(height, 0., 2.);
141  }
142 
146  const std::vector<Contact> & contacts() const
147  {
148  return contacts_;
149  }
150 
154  double doubleSupportDuration() const
155  {
156  return doubleSupportDuration_;
157  }
158 
164  void doubleSupportDuration(double duration)
165  {
166  doubleSupportDuration_ = clamp(duration, 0., 1.);
167  }
168 
172  double finalDSPDuration() const
173  {
174  return finalDSPDuration_;
175  }
176 
180  bool hasTorsoPitch() const
181  {
182  return (torsoPitch_ > -10.);
183  }
184 
190  void finalDSPDuration(double duration)
191  {
192  finalDSPDuration_ = clamp(duration, 0.1, 1.6);
193  }
194 
198  double initDSPDuration() const
199  {
200  return initDSPDuration_;
201  }
202 
206  void initDSPDuration(double duration)
207  {
208  initDSPDuration_ = clamp(duration, 0.1, 1.6);
209  }
210 
216  const sva::PTransformd & initPose()
217  {
218  return X_0_init_;
219  }
220 
224  double landingDuration() const
225  {
226  if(supportContact_.swingConfig.has("landing_duration"))
227  {
228  return supportContact_.swingConfig("landing_duration");
229  }
230  return landingDuration_;
231  }
232 
238  void landingDuration(double duration)
239  {
240  landingDuration_ = clamp(duration, 0., 0.5);
241  }
242 
246  double landingPitch() const
247  {
248  if(prevContact_.swingConfig.has("landing_pitch"))
249  {
250  return prevContact_.swingConfig("landing_pitch");
251  }
252  return landingPitch_;
253  }
254 
258  void landingPitch(double pitch)
259  {
260  constexpr double MIN_LANDING_PITCH = -1.;
261  constexpr double MAX_LANDING_PITCH = 1.;
262  landingPitch_ = clamp(pitch, MIN_LANDING_PITCH, MAX_LANDING_PITCH);
263  }
264 
268  const Contact & nextContact() const
269  {
270  return nextContact_;
271  }
272 
276  const Contact & prevContact() const
277  {
278  return prevContact_;
279  }
280 
286  void resetContacts(const std::vector<Contact> & contacts)
287  {
288  contacts_ = contacts;
289  }
290 
294  double singleSupportDuration() const
295  {
296  return singleSupportDuration_;
297  }
298 
302  void singleSupportDuration(double duration)
303  {
304  singleSupportDuration_ = clamp(duration, 0., 2.);
305  }
306 
310  const Contact & supportContact() const
311  {
312  return supportContact_;
313  }
314 
319  {
320  std::swap(contacts_[0], contacts_[1]);
321  }
322 
326  double swingHeight() const
327  {
328  if(prevContact_.swingConfig.has("height"))
329  {
330  return prevContact_.swingConfig("height");
331  }
332  return swingHeight_;
333  }
334 
338  void swingHeight(double height)
339  {
340  constexpr double MIN_SWING_FOOT_HEIGHT = 0.;
341  constexpr double MAX_SWING_FOOT_HEIGHT = 0.25;
342  swingHeight_ = clamp(height, MIN_SWING_FOOT_HEIGHT, MAX_SWING_FOOT_HEIGHT);
343  }
344 
348  double takeoffDuration() const
349  {
350  if(supportContact_.swingConfig.has("takeoff_duration"))
351  {
352  return supportContact_.swingConfig("takeoff_duration");
353  }
354  return takeoffDuration_;
355  }
356 
362  void takeoffDuration(double duration)
363  {
364  takeoffDuration_ = clamp(duration, 0., 0.5);
365  }
366 
370  Eigen::Vector3d takeoffOffset() const
371  {
372  if(prevContact_.swingConfig.has("takeoff_offset"))
373  {
374  return prevContact_.swingConfig("takeoff_offset");
375  }
376  return takeoffOffset_;
377  }
378 
382  void takeoffOffset(const Eigen::Vector3d & offset)
383  {
384  takeoffOffset_ = offset;
385  }
386 
390  double takeoffPitch() const
391  {
392  if(prevContact_.swingConfig.has("takeoff_pitch"))
393  {
394  return prevContact_.swingConfig("takeoff_pitch");
395  }
396  return takeoffPitch_;
397  }
398 
402  void takeoffPitch(double pitch)
403  {
404  constexpr double MIN_TAKEOFF_PITCH = -1.;
405  constexpr double MAX_TAKEOFF_PITCH = 1.;
406  takeoffPitch_ = clamp(pitch, MIN_TAKEOFF_PITCH, MAX_TAKEOFF_PITCH);
407  }
408 
412  const Contact & targetContact() const
413  {
414  return targetContact_;
415  }
416 
420  double torsoPitch() const
421  {
422  return torsoPitch_;
423  }
424 
426  void torsoPitch(double tp)
427  {
428  torsoPitch_ = tp;
429  }
430 
434  void rewind()
435  {
436  reset(0);
437  }
438 
444  void addGUIElements(mc_rtc::gui::StateBuilder & gui);
445 
449  void removeGUIElements(mc_rtc::gui::StateBuilder & gui);
450 
451 public:
452  mc_rtc::Configuration mpcConfig;
453  std::string name = "";
454 
455 private:
456  Contact nextContact_;
457  Contact prevContact_;
458  Contact supportContact_;
459  Contact targetContact_;
460  Eigen::Vector3d takeoffOffset_ = Eigen::Vector3d::Zero(); // [m]
461  double comHeight_ = 0.8; // [m]
462  double doubleSupportDuration_ = 0.2; // [s]
463  double finalDSPDuration_ = 0.6; // [s]
464  double initDSPDuration_ = 0.6; // [s]
465  double landingDuration_ = 0.15; // [s]
466  double landingPitch_ = 0.;
467  double singleSupportDuration_ = 0.8; // [s]
468  double swingHeight_ = 0.04; // [m]
469  double takeoffDuration_ = 0.05; // [s]
470  double takeoffPitch_ = 0.;
471  double torsoPitch_ = -100.;
472  std::vector<Contact> contacts_;
473  sva::PTransformd X_0_init_;
474  unsigned nextFootstep_ = 0;
475 };
476 } // namespace lipm_walking
477 
478 namespace mc_rtc
479 {
480 template<>
481 struct ConfigurationLoader<lipm_walking::FootstepPlan>
482 {
483  static lipm_walking::FootstepPlan load(const mc_rtc::Configuration & config)
484  {
486  plan.load(config);
487  return plan;
488  }
489 
490  static mc_rtc::Configuration save(const lipm_walking::FootstepPlan & plan)
491  {
492  mc_rtc::Configuration config;
493  plan.save(config);
494  return config;
495  }
496 };
497 
498 } // namespace mc_rtc
double clamp(double v, double vMin, double vMax)
Definition: clamp.h:47
mc_rtc::Configuration swingConfig
Definition: Contact.h:312
double landingDuration() const
Definition: FootstepPlan.h:224
double landingPitch() const
Definition: FootstepPlan.h:246
void initDSPDuration(double duration)
Definition: FootstepPlan.h:206
double takeoffPitch() const
Definition: FootstepPlan.h:390
mc_rtc::Configuration mpcConfig
Definition: FootstepPlan.h:452
void takeoffPitch(double pitch)
Definition: FootstepPlan.h:402
void reset(unsigned startIndex)
double doubleSupportDuration() const
Definition: FootstepPlan.h:154
void finalDSPDuration(double duration)
Definition: FootstepPlan.h:190
void doubleSupportDuration(double duration)
Definition: FootstepPlan.h:164
void landingDuration(double duration)
Definition: FootstepPlan.h:238
void addGUIElements(mc_rtc::gui::StateBuilder &gui)
Display the footstep plan in the GUI.
void updateInitialTransform(const sva::PTransformd &X_0_lf, const sva::PTransformd &X_0_rf, double initHeight)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW void complete(const Sole &sole)
void swingHeight(double height)
Definition: FootstepPlan.h:338
void load(const mc_rtc::Configuration &config)
double singleSupportDuration() const
Definition: FootstepPlan.h:294
const Contact & targetContact() const
Definition: FootstepPlan.h:412
double swingHeight() const
Definition: FootstepPlan.h:326
void comHeight(double height)
Definition: FootstepPlan.h:138
const sva::PTransformd & initPose()
Definition: FootstepPlan.h:216
const std::vector< Contact > & contacts() const
Definition: FootstepPlan.h:146
double takeoffDuration() const
Definition: FootstepPlan.h:348
void resetContacts(const std::vector< Contact > &contacts)
Definition: FootstepPlan.h:286
Eigen::Vector3d takeoffOffset() const
Definition: FootstepPlan.h:370
void landingPitch(double pitch)
Definition: FootstepPlan.h:258
void takeoffDuration(double duration)
Definition: FootstepPlan.h:362
void singleSupportDuration(double duration)
Definition: FootstepPlan.h:302
const Contact & nextContact() const
Definition: FootstepPlan.h:268
void save(mc_rtc::Configuration &config) const
void appendContact(Contact step)
Definition: FootstepPlan.h:122
void takeoffOffset(const Eigen::Vector3d &offset)
Definition: FootstepPlan.h:382
double initDSPDuration() const
Definition: FootstepPlan.h:198
sva::PTransformd computeInitialTransform(const mc_rbdyn::Robot &robot) const
double finalDSPDuration() const
Definition: FootstepPlan.h:172
void torsoPitch(double tp)
Definition: FootstepPlan.h:426
const Contact & supportContact() const
Definition: FootstepPlan.h:310
const Contact & prevContact() const
Definition: FootstepPlan.h:276
void removeGUIElements(mc_rtc::gui::StateBuilder &gui)
Remove the footstep plan from the GUI.
static lipm_walking::FootstepPlan load(const mc_rtc::Configuration &config)
Definition: FootstepPlan.h:483
static mc_rtc::Configuration save(const lipm_walking::FootstepPlan &plan)
Definition: FootstepPlan.h:490