28 #include <mc_rbdyn/rpy_utils.h> 37 const sva::PTransformd & targetPose,
41 assert(0. <= takeoffDuration_ && takeoffDuration_ <= 0.5 * duration);
42 assert(0. <= landingDuration_ && landingDuration_ <= 0.5 * duration);
44 accel_ = Eigen::Vector3d::Zero();
45 aerialStart_ = takeoffDuration_;
49 ori_ = initPose.rotation();
51 pos_ = initPose.translation();
52 targetPose_ = targetPose;
53 vel_ = Eigen::Vector3d::Zero();
55 const Eigen::Vector3d & initPos = initPose_.translation();
56 const Eigen::Vector3d & targetPos = targetPose_.translation();
57 double aerialDuration = duration - takeoffDuration_ - landingDuration_;
58 double halfDuration = duration / 2;
60 Eigen::Vector3d aerialStartPos = initPos + takeoffOffset_;
61 xyTakeoffChunk_.
reset(initPos.head<2>(), aerialStartPos.head<2>(), takeoffDuration_);
62 xyAerialChunk_.
reset(aerialStartPos.head<2>(), targetPos.head<2>(), aerialDuration);
64 Eigen::Vector3d airPos = 0.5 * (initPose.translation() + targetPose.translation());
65 airPos.z() = std::min(initPose.translation().z(), targetPose.translation().z()) + height;
66 zFirstChunk_.
reset(initPos.z(), airPos.z(), halfDuration);
67 zSecondChunk_.
reset(airPos.z(), targetPos.z(), halfDuration);
69 pitchTakeoffChunk_.
reset(0., takeoffPitch_, takeoffDuration_);
70 pitchAerialChunk1_.
reset(takeoffPitch_, 0., aerialDuration / 2);
71 pitchAerialChunk2_.
reset(0., landingPitch_, aerialDuration / 2);
72 pitchLandingChunk_.
reset(landingPitch_, 0., landingDuration_);
79 logger.addLogEntry(
"swing_foot_accel", [
this]() {
return accel(); });
80 logger.addLogEntry(
"swing_foot_offset", [
this]() {
return takeoffOffset_; });
81 logger.addLogEntry(
"swing_foot_pitch", [
this]() {
return pitch_; });
82 logger.addLogEntry(
"swing_foot_pose", [
this]() {
return pose(); });
83 logger.addLogEntry(
"swing_foot_vel", [
this]() {
return vel(); });
88 logger.removeLogEntry(
"swing_foot_accel");
89 logger.removeLogEntry(
"swing_foot_offset");
90 logger.removeLogEntry(
"swing_foot_pitch");
91 logger.removeLogEntry(
"swing_foot_pose");
92 logger.removeLogEntry(
"swing_foot_vel");
98 updatePose(playback_);
101 void SwingFoot::updatePose(
double t)
108 void SwingFoot::updateZ(
double t)
111 double t2 = t - zFirstChunk_.
duration();
114 pos_.z() = zFirstChunk_.
pos(t1);
115 vel_.z() = zFirstChunk_.
vel(t1);
116 accel_.z() = zFirstChunk_.
accel(t1);
120 pos_.z() = zSecondChunk_.
pos(t2);
121 vel_.z() = zSecondChunk_.
vel(t2);
122 accel_.z() = zSecondChunk_.
accel(t2);
126 void SwingFoot::updateXY(
double t)
129 double t2 = t1 - xyTakeoffChunk_.
duration();
130 if(t1 <= xyTakeoffChunk_.
duration())
132 pos_.head<2>() = xyTakeoffChunk_.
pos(t1);
133 vel_.head<2>() = xyTakeoffChunk_.
vel(t1);
134 accel_.head<2>() = xyTakeoffChunk_.
accel(t1);
138 pos_.head<2>() = xyAerialChunk_.
pos(t2);
139 vel_.head<2>() = xyAerialChunk_.
vel(t2);
140 accel_.head<2>() = xyAerialChunk_.
accel(t2);
144 void SwingFoot::updatePitch(
double t)
146 Eigen::Matrix3d baseOri;
148 double t2 = t1 - pitchTakeoffChunk_.
duration();
149 double t3 = t2 - pitchAerialChunk1_.
duration();
150 double t4 = t3 - pitchAerialChunk2_.
duration();
152 double aerialDuration = xyAerialChunk_.
duration();
153 if(t1 <= takeoffDuration)
155 baseOri = initPose_.rotation();
157 else if(t2 <= aerialDuration)
159 double s2 = xyAerialChunk_.
s(t2);
160 baseOri =
slerp(initPose_.rotation(), targetPose_.rotation(), s2);
164 baseOri = targetPose_.rotation();
166 if(t1 <= pitchTakeoffChunk_.
duration())
168 pitch_ = pitchTakeoffChunk_.
pos(t1);
170 else if(t2 <= pitchAerialChunk1_.
duration())
172 pitch_ = pitchAerialChunk1_.
pos(t2);
174 else if(t3 <= pitchAerialChunk2_.
duration())
176 pitch_ = pitchAerialChunk2_.
pos(t3);
180 pitch_ = pitchLandingChunk_.
pos(t4);
182 ori_ = mc_rbdyn::rpyToMat(0., pitch_, 0.) * baseOri;
void reset(const T &initPos, const T &targetPos, double duration)
Reset duration and boundary positions.
T vel(double t) const
Velocity along the retimed trajectory.
T accel(double t) const
Acceleration along the retimed trajectory.
double duration() const
Get trajectory duration.
T pos(double t) const
Position along the retimed trajectory.
Main controller namespace.
Eigen::Matrix3d slerp(const Eigen::Matrix3d &from, const Eigen::Matrix3d &to, double t)
Spherical linear interpolation between two rotation matrices.
double s(double t) const
Mapping from to .