Pendulum.cpp
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 #include <lipm_walking/Pendulum.h>
30 
31 namespace lipm_walking
32 {
33 
34 Pendulum::Pendulum(const Eigen::Vector3d & com, const Eigen::Vector3d & comd, const Eigen::Vector3d & comdd)
35 {
36  reset(com, comd, comdd);
37 }
38 
39 void Pendulum::reset(const Eigen::Vector3d & com, const Eigen::Vector3d & comd, const Eigen::Vector3d & comdd)
40 {
41  constexpr double DEFAULT_HEIGHT = 0.8; // [m]
42  constexpr double DEFAULT_LAMBDA = world::GRAVITY / DEFAULT_HEIGHT;
43  com_ = com;
44  comd_ = comd;
45  comdd_ = comdd;
46  comddd_ = Eigen::Vector3d::Zero();
47  omega_ = std::sqrt(DEFAULT_LAMBDA);
48  zmp_ = com_ + (world::gravity - comdd_) / DEFAULT_LAMBDA;
49  zmpd_ = comd_ - comddd_ / DEFAULT_LAMBDA;
50 }
51 
52 void Pendulum::integrateIPM(Eigen::Vector3d zmp, double lambda, double dt)
53 {
54  Eigen::Vector3d com_prev = com_;
55  Eigen::Vector3d comd_prev = comd_;
56  omega_ = std::sqrt(lambda);
57  zmp_ = zmp;
58 
59  Eigen::Vector3d vrp = zmp_ - world::gravity / lambda;
60  double ch = std::cosh(omega_ * dt);
61  double sh = std::sinh(omega_ * dt);
62  comdd_ = lambda * (com_prev - zmp_) + world::gravity;
63  comd_ = comd_prev * ch + omega_ * (com_prev - vrp) * sh;
64  com_ = com_prev * ch + comd_prev * sh / omega_ - vrp * (ch - 1.0);
65 
66  // default values for third-order terms
67  comddd_ = Eigen::Vector3d::Zero();
68  zmpd_ = comd_ - comddd_ / lambda;
69 }
70 
71 void Pendulum::integrateCoMJerk(const Eigen::Vector3d & comddd, double dt)
72 {
73  com_ += dt * (comd_ + dt * (comdd_ / 2 + dt * (comddd / 6)));
74  comd_ += dt * (comdd_ + dt * (comddd / 2));
75  comdd_ += dt * comddd;
76  comddd_ = comddd;
77 }
78 
79 void Pendulum::resetCoMHeight(double height, const Contact & plane)
80 {
81  auto n = plane.normal();
82  com_ += (height + n.dot(plane.p() - com_)) * n;
83  comd_ -= n.dot(comd_) * n;
84  comdd_ -= n.dot(comdd_) * n;
85  comddd_ -= n.dot(comddd_) * n;
86 }
87 
88 void Pendulum::completeIPM(const Contact & plane)
89 {
90  auto n = plane.normal();
91  auto gravitoInertial = world::gravity - comdd_;
92  double lambda = n.dot(gravitoInertial) / n.dot(plane.p() - com_);
93  zmp_ = com_ + gravitoInertial / lambda;
94  zmpd_ = comd_ - comddd_ / lambda;
95  omega_ = std::sqrt(lambda);
96 }
97 
98 } // namespace lipm_walking
const Eigen::Vector3d & p() const
Shorthand for position.
Definition: Contact.h:111
void reset(const Eigen::Vector3d &com, const Eigen::Vector3d &comd=Eigen::Vector3d::Zero(), const Eigen::Vector3d &comdd=Eigen::Vector3d::Zero())
Reset to a new state from CoM position and its derivatives.
Definition: Pendulum.cpp:39
const Eigen::Vector3d & comdd() const
CoM acceleration in the world frame.
Definition: Pendulum.h:128
constexpr double GRAVITY
Definition: world.h:38
Eigen::Vector3d zmpd_
Velocity of the zero-tilting moment point.
Definition: Pendulum.h:174
Eigen::Vector3d comdd_
Acceleration of the center of mass.
Definition: Pendulum.h:171
void completeIPM(const Contact &plane)
Complete inverted pendulum inputs (ZMP and natural frequency) from contact plane. ...
Definition: Pendulum.cpp:88
const Eigen::Vector3d & comd() const
CoM velocity in the world frame.
Definition: Pendulum.h:120
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Pendulum(const Eigen::Vector3d &com=Eigen::Vector3d::Zero(), const Eigen::Vector3d &comd=Eigen::Vector3d::Zero(), const Eigen::Vector3d &comdd=Eigen::Vector3d::Zero())
Initialize state from CoM position and its derivatives.
Definition: Pendulum.cpp:34
Eigen::Vector3d zmp_
Position of the zero-tilting moment point.
Definition: Pendulum.h:173
void integrateCoMJerk(const Eigen::Vector3d &comddd, double dt)
Integrate constant CoM jerk for a given duration.
Definition: Pendulum.cpp:71
Eigen::Vector3d com_
Position of the center of mass.
Definition: Pendulum.h:169
void resetCoMHeight(double height, const Contact &contact)
Reset CoM height above a given contact plane.
Definition: Pendulum.cpp:79
const Eigen::Vector3d & zmp() const
Zero-tilting moment point.
Definition: Pendulum.h:155
void integrateIPM(Eigen::Vector3d zmp, double lambda, double dt)
Integrate in floating-base inverted pendulum mode with constant inputs.
Definition: Pendulum.cpp:52
const Eigen::Vector3d gravity
Definition: world.h:40
Eigen::Vector3d comd_
Velocity of the center of mass.
Definition: Pendulum.h:170
Main controller namespace.
Definition: build.dox:1
Eigen::Vector3d comddd_
Jerk of the center of mass.
Definition: Pendulum.h:172
const Eigen::Vector3d & com() const
CoM position in the world frame.
Definition: Pendulum.h:112
Contacts wrap foot frames with extra info from the footstep plan.
Definition: Contact.h:58
double omega_
Natural frequency in [Hz].
Definition: Pendulum.h:175
Eigen::Vector3d normal() const
Normal unit vector of the contact frame.
Definition: Contact.h:95