Skip to content
Snippets Groups Projects
Commit 0db56812 authored by odri's avatar odri
Browse files

Switch from std::vector to Eigen Matrix to avoid runtime in FootTrajectoryGenerator

parent f5f69600
No related branches found
No related tags found
No related merge requests found
Pipeline #16532 failed
...@@ -84,7 +84,7 @@ class FootTrajectoryGenerator { ...@@ -84,7 +84,7 @@ class FootTrajectoryGenerator {
double lockTime_; // Target lock before the touchdown double lockTime_; // Target lock before the touchdown
double vertTime_; // Duration during which feet move only along Z when taking off and landing double vertTime_; // Duration during which feet move only along Z when taking off and landing
std::vector<int> feet; // Column indexes of feet currently in swing phase Eigen::Matrix<int, 1, 4> feet; // Column indexes of feet currently in swing phase
Vector4 t0s; // Elapsed time since the start of the swing phase movement Vector4 t0s; // Elapsed time since the start of the swing phase movement
Vector4 t_swing; // Swing phase duration for each foot Vector4 t_swing; // Swing phase duration for each foot
......
...@@ -8,7 +8,7 @@ FootTrajectoryGenerator::FootTrajectoryGenerator() ...@@ -8,7 +8,7 @@ FootTrajectoryGenerator::FootTrajectoryGenerator()
k_mpc(0), k_mpc(0),
maxHeight_(0.0), maxHeight_(0.0),
lockTime_(0.0), lockTime_(0.0),
feet(), feet(Eigen::Matrix<int, 1, 4>::Zero()),
t0s(Vector4::Zero()), t0s(Vector4::Zero()),
t_swing(Vector4::Zero()), t_swing(Vector4::Zero()),
targetFootstep_(Matrix34::Zero()), targetFootstep_(Matrix34::Zero()),
...@@ -183,34 +183,40 @@ void FootTrajectoryGenerator::updateFootPosition(int const j, Vector3 const &tar ...@@ -183,34 +183,40 @@ void FootTrajectoryGenerator::updateFootPosition(int const j, Vector3 const &tar
void FootTrajectoryGenerator::update(int k, MatrixN const &targetFootstep) { void FootTrajectoryGenerator::update(int k, MatrixN const &targetFootstep) {
if ((k % k_mpc) == 0) { if ((k % k_mpc) == 0) {
// Indexes of feet in swing phase // Status of feet
feet.clear(); feet = gait_->getCurrentGait().row(0).cast <int> ();
for (int i = 0; i < 4; i++) {
if (gait_->getCurrentGait()(0, i) == 0) feet.push_back(i);
}
// If no foot in swing phase // If no foot in swing phase
if (feet.size() == 0) return; if (feet.sum() == 4) return;
// For each foot in swing phase get remaining duration of the swing phase // For each foot in swing phase get remaining duration of the swing phase
for (int j = 0; j < (int)feet.size(); j++) { for (int i = 0; i < 4; i++) {
int i = feet[j]; if (feet(0, i) == 0)
t_swing[i] = gait_->getPhaseDuration(0, feet[j], 0.0); // 0.0 for swing phase {
double value = t_swing[i] - (gait_->getRemainingTime() * k_mpc - ((k + 1) % k_mpc)) * dt_wbc - dt_wbc; t_swing[i] = gait_->getPhaseDuration(0, i, 0.0); // 0.0 for swing phase
t0s[i] = std::max(0.0, value); double value = t_swing[i] - (gait_->getRemainingTime() * k_mpc - ((k + 1) % k_mpc)) * dt_wbc - dt_wbc;
t0s[i] = std::max(0.0, value);
}
} }
} else { } else {
// If no foot in swing phase // If no foot in swing phase
if (feet.size() == 0) return; if (feet.sum() == 4) return;
// Increment of one time step for feet in swing phase // Increment of one time step for feet in swing phase
for (int i = 0; i < (int)feet.size(); i++) { for (int i = 0; i < 4; i++) {
double value = t0s[feet[i]] + dt_wbc; if (feet(0, i) == 0)
t0s[feet[i]] = std::max(0.0, value); {
double value = t0s[i] + dt_wbc;
t0s[i] = std::max(0.0, value);
}
} }
} }
for (int i = 0; i < (int)feet.size(); i++) { for (int i = 0; i < 4; i++) {
updateFootPosition(feet[i], targetFootstep.col(feet[i])); if (feet(0, i) == 0)
{
updateFootPosition(i, targetFootstep.col(i));
}
} }
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment