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 lipm_walking
36 {
37 
42 {
43  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
44 
50  void complete(const Sole & sole);
51 
57  sva::PTransformd computeInitialTransform(const mc_rbdyn::Robot & robot) const;
58 
62  void goToNextFootstep();
63 
70  void goToNextFootstep(const sva::PTransformd & actualTargetPose);
71 
77  void load(const mc_rtc::Configuration & config);
78 
84  void reset(unsigned startIndex);
85 
92 
98  void save(mc_rtc::Configuration & config) const;
99 
109  void updateInitialTransform(const sva::PTransformd & X_0_lf, const sva::PTransformd & X_0_rf, double initHeight);
110 
115  {
116  contacts_.push_back(step);
117  }
118 
122  double comHeight() const
123  {
124  return comHeight_;
125  }
126 
130  void comHeight(double height)
131  {
132  comHeight_ = clamp(height, 0., 2.);
133  }
134 
138  const std::vector<Contact> & contacts() const
139  {
140  return contacts_;
141  }
142 
146  double doubleSupportDuration() const
147  {
148  return doubleSupportDuration_;
149  }
150 
156  void doubleSupportDuration(double duration)
157  {
158  doubleSupportDuration_ = clamp(duration, 0., 1.);
159  }
160 
164  double finalDSPDuration() const
165  {
166  return finalDSPDuration_;
167  }
168 
172  bool hasTorsoPitch() const
173  {
174  return (torsoPitch_ > -10.);
175  }
176 
182  void finalDSPDuration(double duration)
183  {
184  finalDSPDuration_ = clamp(duration, 0.1, 1.6);
185  }
186 
190  double initDSPDuration() const
191  {
192  return initDSPDuration_;
193  }
194 
198  void initDSPDuration(double duration)
199  {
200  initDSPDuration_ = clamp(duration, 0.1, 1.6);
201  }
202 
208  const sva::PTransformd & initPose()
209  {
210  return X_0_init_;
211  }
212 
216  double landingDuration() const
217  {
218  if(supportContact_.swingConfig.has("landing_duration"))
219  {
220  return supportContact_.swingConfig("landing_duration");
221  }
222  return landingDuration_;
223  }
224 
230  void landingDuration(double duration)
231  {
232  landingDuration_ = clamp(duration, 0., 0.5);
233  }
234 
238  double landingPitch() const
239  {
240  if(prevContact_.swingConfig.has("landing_pitch"))
241  {
242  return prevContact_.swingConfig("landing_pitch");
243  }
244  return landingPitch_;
245  }
246 
250  void landingPitch(double pitch)
251  {
252  constexpr double MIN_LANDING_PITCH = -1.;
253  constexpr double MAX_LANDING_PITCH = 1.;
254  landingPitch_ = clamp(pitch, MIN_LANDING_PITCH, MAX_LANDING_PITCH);
255  }
256 
260  const Contact & nextContact() const
261  {
262  return nextContact_;
263  }
264 
268  const Contact & prevContact() const
269  {
270  return prevContact_;
271  }
272 
278  void resetContacts(const std::vector<Contact> & contacts)
279  {
280  contacts_ = contacts;
281  }
282 
286  double singleSupportDuration() const
287  {
288  return singleSupportDuration_;
289  }
290 
294  void singleSupportDuration(double duration)
295  {
296  singleSupportDuration_ = clamp(duration, 0., 2.);
297  }
298 
302  const Contact & supportContact() const
303  {
304  return supportContact_;
305  }
306 
311  {
312  std::swap(contacts_[0], contacts_[1]);
313  }
314 
318  double swingHeight() const
319  {
320  if(prevContact_.swingConfig.has("height"))
321  {
322  return prevContact_.swingConfig("height");
323  }
324  return swingHeight_;
325  }
326 
330  void swingHeight(double height)
331  {
332  constexpr double MIN_SWING_FOOT_HEIGHT = 0.;
333  constexpr double MAX_SWING_FOOT_HEIGHT = 0.25;
334  swingHeight_ = clamp(height, MIN_SWING_FOOT_HEIGHT, MAX_SWING_FOOT_HEIGHT);
335  }
336 
340  double takeoffDuration() const
341  {
342  if(supportContact_.swingConfig.has("takeoff_duration"))
343  {
344  return supportContact_.swingConfig("takeoff_duration");
345  }
346  return takeoffDuration_;
347  }
348 
354  void takeoffDuration(double duration)
355  {
356  takeoffDuration_ = clamp(duration, 0., 0.5);
357  }
358 
362  Eigen::Vector3d takeoffOffset() const
363  {
364  if(prevContact_.swingConfig.has("takeoff_offset"))
365  {
366  return prevContact_.swingConfig("takeoff_offset");
367  }
368  return takeoffOffset_;
369  }
370 
374  void takeoffOffset(const Eigen::Vector3d & offset)
375  {
376  takeoffOffset_ = offset;
377  }
378 
382  double takeoffPitch() const
383  {
384  if(prevContact_.swingConfig.has("takeoff_pitch"))
385  {
386  return prevContact_.swingConfig("takeoff_pitch");
387  }
388  return takeoffPitch_;
389  }
390 
394  void takeoffPitch(double pitch)
395  {
396  constexpr double MIN_TAKEOFF_PITCH = -1.;
397  constexpr double MAX_TAKEOFF_PITCH = 1.;
398  takeoffPitch_ = clamp(pitch, MIN_TAKEOFF_PITCH, MAX_TAKEOFF_PITCH);
399  }
400 
404  const Contact & targetContact() const
405  {
406  return targetContact_;
407  }
408 
412  double torsoPitch() const
413  {
414  return torsoPitch_;
415  }
416 
420  void rewind()
421  {
422  reset(0);
423  }
424 
425 public:
426  mc_rtc::Configuration mpcConfig;
427  std::string name = "";
428 
429 private:
430  Contact nextContact_;
431  Contact prevContact_;
432  Contact supportContact_;
433  Contact targetContact_;
434  Eigen::Vector3d takeoffOffset_ = Eigen::Vector3d::Zero(); // [m]
435  double comHeight_ = 0.8; // [m]
436  double doubleSupportDuration_ = 0.2; // [s]
437  double finalDSPDuration_ = 0.6; // [s]
438  double initDSPDuration_ = 0.6; // [s]
439  double landingDuration_ = 0.15; // [s]
440  double landingPitch_ = 0.;
441  double singleSupportDuration_ = 0.8; // [s]
442  double swingHeight_ = 0.04; // [m]
443  double takeoffDuration_ = 0.05; // [s]
444  double takeoffPitch_ = 0.;
445  double torsoPitch_ = -100.;
446  std::vector<Contact> contacts_;
447  sva::PTransformd X_0_init_;
448  unsigned nextFootstep_ = 0;
449 };
450 } // namespace lipm_walking
451 
452 namespace mc_rtc
453 {
454 template<>
455 struct ConfigurationLoader<lipm_walking::FootstepPlan>
456 {
457  static lipm_walking::FootstepPlan load(const mc_rtc::Configuration & config)
458  {
460  plan.load(config);
461  return plan;
462  }
463 
464  static mc_rtc::Configuration save(const lipm_walking::FootstepPlan & plan)
465  {
466  mc_rtc::Configuration config;
467  plan.save(config);
468  return config;
469  }
470 };
471 
472 } // namespace mc_rtc
double clamp(double v, double vMin, double vMax)
Clamp a value in a given interval.
Definition: clamp.h:47
const Contact & prevContact() const
Previous contact in plan.
Definition: FootstepPlan.h:268
double finalDSPDuration() const
Get final double support phase duration.
Definition: FootstepPlan.h:164
double initDSPDuration() const
Get initial double support phase duration.
Definition: FootstepPlan.h:190
double takeoffPitch() const
Get swing foot takeoff pitch angle.
Definition: FootstepPlan.h:382
void load(const mc_rtc::Configuration &config)
Load plan from configuration dictionary.
double swingHeight() const
Default swing-foot height.
Definition: FootstepPlan.h:318
void goToNextFootstep()
Advance to next footstep in plan.
void updateInitialTransform(const sva::PTransformd &X_0_lf, const sva::PTransformd &X_0_rf, double initHeight)
Update plan coordinates from robot foot transforms.
void landingDuration(double duration)
Set swing foot landing duration.
Definition: FootstepPlan.h:230
void doubleSupportDuration(double duration)
Set default double-support duration.
Definition: FootstepPlan.h:156
Framework namespace, only used to add a configuration loader.
Definition: Contact.h:340
void takeoffDuration(double duration)
Set swing foot takeoff duration.
Definition: FootstepPlan.h:354
double comHeight() const
Default CoM height above ground contact.
Definition: FootstepPlan.h:122
sva::PTransformd computeInitialTransform(const mc_rbdyn::Robot &robot) const
Compute initial floating-base transform over first contact.
const Contact & supportContact() const
Current support contact.
Definition: FootstepPlan.h:302
void rewind()
Rewind plan to the beginning.
Definition: FootstepPlan.h:420
const Contact & nextContact() const
Next contact in plan.
Definition: FootstepPlan.h:260
void swingHeight(double height)
Set default swing-foot height.
Definition: FootstepPlan.h:330
void resetContacts(const std::vector< Contact > &contacts)
Reset contacts from another footstep plan.
Definition: FootstepPlan.h:278
void takeoffOffset(const Eigen::Vector3d &offset)
Set swing foot takeoff offset.
Definition: FootstepPlan.h:374
mc_rtc::Configuration mpcConfig
Definition: FootstepPlan.h:426
void finalDSPDuration(double duration)
Set final double support phase duration.
Definition: FootstepPlan.h:182
mc_rtc::Configuration swingConfig
Additional configuration for swing foot trajectories that originate from this contact.
Definition: Contact.h:319
static mc_rtc::Configuration save(const lipm_walking::FootstepPlan &plan)
Definition: FootstepPlan.h:464
const Contact & targetContact() const
Current target contact.
Definition: FootstepPlan.h:404
double singleSupportDuration() const
Default single-support duration.
Definition: FootstepPlan.h:286
void restorePreviousFootstep()
Rewind one footstep back in plan.
double takeoffDuration() const
Get swing foot takeoff duration.
Definition: FootstepPlan.h:340
Main controller namespace.
Definition: build.dox:1
void reset(unsigned startIndex)
Rewind plan to a given contact.
const sva::PTransformd & initPose()
Initial transform with respect to world frame.
Definition: FootstepPlan.h:208
EIGEN_MAKE_ALIGNED_OPERATOR_NEW void complete(const Sole &sole)
Complete contacts from sole parameters.
bool hasTorsoPitch() const
Does the plan provide a reference torso pitch?
Definition: FootstepPlan.h:172
double doubleSupportDuration() const
Default double-support duration.
Definition: FootstepPlan.h:146
Contacts wrap foot frames with extra info from the footstep plan.
Definition: Contact.h:58
void landingPitch(double pitch)
Set swing foot takeoff pitch angle.
Definition: FootstepPlan.h:250
void singleSupportDuration(double duration)
Set single-support duration.
Definition: FootstepPlan.h:294
Foot sole properties.
Definition: Sole.h:38
static lipm_walking::FootstepPlan load(const mc_rtc::Configuration &config)
Definition: FootstepPlan.h:457
double landingPitch() const
Get swing foot landing pitch angle.
Definition: FootstepPlan.h:238
Eigen::Vector3d takeoffOffset() const
Get swing foot takeoff offset.
Definition: FootstepPlan.h:362
void initDSPDuration(double duration)
Set initial double support phase duration.
Definition: FootstepPlan.h:198
double torsoPitch() const
Reference torso pitch angle.
Definition: FootstepPlan.h:412
double landingDuration() const
Get swing foot landing ratio.
Definition: FootstepPlan.h:216
void save(mc_rtc::Configuration &config) const
Save plan to configuration dictionary.
Sequence of footsteps with gait parameters.
Definition: FootstepPlan.h:41
void takeoffPitch(double pitch)
Set swing foot takeoff pitch angle.
Definition: FootstepPlan.h:394
void appendContact(Contact step)
Append footstep to plan.
Definition: FootstepPlan.h:114
const std::vector< Contact > & contacts() const
Reference to list of contacts.
Definition: FootstepPlan.h:138
void swapFirstTwoContacts()
Swap first two contacts in plan.
Definition: FootstepPlan.h:310
void comHeight(double height)
Set default CoM height above ground contact.
Definition: FootstepPlan.h:130