Skip to content

Commit 1cc1474

Browse files
committed
Use xacro for world file (ros-navigation#2)
Signed-off-by: Addisu Z. Taddese <[email protected]>
1 parent 43ef810 commit 1cc1474

File tree

8 files changed

+88
-70
lines changed

8 files changed

+88
-70
lines changed

nav2_bringup/launch/tb3_gz_robot_launch.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
from ament_index_python.packages import get_package_share_directory
1818

1919
from launch import LaunchDescription
20-
from launch.actions import DeclareLaunchArgument, ExecuteProcess
2120
from launch.actions import AppendEnvironmentVariable
21+
from launch.actions import DeclareLaunchArgument
2222
from launch.conditions import IfCondition
23-
from launch.substitutions import Command, LaunchConfiguration
23+
from launch.substitutions import LaunchConfiguration
24+
2425
from launch_ros.actions import Node
2526

2627

@@ -59,19 +60,19 @@ def generate_launch_description():
5960
default_value=os.path.join(bringup_dir, 'worlds', 'gz_waffle.sdf'),
6061
description='Full path to robot sdf file to spawn the robot in gazebo')
6162

62-
pkg_nav2_bringup = get_package_share_directory("nav2_bringup")
63+
pkg_nav2_bringup = get_package_share_directory('nav2_bringup')
6364
bridge = Node(
64-
package="ros_gz_bridge",
65-
executable="parameter_bridge",
65+
package='ros_gz_bridge',
66+
executable='parameter_bridge',
6667
parameters=[
6768
{
68-
"config_file": os.path.join(
69-
pkg_nav2_bringup, "params", "turtlebot3_waffle_bridge.yaml"
69+
'config_file': os.path.join(
70+
pkg_nav2_bringup, 'params', 'turtlebot3_waffle_bridge.yaml'
7071
),
71-
"qos_overrides./tf_static.publisher.durability": "transient_local",
72+
'qos_overrides./tf_static.publisher.durability': 'transient_local',
7273
}
7374
],
74-
output="screen",
75+
output='screen',
7576
)
7677

7778
spawn_model = Node(
@@ -87,9 +88,10 @@ def generate_launch_description():
8788
'-R', pose['R'], '-P', pose['P'], '-Y', pose['Y']]
8889
)
8990

90-
set_env_vars_resources = AppendEnvironmentVariable('GZ_SIM_RESOURCE_PATH',
91-
os.path.join(get_package_share_directory('turtlebot3_gazebo'),
92-
'models'))
91+
set_env_vars_resources = AppendEnvironmentVariable(
92+
'GZ_SIM_RESOURCE_PATH',
93+
os.path.join(get_package_share_directory('turtlebot3_gazebo'),
94+
'models'))
9395

9496
# Create the launch description and populate
9597
ld = LaunchDescription()

nav2_bringup/launch/tb3_gz_simulation_launch.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@
1515
"""This is all-in-one launch script intended for use by nav2 developers."""
1616

1717
import os
18+
import tempfile
1819

1920
from ament_index_python.packages import get_package_share_directory
2021

2122
from launch import LaunchDescription
2223
from launch.actions import (
24+
AppendEnvironmentVariable,
2325
DeclareLaunchArgument,
2426
ExecuteProcess,
2527
IncludeLaunchDescription,
26-
SetEnvironmentVariable,
28+
OpaqueFunction,
29+
RegisterEventHandler,
2730
)
28-
from launch.conditions import IfCondition, UnlessCondition
31+
from launch.conditions import IfCondition
32+
from launch.event_handlers import OnShutdown
2933
from launch.launch_description_sources import PythonLaunchDescriptionSource
3034
from launch.substitutions import LaunchConfiguration, PythonExpression
31-
from launch.substitutions import Command
35+
3236
from launch_ros.actions import Node
3337

3438

@@ -159,7 +163,7 @@ def generate_launch_description():
159163
# https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91
160164
# default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'),
161165
# worlds/turtlebot3_worlds/waffle.model')
162-
default_value=os.path.join(bringup_dir, 'worlds', 'gz_world_only.model'),
166+
default_value=os.path.join(bringup_dir, 'worlds', 'gz_world_only.sdf.xacro'),
163167
description='Full path to world model file to load',
164168
)
165169

@@ -215,29 +219,30 @@ def generate_launch_description():
215219
}.items(),
216220
)
217221

