Skip to content

Commit

Permalink
ForceTorque system: improve readability (#2403)
Browse files Browse the repository at this point in the history
This adds some comments and uses structured bindings
in range-based for loops to improve readability.
It also adds const to unmodified variables in a loop.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
  • Loading branch information
scpeters committed May 14, 2024
1 parent 4019e09 commit a8f99a9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/systems/force_torque/ForceTorque.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ void ForceTorque::PostUpdate(const UpdateInfo &_info,
// note: gz-sensors does its own throttling. Here the check is mainly
// to avoid doing work in the ForceTorquePrivate::Update function
bool needsUpdate = false;
for (auto &it : this->dataPtr->entitySensorMap)
for (const auto &[sensorEntity, sensor] : this->dataPtr->entitySensorMap)
{
if (it.second->NextDataUpdateTime() <= _info.simTime &&
it.second->HasConnections())
if (sensor->NextDataUpdateTime() <= _info.simTime &&
sensor->HasConnections())
{
needsUpdate = true;
break;
Expand All @@ -193,11 +193,16 @@ void ForceTorque::PostUpdate(const UpdateInfo &_info,
if (!needsUpdate)
return;

// Transform joint wrench to sensor wrench and write to sensor
this->dataPtr->Update(_ecm);

for (auto &it : this->dataPtr->entitySensorMap)
for (auto &[sensorEntity, sensor] : this->dataPtr->entitySensorMap)
{
it.second->Update(_info.simTime, false);
// Call gz::sensors::ForceTorqueSensor::Update
// * Convert to user-specified frame
// * Apply noise
// * Publish to gz-transport topic
sensor->Update(_info.simTime, false);
}
}

Expand Down Expand Up @@ -269,7 +274,8 @@ void ForceTorquePrivate::Update(const EntityComponentManager &_ecm)
return true;
}

// Appropriate components haven't been populated by physics yet
// Return early if JointTransmittedWrench component has not yet been
// populated by the Physics system
auto jointWrench = _ecm.Component<components::JointTransmittedWrench>(
jointLinkIt->second.joint);
if (nullptr == jointWrench)
Expand Down

0 comments on commit a8f99a9

Please sign in to comment.