Skip to content

Commit 90577db

Browse files
committed
update demo launcher for Gazebo Ignition
1 parent 16af6a2 commit 90577db

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

opennav_coverage_demo/launch/coverage_demo_launch.py

+42-25
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
# limitations under the License.
1414

1515
import os
16+
import tempfile
1617

1718
from ament_index_python.packages import get_package_share_directory
18-
1919
from launch import LaunchDescription
20-
from launch.actions import ExecuteProcess, IncludeLaunchDescription
20+
from launch.actions import ExecuteProcess, IncludeLaunchDescription, OpaqueFunction, RegisterEventHandler
21+
from launch.event_handlers import OnShutdown
2122
from launch.launch_description_sources import PythonLaunchDescriptionSource
2223
from launch_ros.actions import Node
2324

@@ -26,22 +27,21 @@ def generate_launch_description():
2627
nav2_bringup_dir = get_package_share_directory('nav2_bringup')
2728
coverage_demo_dir = get_package_share_directory('opennav_coverage_demo')
2829
rviz_config_file = os.path.join(coverage_demo_dir, 'rviz_config.rviz')
30+
sim_dir = get_package_share_directory("nav2_minimal_tb3_sim")
2931

3032
world = os.path.join(coverage_demo_dir, 'blank.world')
3133
param_file_path = os.path.join(coverage_demo_dir, 'demo_params.yaml')
32-
sdf = os.path.join(nav2_bringup_dir, 'worlds', 'waffle.model')
34+
robot_sdf = os.path.join(sim_dir, "urdf", "gz_waffle.sdf.xacro")
3335

3436
# start the simulation
35-
start_gazebo_server_cmd = ExecuteProcess(
36-
cmd=['gzserver', '-s', 'libgazebo_ros_init.so',
37-
'-s', 'libgazebo_ros_factory.so', world],
38-
cwd=[coverage_demo_dir], output='screen')
39-
40-
# start_gazebo_client_cmd = ExecuteProcess(
41-
# cmd=['gzclient'],
42-
# cwd=[coverage_demo_dir], output='screen')
43-
44-
urdf = os.path.join(nav2_bringup_dir, 'urdf', 'turtlebot3_waffle.urdf')
37+
world_sdf = tempfile.mktemp(prefix="nav2_", suffix=".sdf")
38+
world_sdf_xacro = ExecuteProcess(cmd=["xacro", "-o", world_sdf, "headless:=false", world])
39+
gazebo_server = ExecuteProcess(
40+
cmd=["gz", "sim", "-r", "-s", world_sdf],
41+
output="screen",
42+
)
43+
44+
urdf = os.path.join(sim_dir, 'urdf', 'turtlebot3_waffle.urdf')
4545
with open(urdf, 'r') as infp:
4646
robot_description = infp.read()
4747

@@ -53,15 +53,29 @@ def generate_launch_description():
5353
parameters=[{'use_sim_time': True,
5454
'robot_description': robot_description}])
5555

56-
start_gazebo_spawner_cmd = Node(
57-
package='gazebo_ros',
58-
executable='spawn_entity.py',
59-
output='screen',
60-
arguments=[
61-
'-entity', 'tb3',
62-
'-file', sdf,
63-
'-x', '5.0', '-y', '5.0', '-z', '0.10',
64-
'-R', '0.0', '-P', '0.0', '-Y', '0.0'])
56+
remove_temp_sdf_file = RegisterEventHandler(
57+
event_handler=OnShutdown(on_shutdown=[OpaqueFunction(function=lambda _: os.remove(world_sdf))])
58+
)
59+
60+
gazebo_client = IncludeLaunchDescription(
61+
PythonLaunchDescriptionSource(
62+
os.path.join(get_package_share_directory("ros_gz_sim"), "launch", "gz_sim.launch.py")
63+
),
64+
launch_arguments={"gz_args": ["-v4 -g "]}.items(),
65+
)
66+
67+
start_gazebo_spawner_cmd = IncludeLaunchDescription(
68+
PythonLaunchDescriptionSource(
69+
os.path.join(sim_dir, 'launch', 'spawn_tb3.launch.py')),
70+
launch_arguments={'namespace': '',
71+
'robot_name': 'turtlebot3_waffle',
72+
'robot_sdf': robot_sdf,
73+
'x_pose': str(5.0),
74+
'y_pose': str(5.0),
75+
'z_pose': str(0.1),
76+
'roll': str(0.0),
77+
'pitch': str(0.0),
78+
'yaw': str(0.0)}.items())
6579

6680
# start the visualization
6781
rviz_cmd = IncludeLaunchDescription(
@@ -90,10 +104,13 @@ def generate_launch_description():
90104
output='screen')
91105

92106
ld = LaunchDescription()
93-
ld.add_action(start_gazebo_server_cmd)
94-
# ld.add_action(start_gazebo_client_cmd)
95-
ld.add_action(start_robot_state_publisher_cmd)
107+
ld.add_action(world_sdf_xacro)
108+
ld.add_action(remove_temp_sdf_file)
109+
ld.add_action(gazebo_server)
110+
ld.add_action(gazebo_client)
96111
ld.add_action(start_gazebo_spawner_cmd)
112+
113+
ld.add_action(start_robot_state_publisher_cmd)
97114
ld.add_action(rviz_cmd)
98115
ld.add_action(bringup_cmd)
99116
ld.add_action(fake_localization_cmd)

opennav_coverage_demo/package.xml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<depend>opennav_row_coverage</depend>
1818
<depend>opennav_coverage_navigator</depend>
1919

20+
<exec_depend>nav2_minimal_tb3_sim</exec_depend>
21+
2022
<test_depend>ament_lint_common</test_depend>
2123
<test_depend>ament_lint_auto</test_depend>
2224

0 commit comments

Comments
 (0)