218-
gz_sim_server_config = SetEnvironmentVariable('GZ_SIM_SERVER_CONFIG_PATH',
219-
os.path.join(bringup_dir, 'worlds', 'gz_sim_server_config.xml'),
220-
condition=IfCondition(headless))
221-
222-
gz_start_scene_broadcaster = SetEnvironmentVariable('GZ_SIM_SERVER_CONFIG_PATH',
223-
os.path.join(bringup_dir, 'worlds', 'gz_sim_server_scene_broadcaster_config.xml'),
224-
condition=UnlessCondition(headless))
225-
222+
world_sdf = tempfile.mktemp(prefix='nav2_', suffix='.sdf')
223+
world_sdf_xacro = ExecuteProcess(
224+
cmd=['xacro', '-o', world_sdf, ['headless:=', headless], world])
226225
gazebo_server = IncludeLaunchDescription(
227226
PythonLaunchDescriptionSource(
228-
os.path.join(get_package_share_directory('ros_gz_sim'),
229-
'launch',
230-
'gz_sim.launch.py')
231-
),
232-
launch_arguments={'gz_args': ['-r -s ', world]}.items(),
233-
condition=IfCondition(use_simulator)
234-
)
235-
227+
os.path.join(get_package_share_directory('ros_gz_sim'), 'launch',
228+
'gz_sim.launch.py')),
229+
launch_arguments={'gz_args': ['-r -s ', world_sdf]}.items(),
230+
condition=IfCondition(use_simulator))
231+
232+
remove_temp_sdf_file = RegisterEventHandler(event_handler=OnShutdown(
233+
on_shutdown=[
234+
OpaqueFunction(function=lambda context: os.remove(world_sdf))
235+
]))
236+
237+
set_env_vars_resources = AppendEnvironmentVariable(
238+
'GZ_SIM_RESOURCE_PATH',
239+
os.path.join(get_package_share_directory('turtlebot3_gazebo'),
240+
'models'))
236241
gazebo_client = IncludeLaunchDescription(
237242
PythonLaunchDescriptionSource(
238243
os.path.join(get_package_share_directory('ros_gz_sim'),
239-
'launch',
240-
'gz_sim.launch.py')
244+
'launch',
245+
'gz_sim.launch.py')
241246
),
242247
condition=IfCondition(PythonExpression(
243248
[use_simulator, ' and not ', headless])),
@@ -282,10 +287,10 @@ def generate_launch_description():
282287
ld.add_action(declare_robot_sdf_cmd)
283288
ld.add_action(declare_use_respawn_cmd)
284289

285-
290+
ld.add_action(set_env_vars_resources)
291+
ld.add_action(world_sdf_xacro)
292+
ld.add_action(remove_temp_sdf_file)
286293
ld.add_action(gz_robot)
287-
ld.add_action(gz_sim_server_config)
288-
ld.add_action(gz_start_scene_broadcaster)
289294
ld.add_action(gazebo_server)
290295
ld.add_action(gazebo_client)
291296

nav2_bringup/launch/tb3_simulation_launch.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,10 @@ def generate_launch_description():
176176
condition=IfCondition(use_simulator),
177177
cmd=[
178178
'gzserver',
179-
'--verbose',
180179
'-s',
181180
'libgazebo_ros_init.so',
182181
'-s',
183182
'libgazebo_ros_factory.so',
184-
'-e',
185-
'dart',
186183
world,
187184
],
188185
cwd=[launch_dir],

nav2_bringup/urdf/gz_turtlebot3_waffle.urdf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277
<gazebo reference="base_scan">
278278
<sensor name='gpu_lidar' type='gpu_lidar'>"
279279
<topic>scan</topic>
280-
<ignition_frame_id>base_scan</ignition_frame_id>
280+
<gz_frame_id>base_scan</gz_frame_id>
281281
<pose>-0.064 0 0.15 0 0 0</pose>
282282
<update_rate>5</update_rate>
283283
<ray>
@@ -314,7 +314,7 @@
314314
<always_on>true</always_on>
315315
<update_rate>200</update_rate>
316316
<topic>imu</topic>
317-
<ignition_frame_id>imu_link</ignition_frame_id>
317+
<gz_frame_id>imu_link</gz_frame_id>
318318
<imu>
319319
<angular_velocity>
320320
<x>
@@ -362,7 +362,7 @@
362362

363363
<gazebo>
364364
<plugin
365-
filename="ignition-gazebo-diff-drive-system"
365+
filename="gz-sim-diff-drive-system"
366366
name="gz::sim::systems::DiffDrive">
367367
<left_joint>wheel_left_joint</left_joint>
368368
<right_joint>wheel_right_joint</right_joint>
@@ -385,8 +385,8 @@
385385
</plugin>
386386

