1414# limitations under the License.
1515
1616import os
17+ from pathlib import Path
1718import sys
1819
1920from ament_index_python .packages import get_package_share_directory
2021
2122from launch import LaunchDescription
2223from launch import LaunchService
2324from launch .actions import (
25+ AppendEnvironmentVariable ,
2426 ExecuteProcess ,
2527 IncludeLaunchDescription ,
2628 SetEnvironmentVariable ,
3032from launch_testing .legacy import LaunchTestService
3133
3234from nav2_common .launch import RewrittenYaml
35+ from nav2_simple_commander .utils import kill_os_processes
3336
3437
3538def generate_launch_description ():
36- map_yaml_file = os .getenv ('TEST_MAP' )
37- world = os .getenv ('TEST_WORLD' )
39+ sim_dir = get_package_share_directory ('nav2_minimal_tb3_sim' )
40+ nav2_bringup_dir = get_package_share_directory ('nav2_bringup' )
41+ ros_gz_sim_dir = get_package_share_directory ('ros_gz_sim' )
42+
43+ world_sdf_xacro = os .path .join (sim_dir , 'worlds' , 'tb3_sandbox.sdf.xacro' )
44+ robot_sdf = os .path .join (sim_dir , 'urdf' , 'gz_waffle.sdf.xacro' )
45+
46+ urdf = os .path .join (sim_dir , 'urdf' , 'turtlebot3_waffle.urdf' )
47+ with open (urdf , 'r' ) as infp :
48+ robot_description = infp .read ()
49+
50+ map_yaml_file = os .path .join (nav2_bringup_dir , 'maps' , 'tb3_sandbox.yaml' )
3851
3952 bt_navigator_xml = os .path .join (
4053 get_package_share_directory ('nav2_bt_navigator' ),
@@ -55,31 +68,42 @@ def generate_launch_description():
5568 SetEnvironmentVariable ('RCUTILS_LOGGING_BUFFERED_STREAM' , '1' ),
5669 SetEnvironmentVariable ('RCUTILS_LOGGING_USE_STDOUT' , '1' ),
5770 # Launch gazebo server for simulation
58- ExecuteProcess (
59- cmd = [
60- 'gzserver' ,
61- '-s' ,
62- 'libgazebo_ros_init.so' ,
63- '-s' ,
64- 'libgazebo_ros_factory.so' ,
65- '--minimal_comms' ,
66- world ,
67- ],
68- output = 'screen' ,
71+ AppendEnvironmentVariable (
72+ 'GZ_SIM_RESOURCE_PATH' , os .path .join (sim_dir , 'models' )
6973 ),
70- # TODO(orduno) Launch the robot state publisher instead
71- # using a local copy of TB3 urdf file
72- Node (
73- package = 'tf2_ros' ,
74- executable = 'static_transform_publisher' ,
75- output = 'screen' ,
76- arguments = ['0' , '0' , '0' , '0' , '0' , '0' , 'base_footprint' , 'base_link' ],
74+ AppendEnvironmentVariable (
75+ 'GZ_SIM_RESOURCE_PATH' ,
76+ str (Path (os .path .join (sim_dir )).parent .resolve ())
77+ ),
78+ IncludeLaunchDescription (
79+ PythonLaunchDescriptionSource (
80+ os .path .join (ros_gz_sim_dir , 'launch' , 'gz_sim.launch.py' )
81+ ),
82+ launch_arguments = {'gz_args' : ['-r -s ' , world_sdf_xacro ]}.items (),
83+ ),
84+ IncludeLaunchDescription (
85+ PythonLaunchDescriptionSource (
86+ os .path .join (sim_dir , 'launch' , 'spawn_tb3.launch.py' )
87+ ),
88+ launch_arguments = {
89+ 'use_sim_time' : 'True' ,
90+ 'robot_sdf' : robot_sdf ,
91+ 'x_pose' : '-2.0' ,
92+ 'y_pose' : '-0.5' ,
93+ 'z_pose' : '0.01' ,
94+ 'roll' : '0.0' ,
95+ 'pitch' : '0.0' ,
96+ 'yaw' : '0.0' ,
97+ }.items (),
7798 ),
7899 Node (
79- package = 'tf2_ros' ,
80- executable = 'static_transform_publisher' ,
100+ package = 'robot_state_publisher' ,
101+ executable = 'robot_state_publisher' ,
102+ name = 'robot_state_publisher' ,
81103 output = 'screen' ,
82- arguments = ['0' , '0' , '0' , '0' , '0' , '0' , 'base_link' , 'base_scan' ],
104+ parameters = [
105+ {'use_sim_time' : True , 'robot_description' : robot_description }
106+ ],
83107 ),
84108 IncludeLaunchDescription (
85109 PythonLaunchDescriptionSource (
@@ -111,7 +135,9 @@ def main(argv=sys.argv[1:]):
111135 lts .add_test_action (ld , test1_action )
112136 ls = LaunchService (argv = argv )
113137 ls .include_launch_description (ld )
114- return lts .run (ls )
138+ return_code = lts .run (ls )
139+ kill_os_processes ('gz sim' )
140+ return return_code
115141
116142
117143if __name__ == '__main__' :
0 commit comments