You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/Tutorials/Advanced/Simulators/Webots.rst
+53-61
Original file line number
Diff line number
Diff line change
@@ -35,32 +35,15 @@ Prerequisites
35
35
36
36
It is recommended to understand basic ROS principles covered in the beginner :doc:`../../../Tutorials`.
37
37
In particular, :doc:`../../Beginner-CLI-Tools/Introducing-Turtlesim/Introducing-Turtlesim`, :doc:`../../Beginner-CLI-Tools/Understanding-ROS2-Topics/Understanding-ROS2-Topics`, :doc:`../../Beginner-Client-Libraries/Creating-A-Workspace/Creating-A-Workspace`, :doc:`../../Beginner-Client-Libraries/Creating-Your-First-ROS2-Package` and :doc:`../../Intermediate/Launch/Creating-Launch-Files` are useful prerequisites.
38
-
Finally, you will need to install ``webots_ros2_driver`` from a terminal with this command:
38
+
Finally, you will need to install ``webots_ros2_driver`` from a terminal with the following commands.
39
+
On Windows, a WSL (Windows Subsystem for Linux) environment must be configured and used to run all the Linux and ROS commands contained in this tutorial.
40
+
This `page <https://github.com/cyberbotics/webots_ros2/wiki/Build-and-Install#windows>`_ explains how to setup such installation.
@@ -193,13 +176,22 @@ In the ``my_package/resource`` folder create a text file named ``my_robot.urdf``
193
176
Let's create now the launch file to easily launch the simulation and the ROS controller with a single command.
194
177
In the ``my_package/launch`` folder create a new text file named ``robot_launch.py`` with this code:
195
178
196
-
.. literalinclude:: Code/robot_launch.py
197
-
:language: python
179
+
.. tabs::
180
+
181
+
.. group-tab:: Linux
182
+
183
+
.. literalinclude:: Code/robot_launch_linux.py
184
+
:language: python
185
+
186
+
.. group-tab:: Windows
187
+
188
+
.. literalinclude:: Code/robot_launch_windows.py
189
+
:language: python
198
190
199
191
The ``WebotsLauncher`` object is a custom action that allows you to start a Webots simulation instance.
200
192
You have to specify in the constructor which world file the simulator will open.
201
193
202
-
.. literalinclude:: Code/robot_launch.py
194
+
.. literalinclude:: Code/robot_launch_linux.py
203
195
:language: python
204
196
:dedent: 4
205
197
:lines: 14-16
@@ -208,7 +200,7 @@ A supervisor Robot is always automatically added to the world file by ``WebotsLa
208
200
This robot is controlled by the custom node ``Ros2Supervisor``, which must also be started using the ``Ros2SupervisorLauncher``.
209
201
This node allows to spawn URDF robots directly into the world, and it also publishes useful topics like ``/clock``.
210
202
211
-
.. literalinclude:: Code/robot_launch.py
203
+
.. literalinclude:: Code/robot_launch_linux.py
212
204
:language: python
213
205
:dedent: 4
214
206
:lines: 18
@@ -219,23 +211,37 @@ The node will be able to communicate with the simulated robot by using a custom
219
211
In your case, you need to run a single instance of this node, because you have a single robot in the simulation.
220
212
But if you had more robots in the simulation, you would have to run one instance of this node per robot.
221
213
``WEBOTS_CONTROLLER_URL`` is used to define the name of the robot the driver should connect to.
214
+
On Windows, the communication between Webots (running in Windows) and the controllers (running in WSL) goes through a TCP connection.
215
+
The IP address is automatically retrieved by ``webots_ros2_driver``.
216
+
The default Webots port number is 1234.
222
217
The ``robot_description`` parameter holds the contents of the URDF file which refers to the ``my_robot_driver.py`` Python plugin.
223
218
224
-
.. literalinclude:: Code/robot_launch.py
225
-
:language: python
226
-
:dedent: 4
227
-
:lines: 20-28
219
+
.. tabs::
220
+
221
+
.. group-tab:: Linux
222
+
223
+
.. literalinclude:: Code/robot_launch_linux.py
224
+
:language: python
225
+
:dedent: 4
226
+
:lines: 20-28
227
+
228
+
.. group-tab:: Windows
229
+
230
+
.. literalinclude:: Code/robot_launch_windows.py
231
+
:language: python
232
+
:dedent: 4
233
+
:lines: 21-29
228
234
229
235
After that, the three nodes are set to be launched in the ``LaunchDescription`` constructor:
230
236
231
-
.. literalinclude:: Code/robot_launch.py
237
+
.. literalinclude:: Code/robot_launch_linux.py
232
238
:language: python
233
239
:dedent: 4
234
240
:lines: 30-33
235
241
236
242
Finally, an optional part is added in order to shutdown all the nodes once Webots terminates (e.g., when it gets closed from the graphical user interface).
237
243
238
-
.. literalinclude:: Code/robot_launch.py
244
+
.. literalinclude:: Code/robot_launch_linux.py
239
245
:language: python
240
246
:dedent: 8
241
247
:lines: 34-39
@@ -256,24 +262,12 @@ This sets-up the package and adds in the ``data_files`` variable the newly added
256
262
257
263
From a terminal in your ROS2 workspace run:
258
264
259
-
.. tabs::
260
-
261
-
.. group-tab:: Linux
262
-
263
-
.. code-block:: console
265
+
.. code-block:: console
264
266
265
267
colcon build
266
268
source install/local_setup.bash
267
269
ros2 launch my_package robot_launch.py
268
270
269
-
.. group-tab:: Windows
270
-
271
-
.. code-block:: console
272
-
273
-
colcon build
274
-
call install\local_setup.bat
275
-
ros2 launch my_package robot_launch.py
276
-
277
271
This will launch the simulation.
278
272
Webots will be automatically installed on the first run in case it was not already installed.
279
273
@@ -359,9 +353,19 @@ This will add an entry point for the ``obstacle_avoider`` node.
359
353
360
354
Go to the file ``robot_launch.py`` and replace ``def generate_launch_description():`` with:
This will create an ``obstacle_avoider`` node that will be included in the ``LaunchDescription``.
367
371
@@ -370,24 +374,12 @@ This will create an ``obstacle_avoider`` node that will be included in the ``Lau
370
374
371
375
As in task ``7``, launch the simulation from a terminal in your ROS 2 workspace:
372
376
373
-
.. tabs::
374
-
375
-
.. group-tab:: Linux
376
-
377
-
.. code-block:: console
377
+
.. code-block:: console
378
378
379
379
colcon build
380
380
source install/local_setup.bash
381
381
ros2 launch my_package robot_launch.py
382
382
383
-
.. group-tab:: Windows
384
-
385
-
.. code-block:: console
386
-
387
-
colcon build
388
-
call install\local_setup.bat
389
-
ros2 launch my_package robot_launch.py
390
-
391
383
Your robot should go forward and before hitting the wall it should turn clockwise.
392
384
You can press ``Ctrl+F10`` in Webots or go to the ``View`` menu, ``Optional Rendering`` and ``Show DistanceSensor Rays`` to display the range of the distance sensors of the robot.
0 commit comments