387387
<plugin
388-
filename="ignition-gazebo-pose-publisher-system"
389-
name="ignition::gazebo::systems::PosePublisher">
388+
filename="gz-sim-pose-publisher-system"
389+
name="gz::sim::systems::PosePublisher">
390390
<publish_link_pose>true</publish_link_pose>
391391
<publish_sensor_pose>true</publish_sensor_pose>
392392
<publish_collision_pose>false</publish_collision_pose>

nav2_bringup/worlds/gz_sim_server_config.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

nav2_bringup/worlds/gz_sim_server_scene_broadcaster_config.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

nav2_bringup/worlds/gz_waffle.sdf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<scale>0.001 0.001 0.001</scale>
3838
</mesh>
3939
</geometry>
40+
<material>
41+
<diffuse>1 1 1</diffuse>
42+
</material>
4043
</visual>
4144
</link>
4245

@@ -45,7 +48,6 @@
4548
<always_on>true</always_on>
4649
<update_rate>200</update_rate>
4750
<topic>imu</topic>
48-
<ignition_frame_id>imu_link</ignition_frame_id>
4951
<gz_frame_id>imu_link</gz_frame_id>
5052
<imu>
5153
<angular_velocity>
@@ -124,6 +126,9 @@
124126
<scale>0.001 0.001 0.001</scale>
125127
</mesh>
126128
</geometry>
129+
<material>
130+
<diffuse>1 1 1</diffuse>
131+
</material>
127132
</visual>
128133

129134
<sensor name="hls_lfcd_lds" type="gpu_lidar">
@@ -132,7 +137,6 @@
132137
<pose>-0.064 0 0.15 0 0 0</pose>
133138
<update_rate>5</update_rate>
134139
<topic>scan</topic>
135-
<ignition_frame_id>base_scan</ignition_frame_id>
136140
<gz_frame_id>base_scan</gz_frame_id>
137141
<ray>
138142
<scan>
@@ -211,6 +215,9 @@
211215
<scale>0.001 0.001 0.001</scale>
212216
</mesh>
213217
</geometry>
218+
<material>
219+
<diffuse>1 1 1</diffuse>
220+
</material>
214221
</visual>
215222
</link>
216223

@@ -268,6 +275,9 @@
268275
<scale>0.001 0.001 0.001</scale>
269276
</mesh>
270277
</geometry>
278+
<material>
279+
<diffuse>1 1 1</diffuse>
280+
</material>
271281
</visual>
272282
</link>
273283

@@ -367,7 +377,6 @@
367377
<always_on>1</always_on>
368378
<update_rate>5</update_rate>
369379
<pose>0.064 -0.047 0.107 0 0 0</pose>
370-
<ignition_frame_id>camera_depth_frame</ignition_frame_id>
371380
<gz_frame_id>camera_depth_frame</gz_frame_id>
372381
<camera name="realsense_depth_camera">
373382
<horizontal_fov>1.047</horizontal_fov>

nav2_bringup/worlds/gz_world_only.model renamed to nav2_bringup/worlds/gz_world_only.sdf.xacro

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
<?xml version="1.0"?>
2-
<sdf version="1.6">
2+
<sdf version="1.6" xmlns:xacro="http://www.ros.org/wiki/xacro">
3+
<xacro:arg name="headless" default="true"/>
4+
35
<world name="default">
6+
<plugin
7+
filename="gz-sim-physics-system"
8+
name="gz::sim::systems::Physics">
9+
</plugin>
10+
<plugin
11+
filename="gz-sim-user-commands-system"
12+
name="gz::sim::systems::UserCommands">
13+
</plugin>
14+
<xacro:unless value="$(arg headless)">
15+
<plugin
16+
filename="gz-sim-scene-broadcaster-system"
17+
name="gz::sim::systems::SceneBroadcaster">
18+
</plugin>
19+
</xacro:unless>
20+
<plugin
21+
filename="gz-sim-sensors-system"
22+
name="gz::sim::systems::Sensors">
23+
<render_engine>ogre</render_engine>
24+
</plugin>
25+
<plugin
26+
filename="gz-sim-imu-system"
27+
name="gz::sim::systems::Imu">
28+
</plugin>
29+
430
<light name='sun' type='directional'>
531
<cast_shadows>0</cast_shadows>
632
<pose>0 0 10 0 0 0</pose>

0 commit comments

Comments
 (0)