Skip to content

Commit

Permalink
Update custom sensor system example to make the sensor respect update…
Browse files Browse the repository at this point in the history
… rate (#2817)

Signed-off-by: Ian Chen <ichen@openrobotics.org>
  • Loading branch information
iche033 authored Mar 8, 2025
1 parent 7608ed9 commit 7fbc51c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion examples/plugin/custom_sensor_system/OdometerSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,19 @@ void OdometerSystem::PostUpdate(const gz::sim::UpdateInfo &_info,
for (auto &[entity, sensor] : this->entitySensorMap)
{
sensor->NewPosition(gz::sim::worldPose(entity, _ecm).Pos());
sensor->Update(_info.simTime);
// Call base Sensor class' Update function with force = false
// to make the sensor respect the specified update rate.
auto baseSensor = std::dynamic_pointer_cast<gz::sensors::Sensor>(sensor);
if (baseSensor)
{
baseSensor->Update(_info.simTime, false);
}
else
{
sensor->Update(_info.simTime);
gzerr << "Error casting custom sensor to base Sensor class. "
<< "This should not happen." << std::endl;
}
}
}

Expand Down

0 comments on commit 7fbc51c

Please # to comment.