Skip to content

Commit 57f70d0

Browse files
authored
Tutorial for lockstep of physics and sensors (#113)
Signed-off-by: Mabel Zhang <[email protected]>
1 parent bf2d35a commit 57f70d0

File tree

6 files changed

+155
-0
lines changed

6 files changed

+155
-0
lines changed
Loading
Loading
160 KB
Loading
Loading

lockstep_physics_sensors/tutorial.md

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Introduction
2+
Sometimes, it may be desired to strictly adhere to update rates specified for
3+
sensors, even if it means slowing down physics to wait for sensor updates to
4+
catch up.
5+
For example, running a high-resolution camera sensor on a computer with limited
6+
computing power could result in the camera updates lagging behind physics,
7+
causing the camera frames to be out of sync with physics.
8+
9+
The lockstep feature, enabled by passing `--lockstep` to Gazebo server, allows
10+
the sensor update rate to be strictly followed.
11+
This means that on computers with different computing resources, the specified
12+
update rate can always be respected, allowing for sensor updates and physics to
13+
be in sync.
14+
15+
# Create a world with a camera
16+
17+
We will use a high-resolution high-frame-rate camera for illustration.
18+
19+
Create a world file:
20+
21+
gedit camera_strict_rate.world
22+
23+
Paste in the following content:
24+
25+
~~~
26+
<?xml version="1.0" ?>
27+
<sdf version="1.6">
28+
<world name="default">
29+
<include>
30+
<uri>model://ground_plane</uri>
31+
</include>
32+
<include>
33+
<uri>model://sun</uri>
34+
</include>
35+
36+
<model name="camera_model">
37+
<static>true</static>
38+
<pose>-10.0 0.0 0.5 0 0 0</pose>
39+
<link name="link">
40+
<visual name="visual">
41+
<geometry>
42+
<box>
43+
<size>1 1 1</size>
44+
</box>
45+
</geometry>
46+
</visual>
47+
<!-- High fps high-res camera to test strict rate -->
48+
<sensor name="camera_sensor" type="camera">
49+
<camera>
50+
<horizontal_fov>1.0472</horizontal_fov>
51+
<image>
52+
<width>1280</width>
53+
<height>720</height>
54+
</image>
55+
</camera>
56+
<always_on>1</always_on>
57+
<!-- We choose a high fps on purpose. The goal is to check the effect
58+
of lockstep. -->
59+
<update_rate>500</update_rate>
60+
<visualize>true</visualize>
61+
</sensor>
62+
<!-- Regular camera, to make sure strict rate is only applied to the sensor intended -->
63+
<sensor name="camera_sensor_regular" type="camera">
64+
<camera>
65+
<horizontal_fov>1.0472</horizontal_fov>
66+
<image>
67+
<width>320</width>
68+
<height>240</height>
69+
</image>
70+
</camera>
71+
<always_on>1</always_on>
72+
<update_rate>30</update_rate>
73+
<visualize>true</visualize>
74+
</sensor>
75+
</link>
76+
</model>
77+
78+
<!-- Double pendulum -->
79+
<include>
80+
<name>active_pendulum</name>
81+
<uri>model://double_pendulum_with_base</uri>
82+
<pose>2 0 0 0 0 0</pose>
83+
<scale>0.5 0.5 0.5</scale>
84+
</include>
85+
86+
</world>
87+
</sdf>
88+
~~~
89+
90+
This world contains a high-resolution (1280x720) high-frame-rate (500 fps)
91+
camera, as well as a low-resolution (320x240) low-frame-rate (30 fps) camera
92+
for comparison.
93+
It also includes a pendulum, for visual verification.
94+
95+
# Run the world without lockstep
96+
97+
1. First, we will inspect what happens if we run the world normally, without the
98+
lockstep feature.
99+
100+
gazebo camera_strict_rate.world
101+
102+
1. Visualize the camera image: click on Window->Topic Visualization (or press
103+
Ctrl-T) to bring up the Topic Selector.
104+
Select the first item under the Image type.
105+
106+
[[file:files/topic_selector.png|640px]]
107+
108+
1. Examine the Hz field. It is likely unable to reach the specified 500 fps.
109+
110+
[[file:files/no_lockstep.png|640px]]
111+
112+
1. Take note of the real time factor at the bottom of the window. It should be
113+
close to 1.0.
114+
115+
This shows us that without enabling lockstep, the default behavior updates the
116+
sensors as fast as the computing resources allow.
117+
For a sensor that demands high computing power, it may never reach the specified
118+
update rate.
119+
120+
# Run the world with lockstep
121+
122+
1. Now we will run the world with lockstep enabled.
123+
124+
gazebo --lockstep camera_strict_rate.world
125+
126+
1. Bring up the camera image visualization as before.
127+
The Hz field should show 500.
128+
129+
[[file:files/lockstep_highres_camera.png|640px]]
130+
131+
The real time factor is likely less than 1.0. The exact number depends on your
132+
computing power.
133+
134+
This shows that the sensor's update rate is strictly followed, and physics has
135+
slowed down in order to accommodate for the high update rate.
136+
137+
1. In the Topic drop-down list, we can switch to the low-frame-rate camera and
138+
observe the Hz and real time factor.
139+
140+
[[file:files/lockstep_regular_camera.png|640px]]
141+
142+
The Hz field shows around 30.
143+
144+
However, the real time factor is still less than 1.0. This is a caveat with
145+
using the lockstep feature. When lockstep is enabled, poses in the scene are
146+
updated using function callbacks, which are slower than message transport used
147+
in the default setting (lockstep disabled). Therefore, overall simulation speed
148+
will slow down when lockstep is enabled.

manifest.xml

+7
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,12 @@
704704
<skill>intermediate</skill>
705705
</tutorial>
706706

707+
<tutorial title="Lockstep of physics and sensors" ref='lockstep_physics_sensors'>
708+
<markdown version="9+">lockstep_physics_sensors/tutorial.md</markdown>
709+
<description>How to enable lockstep synchronization between physics and sensors.</description>
710+
<skill>intermediate</skill>
711+
</tutorial>
712+
707713

708714
<!-- ****************** -->
709715
<!-- Advanced tutorials -->
@@ -1169,6 +1175,7 @@
11691175
<tutorial>camera_save</tutorial>
11701176
<tutorial>force_torque_sensor</tutorial>
11711177
<tutorial>logical_camera_sensor</tutorial>
1178+
<tutorial>lockstep_physics_sensors</tutorial>
11721179
</tutorials>
11731180
</category>
11741181

0 commit comments

Comments
 (0)