Skip to content

Commit

Permalink
Port sensor update rate fix (#3353)
Browse files Browse the repository at this point in the history
* resolve conflicts

Signed-off-by: Ian Chen <ichen@openrobotics.org>

* add lock

Signed-off-by: Ian Chen <ichen@openrobotics.org>

---------

Signed-off-by: Ian Chen <ichen@openrobotics.org>
  • Loading branch information
iche033 authored Nov 8, 2023
1 parent 391c4f2 commit 41b34e5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions gazebo/sensors/Sensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,18 @@ void Sensor::Update(const bool _force)
{
if (this->useStrictRate)
{
// rendering sensors (IMAGE category) has its own mechanism
// for throttling and lockstepping with physics. So throttle just
// physics sensors
if (this->dataPtr->category != IMAGE && !this->NeedsUpdate() && !_force)
return;

if (this->UpdateImpl(_force))
{
std::lock_guard<std::mutex> lock(this->dataPtr->mutexLastUpdateTime);
this->lastUpdateTime = this->world->SimTime();;
this->updated();
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion gazebo/sensors/SensorManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ void SensorManager::SensorContainer::RunLoop()
if (!g_sensorsDirty)
return;

// Get the minimum update rate from the sensors.
// Get the maximum update rate from the sensors.
for (Sensor_V::iterator iter = this->sensors.begin();
iter != this->sensors.end() && !this->stop; ++iter)
{
Expand Down
27 changes: 27 additions & 0 deletions test/worlds/laser_hit_strict_rate_test.world
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@
<static>true</static>
<link name="link">
<sensor name="laser" type="ray">
<ray>
<scan>
<horizontal>
<samples>4</samples>
<resolution>1</resolution>
<min_angle>-2.26889</min_angle>
<max_angle>2.268899</max_angle>
</horizontal>
</scan>
<range>
<min>0.0</min>
<max>20</max>
<resolution>0.01</resolution>
</range>
</ray>
<always_on>1</always_on>
<update_rate>250</update_rate>
<visualize>true</visualize>
</sensor>
</link>
</model>

<model name="ray_model2">
<static>true</static>
<link name="link2">
<sensor name="laser2" type="ray">
<ray>
<scan>
<horizontal>
Expand All @@ -53,5 +79,6 @@
</sensor>
</link>
</model>

</world>
</sdf>

0 comments on commit 41b34e5

Please sign in to comment.