gz-sim icon indicating copy to clipboard operation
gz-sim copied to clipboard

Custom sensor system example ignoring sdf's update rate

Open 5p00kk opened this issue 1 year ago • 2 comments

Description

In the implementation of a system for the custom sensor, the sensor is updated calling custom sensor's Update() method: https://github.com/gazebosim/gz-sim/blob/c158287d6f8556112d86d6e4188c39784364bd40/examples/plugin/custom_sensor_system/OdometerSystem.cc#L103 This will result in sensor update for at each simulation step and the system will ignore the sdf's update_rate attribute.

To avoid it the parent (gz::sensors::Sensor) Update() function should be called that executes the update at given update_rate (if force flag is false). For instance:

sensor->gz::sensors::Sensor::Update(_info.simTime, false);

5p00kk avatar Jan 17 '24 12:01 5p00kk

In general, I believe that our sensor systems are guarded with logic like this: https://github.com/gazebosim/gz-sim/blob/c158287d6f8556112d86d6e4188c39784364bd40/src/systems/imu/Imu.cc#L154-L166

There has been discussion of a set of system callbacks that could fire at particular rates, but there are some intricacies to consider with the potential of rewinding or jumps in time.

mjcarroll avatar Jan 19 '24 15:01 mjcarroll

Probably it's two approaches as the following call includes the same check (if forcing=False, the sensor will update itself only if it's time), the sensor's implementation is very similar to the guard in the system:

https://github.com/gazebosim/gz-sim/blob/c158287d6f8556112d86d6e4188c39784364bd40/src/systems/imu/Imu.cc#L171

https://github.com/gazebosim/gz-sensors/blob/d522779693916a81aac6360b049286e7ebb6cdb3/src/Sensor.cc#L456C4-L461C1

Regardless, the way OdometerSystem is implemented right now is incorrect because there is neither System level check or call to Sensor's class Update function that would check if it's time to update. Right now the direct Update implementation is being called, which results in Custom Sensor's update being called at the simulation rate.

5p00kk avatar Jan 19 '24 16:01 5p00kk