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

Fix physics based sensor update rate in lockstep mode #2863

Merged
merged 2 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions gazebo/sensors/Sensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,18 @@ void Sensor::Update(const bool _force)
{
if (this->useStrictRate)
{
// rendering sensors (IMAGE category) has it's 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))
{
common::Time simTime = this->world->SimTime();
this->lastUpdateTime = simTime;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could avoid the temporary object here:

Suggested change
this->lastUpdateTime = simTime;
this->lastUpdateTime = this->world->SimTime();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. 4ab78c5

this->dataPtr->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 @@ -762,7 +762,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>