33# SPDX-License-Identifier: Apache-2.0
44
55
6+ import math
67import xml .etree .ElementTree as ET
78
89from launch import LaunchContext , LaunchDescription
1617world_arg = LaunchArgument ("world" , "walls.sdf" )
1718robots_arg = LaunchArgument ("robots" , "" )
1819positions_arg = LaunchArgument ("positions" , "" )
20+ orientation_arg = LaunchArgument ("orientation" , "0,0,0,1" )
1921bridge_topics_arg = LaunchArgument ("bridge_topics" , "" )
2022
2123
@@ -35,6 +37,7 @@ def launch_setup(context: LaunchContext) -> list:
3537 world = world_arg .string_value (context )
3638 robots = robots_arg .string_value (context ).split ()
3739 positions = positions_arg .string_value (context ).split ()
40+ orientations = orientation_arg .string_value (context ).split ()
3841 bridge_topics = bridge_topics_arg .string_value (context ).split ()
3942
4043 sdf_file = get_file_path ("rcdt_gazebo" , ["worlds" ], world )
@@ -61,9 +64,21 @@ def launch_setup(context: LaunchContext) -> list:
6164 )
6265
6366 spawn_robots : list [Node ] = []
64- for robot , position in zip (robots , positions , strict = False ):
67+ for robot , position , orientation in zip (
68+ robots , positions , orientations , strict = False
69+ ):
6570 namespace = "" if not robot else f"/{ robot } "
6671 x , y , z = position .split ("," )
72+ qx , qy , qz , qw = orientation .split ("," )
73+ roll , pitch , yaw = 0 , 0 , 0
74+ if robot in {"realsense1" , "realsense" }:
75+ roll = 0
76+ pitch = math .radians (90 )
77+ yaw = 0
78+
79+ print (
80+ f"Spawning robot '{ robot } ' at position { position } with orientation { roll , pitch , yaw } in world '{ world_name } '"
81+ )
6782 spawn_robot = Node (
6883 package = "ros_gz_sim" ,
6984 executable = "create" ,
@@ -78,6 +93,12 @@ def launch_setup(context: LaunchContext) -> list:
7893 str (y ),
7994 "-z" ,
8095 str (z ),
96+ "-P" ,
97+ str (pitch ),
98+ "-R" ,
99+ str (roll ),
100+ "-Y" ,
101+ str (yaw ),
81102 ],
82103 output = "screen" ,
83104 )
@@ -125,6 +146,7 @@ def generate_launch_description() -> LaunchDescription:
125146 world_arg .declaration ,
126147 robots_arg .declaration ,
127148 positions_arg .declaration ,
149+ orientation_arg .declaration ,
128150 bridge_topics_arg .declaration ,
129151 OpaqueFunction (function = launch_setup ),
130152 ]
0 commit comments