Skip to content

Commit 2e62b93

Browse files
authored
Update nav2 example (#15)
1 parent 931625b commit 2e62b93

File tree

10 files changed

+163
-53
lines changed

10 files changed

+163
-53
lines changed

.github/workflows/test_build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ jobs:
241241
export IGN_PARTITION=${HOSTNAME}:${GITHUB_RUN_ID}
242242
sed -i 's/60s/600s/g' examples/example_nav2/example_nav2.osc
243243
# shellcheck disable=SC1083
244-
scenario_batch_execution -i examples/example_nav2/ -o test_example_nav2 --ignore-process-return-value -- ros2 launch tb4_sim_scenario sim_nav_scenario_launch.py scenario:={SCENARIO} output_dir:={OUTPUT_DIR} headless:=True use_rviz:=False
244+
scenario_batch_execution -i examples/example_nav2/ -o test_example_nav2 --ignore-process-return-value -- ros2 launch example_nav2 example_nav2_launch.py output_dir:={OUTPUT_DIR} headless:=True use_rviz:=False
245245
- name: Upload result
246246
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
247247
if: always()

docs/tutorials.rst

+22-48
Original file line numberDiff line numberDiff line change
@@ -161,32 +161,26 @@ and control it with Nav2, can be found in :repo_link:`examples/example_nav2/exam
161161
This scenario files looks as follows:
162162

163163
::
164-
164+
import osc.helpers
165165
import osc.ros
166+
import osc.nav2
166167

167-
scenario nav2_simulation_nav_to_pose:
168+
scenario example_nav2:
169+
timeout(60s)
168170
robot: differential_drive_robot
169-
do parallel:
170-
test_drive: serial:
171-
robot.init_nav2(pose_3d(position_3d(x: 0.0m, y: 0.0m)))
172-
robot.nav_to_pose(pose_3d(position_3d(x: 3.0m, y: -3.0m)))
173-
robot.nav_to_pose(pose_3d(position_3d(x: 0.0m, y: 0.0m)))
174-
emit end
175-
time_out: serial:
176-
wait elapsed(120s)
177-
emit fail
171+
do serial:
172+
robot.init_nav2(pose_3d(position_3d(x: 0.0m, y: 0.0m)))
173+
robot.nav_to_pose(pose_3d(position_3d(x: 3.0m, y: -3.0m)))
174+
178175

179176
Let’s break down the individual components of the scenario. The
180177
following snippet defines the turtlebot4 amr-object.
181178

182179
.. code-block::
183180
184-
turtlebot4: differential_drive_robot: # define turtlebot4 robot
181+
robot: differential_drive_robot
185182
186-
The ``do parallel`` runs the actual test drive and a time-out in
187-
parallel. In case something goes wrong, the time-out prevents the
188-
scenario from running indefinitely by canceling it after 2 minutes and
189-
marking it as failed.
183+
The ``do serial`` runs the actual test drive. A modifier is used to specify a timeout. If the scenario takes longer than 60 seconds, it will be marked as failed.
190184

191185

192186
Before being able to navigate, nav2 needs to be initialized. This
@@ -195,7 +189,7 @@ includes setting the initial pose of the Nav2 localization module
195189

196190
.. code-block::
197191
198-
turtlebot4.init_nav2(pose_3d(position_3d(x: 0.0m, y: 0.0m))) # initialize Nav2
192+
robot.init_nav2(pose_3d(position_3d(x: 0.0m, y: 0.0m)))
199193
200194
Finally, the following snippet calls the Nav2 `NavigateToPose
201195
action <https://github.com/ros-planning/navigation2/blob/main/nav2_msgs/action/NavigateToPose.action>`__
@@ -204,59 +198,39 @@ starting position
204198

205199
.. code-block::
206200
207-
turtlebot4.nav_to_pose(pose_3d(position_3d(x: 3.0m, y: -3.0m)))
208-
turtlebot4.nav_to_pose(pose_3d(position_3d(x: 0.0m, y: 0.0m)))
201+
robot.nav_to_pose(pose_3d(position_3d(x: 3.0m, y: -3.0m)))
209202
210-
Once the robot reached the final goal pose ``emit end`` finishes the
211-
scenario and marks it as successful.
203+
Once the robot reached the final goal pose the scenario is marked as successful and the execution ends.
212204

213205
To try this example, run
214206

215207
.. code-block:: bash
216208
217-
ros2 launch tb4_sim_scenario sim_nav_scenario_launch.py scenario:=examples/example_nav2/example_nav2.osc headless:=False
218-
219-
and you should see something like this
220-
221-
.. figure:: images/tb4_scenario.gif
222-
:alt: turtlebot4 nav2 scenario
209+
ros2 launch example_nav2 example_nav2_launch.py
223210
224-
Turtlebot4 NAV2 scenario
225211
226212
In case you want to run the navigation with SLAM instead of AMCL, update
227213
the above described scenario by setting the ``use_initial_pose`` to ``False``:
228214

229215
::
230-
216+
import osc.helpers
231217
import osc.ros
218+
import osc.nav2
232219

233-
scenario nav2_simulation_nav_to_pose:
220+
scenario example_nav2:
221+
timeout(60s)
234222
robot: differential_drive_robot
235-
do parallel:
236-
test_drive: serial:
237-
robot.init_nav2(
238-
initial_pose: pose_3d(position_3d(x: 0.0m, y: 0.0m)),
239-
use_initial_pose: false)
240-
robot.nav_to_pose(pose_3d(position_3d(x: 3.0m, y: -3.0m)))
241-
robot.nav_to_pose(pose_3d(position_3d(x: 0.0m, y: 0.0m)))
242-
emit end
243-
time_out: serial:
244-
wait elapsed(120s)
245-
emit fail
223+
do serial:
224+
robot.init_nav2(pose_3d(position_3d(x: 0.0m, y: 0.0m)), use_initial_pose: false)
225+
robot.nav_to_pose(pose_3d(position_3d(x: 3.0m, y: -3.0m)))
246226

247227

248228
Then, run:
249229

250230
.. code-block:: bash
251231
252-
ros2 launch tb4_sim_scenario sim_nav_scenario_launch.py scenario:=examples/example_nav2/example_nav2.osc headless:=false slam:=True
253-
254-
and you should see something like this
255-
256-
.. figure:: images/tb4_scenario_slam.PNG
257-
:alt: turtlebot4 nav2 scenario SLAM
232+
ros2 launch example_nav2 example_nav2_launch.py slam:=False
258233
259-
Turtlebot4 NAV2 scenario SLAM
260234
261235
Create Navigation Scenario with Obstacle
262236
----------------------------------------

examples/example_nav2/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Example Navigation
22

3-
To run the Example Navigation 2 Scenario, first build the `tb4_sim_scenario` package:
3+
To run the Example Navigation 2 Scenario, first build the `example_nav2` package:
44

55
```bash
6-
colcon build --packages-up-to tb4_sim_scenario
6+
colcon build --packages-up-to example_nav2
77
```
88

99
Source the workspace:
@@ -15,9 +15,9 @@ source install/setup.bash
1515
Now, run the following command to launch the scenario:
1616

1717
```bash
18-
ros2 launch tb4_sim_scenario sim_nav_scenario_launch.py scenario:=examples/example_nav2/example_nav2.osc
18+
ros2 launch example_nav2 example_nav2_launch.py
1919
```
2020

21-
A turtlebot is initialsed with nav2 which drives to a point and back.
21+
A turtlebot is initialsed with nav2 which drives to the scenario-specified goal.
2222

2323
For a more detailed understanding of the code structure and scenario implementation please refer to the [tutorial documentation](https://intellabs.github.io/scenario_execution/tutorials.html).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing,
10+
# software distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions
13+
# and limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing,
10+
# software distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions
13+
# and limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
import os
18+
19+
from ament_index_python.packages import get_package_share_directory
20+
from launch import LaunchDescription
21+
from launch.actions import IncludeLaunchDescription, DeclareLaunchArgument
22+
from launch.launch_description_sources import PythonLaunchDescriptionSource
23+
from launch.substitutions import PathJoinSubstitution, LaunchConfiguration
24+
25+
26+
def generate_launch_description():
27+
28+
example_nav2_dir = get_package_share_directory('example_nav2')
29+
nav2_bringup_dir = get_package_share_directory('nav2_bringup')
30+
scenario_execution_ros_dir = get_package_share_directory('scenario_execution_ros')
31+
32+
scenario = LaunchConfiguration('scenario')
33+
34+
return LaunchDescription([
35+
DeclareLaunchArgument('scenario', description='Scenario file to execute', default_value=PathJoinSubstitution([example_nav2_dir, 'scenarios', 'example_nav2.osc'])),
36+
37+
IncludeLaunchDescription(
38+
PythonLaunchDescriptionSource([PathJoinSubstitution([nav2_bringup_dir, 'launch', 'tb4_simulation_launch.py'])])
39+
),
40+
IncludeLaunchDescription(
41+
PythonLaunchDescriptionSource([PathJoinSubstitution([scenario_execution_ros_dir, 'launch', 'scenario_launch.py'])]),
42+
launch_arguments={'scenario': scenario}.items()
43+
)
44+
])
45+

examples/example_nav2/package.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>example_nav2</name>
5+
<version>1.2.0</version>
6+
<description>Scenario Execution Example for Navigation2</description>
7+
<author>Intel Labs</author>
8+
<author email="[email protected]">Frederik Pasch</author>
9+
<author email="[email protected]">Florian Mirus</author>
10+
<maintainer email="[email protected]">Frederik Pasch</maintainer>
11+
<maintainer email="[email protected]">Florian Mirus</maintainer>
12+
<license>Apache-2.0</license>
13+
14+
<depend>scenario_execution_ros</depend>
15+
<depend>scenario_execution_nav2</depend>
16+
<depend>nav2_bringup</depend>
17+
18+
<exec_depend>rclpy</exec_depend>
19+
20+
<test_depend>ament_copyright</test_depend>
21+
<test_depend>ament_flake8</test_depend>
22+
<test_depend>ament_pep257</test_depend>
23+
<test_depend>python3-pytest</test_depend>
24+
25+
<export>
26+
<build_type>ament_python</build_type>
27+
</export>
28+
</package>

examples/example_nav2/resource/example_nav2

Whitespace-only changes.

examples/example_nav2/setup.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[develop]
2+
script_dir=$base/lib/example_nav2
3+
[install]
4+
install_scripts=$base/lib/example_nav2

examples/example_nav2/setup.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing,
10+
# software distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions
13+
# and limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
""" Setup file for package example_nav2 """
18+
from glob import glob
19+
import os
20+
from setuptools import setup
21+
22+
PACKAGE_NAME = 'example_nav2'
23+
24+
setup(
25+
name=PACKAGE_NAME,
26+
version='1.2.0',
27+
packages=[PACKAGE_NAME],
28+
data_files=[
29+
('share/ament_index/resource_index/packages',
30+
['resource/' + PACKAGE_NAME]),
31+
('share/' + PACKAGE_NAME, ['package.xml']),
32+
(os.path.join('share', PACKAGE_NAME, 'scenarios'), glob('scenarios/*.osc')),
33+
(os.path.join('share', PACKAGE_NAME, 'launch'), glob('launch/*launch.py'))
34+
],
35+
install_requires=['setuptools'],
36+
zip_safe=True,
37+
maintainer='Intel Labs',
38+
maintainer_email='[email protected]',
39+
description='Scenario Execution Example for Navigation2',
40+
license='Apache License 2.0',
41+
tests_require=['pytest'],
42+
entry_points={
43+
},
44+
)

0 commit comments

Comments
 (0)