Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForceTorque system: improve readability #2403

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading