Skip to content

Commit

Permalink
Fix style, sprinkle comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Arjo Chakravarty <[email protected]>
  • Loading branch information
arjo129 authored and chapulina committed Nov 2, 2021
1 parent 604d697 commit ed39cb8
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lrauv_ignition_plugins/src/JointPositionPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,32 +154,44 @@ void TethysJointPlugin::PreUpdate(
cmdPos = this->dataPtr->jointPosCmd;
}

std::chrono::duration<double, std::ratio<1,1>> delta_t = _info.dt;
auto maxPositionChange = delta_t.count() * this->dataPtr->maxVelocity;

std::chrono::duration<double, std::ratio<1,1>> deltaT = _info.dt;
auto maxPositionChange = deltaT.count() * this->dataPtr->maxVelocity;
double desiredVelocity = 0;
if (cmdPos < currentPos[this->dataPtr->jointIndex])
{
if (currentPos[this->dataPtr->jointIndex] - cmdPos > maxPositionChange)
{
desiredVelocity =
(cmdPos - currentPos[this->dataPtr->jointIndex])/delta_t.count();
// If the gap between the current position and the command position is
// more than the max change in one clock cycle then we want to move the
// joint at the max velocity.
desiredVelocity = -this->dataPtr->maxVelocity;
}
else
{
desiredVelocity = -this->dataPtr->maxVelocity;
// Otherwise if the joint gap is less than the max change in one clock
// cycle, move it to the correct position within the clock cycle to
// prevent overshoot.
desiredVelocity =
(cmdPos - currentPos[this->dataPtr->jointIndex])/deltaT.count();
}
}
else if (cmdPos > currentPos[this->dataPtr->jointIndex])
{
if (cmdPos - currentPos[this->dataPtr->jointIndex] > maxPositionChange)
{
desiredVelocity =
(cmdPos - currentPos[this->dataPtr->jointIndex])/delta_t.count();
// If the gap between the current position and the command position is
// more than the max change in one clock cycle then we want to move the
// joint at the max velocity.
desiredVelocity = this->dataPtr->maxVelocity;
}
else
{
desiredVelocity = this->dataPtr->maxVelocity;
// Otherwise if the joint gap is less than the max change in one clock
// cycle, move it to the correct position within the clock cycle to
// prevent overshoot.
desiredVelocity =
(cmdPos - currentPos[this->dataPtr->jointIndex])/deltaT.count();
}
}

Expand Down

0 comments on commit ed39cb8

Please sign in to comment.