11import os
22from launch import LaunchDescription
3- from launch .actions import DeclareLaunchArgument , IncludeLaunchDescription , RegisterEventHandler
3+ from launch .actions import (
4+ DeclareLaunchArgument ,
5+ IncludeLaunchDescription ,
6+ RegisterEventHandler ,
7+ )
48from launch .substitutions import LaunchConfiguration
5- from launch .conditions import IfCondition , UnlessCondition
9+ from launch .conditions import (
10+ IfCondition ,
11+ UnlessCondition ,
12+ LaunchConfigurationNotEquals ,
13+ LaunchConfigurationEquals ,
14+ )
615from launch_ros .actions import Node
716from launch .actions import ExecuteProcess
817from launch .event_handlers import OnProcessExit
@@ -24,8 +33,22 @@ def generate_launch_description():
2433
2534 ros2_control_hardware_type = DeclareLaunchArgument (
2635 "ros2_control_hardware_type" ,
27- default_value = "sim_ignition" ,
28- description = "ROS2 control hardware interface type to use for the launch file -- possible values: [mock_components, isaac]" ,
36+ default_value = "mock_components" ,
37+ description = "ROS2 control hardware interface type to use for the launch file" ,
38+ choices = ["mock_components" , "isaac" , "sim_ignition" ],
39+ )
40+
41+ declare_initial_positions_file = DeclareLaunchArgument (
42+ "initial_positions_file" ,
43+ default_value = "initial_positions.yaml" ,
44+ description = "Initial joint positions to use for ros2_control fake components and simulation -- expected to be a yaml file inside the config directory" ,
45+ )
46+
47+ use_sim_time = LaunchConfiguration ("use_sim_time" )
48+ declare_use_sim_time_cmd = DeclareLaunchArgument (
49+ "use_sim_time" ,
50+ default_value = "False" ,
51+ description = "Use simulation (Gazebo) clock if True" ,
2952 )
3053
3154 moveit_config = (
@@ -35,7 +58,8 @@ def generate_launch_description():
3558 mappings = {
3659 "ros2_control_hardware_type" : LaunchConfiguration (
3760 "ros2_control_hardware_type"
38- )
61+ ),
62+ "initial_positions_file" : LaunchConfiguration ("initial_positions_file" ),
3963 },
4064 )
4165 .robot_description_semantic (file_path = "config/panda.srdf" )
@@ -52,8 +76,12 @@ def generate_launch_description():
5276 package = "moveit_ros_move_group" ,
5377 executable = "move_group" ,
5478 output = "log" ,
55- parameters = [moveit_config .to_dict ()],
56- arguments = ["--ros-args" , "--log-level" , "fatal" ], # MoveIt is spamming the log because of unknown '*_mimic' joints
79+ parameters = [moveit_config .to_dict (), {"use_sim_time" : use_sim_time }],
80+ arguments = [
81+ "--ros-args" ,
82+ "--log-level" ,
83+ "fatal" ,
84+ ], # MoveIt is spamming the log because of unknown '*_mimic' joints
5785 )
5886
5987 # RViz
@@ -89,6 +117,7 @@ def generate_launch_description():
89117 moveit_config .planning_pipelines ,
90118 moveit_config .robot_description_kinematics ,
91119 moveit_config .joint_limits ,
120+ {"use_sim_time" : use_sim_time },
92121 ],
93122 condition = UnlessCondition (tutorial_mode ),
94123 )
@@ -99,6 +128,7 @@ def generate_launch_description():
99128 executable = "static_transform_publisher" ,
100129 name = "static_transform_publisher" ,
101130 output = "log" ,
131+ parameters = [{"use_sim_time" : use_sim_time }],
102132 arguments = ["0.0" , "0.0" , "0.0" , "0.0" , "0.0" , "0.0" , "world" , "panda_link0" ],
103133 )
104134
@@ -108,62 +138,87 @@ def generate_launch_description():
108138 executable = "robot_state_publisher" ,
109139 name = "robot_state_publisher" ,
110140 output = "both" ,
111- parameters = [moveit_config .robot_description ],
141+ parameters = [moveit_config .robot_description , { "use_sim_time" : use_sim_time } ],
112142 )
113143
114- # NOTE: Comment out ros2_control for now
115144 # ros2_control using FakeSystem as hardware
116- # ros2_controllers_path = os.path.join(
117- # get_package_share_directory("moveit_resources_panda_moveit_config"),
118- # "config",
119- # "ros2_controllers.yaml",
120- # )
121- # ros2_control_node = Node(
122- # package="controller_manager",
123- # executable="ros2_control_node",
124- # parameters=[moveit_config.robot_description, ros2_controllers_path],
125- # output="screen",
126- # )
127-
128- # Parse xacro file to pass as string to Ignition
129- import xacro
130- robot_description_config = xacro .process_file (
131- os .path .join (
132- get_package_share_directory ("moveit_resources_panda_moveit_config" ),
133- "config" ,
134- "panda.urdf.xacro" ,
145+ ros2_controllers_path = os .path .join (
146+ get_package_share_directory ("moveit_resources_panda_moveit_config" ),
147+ "config" ,
148+ "ros2_controllers.yaml" ,
149+ )
150+ ros2_control_node = Node (
151+ package = "controller_manager" ,
152+ executable = "ros2_control_node" ,
153+ parameters = [moveit_config .robot_description , ros2_controllers_path ],
154+ output = "screen" ,
155+ condition = LaunchConfigurationNotEquals (
156+ "ros2_control_hardware_type" , "sim_ignition"
135157 ),
136- mappings = {"ros2_control_hardware_type" : "sim_ignition" }
137158 )
138159
139160 ignition_spawn_entity = Node (
140- package = ' ros_gz_sim' ,
141- executable = ' create' ,
142- output = ' screen' ,
161+ package = " ros_gz_sim" ,
162+ executable = " create" ,
163+ output = " screen" ,
143164 arguments = [
144- # '-string', robot_description_config.toxml(),
145- '-topic' , 'robot_description' ,
146- '-name' , 'panda' ,
147- '-allow-renaming' , 'true' ],
165+ "-topic" ,
166+ "robot_description" ,
167+ "-name" ,
168+ "panda" ,
169+ "-allow-renaming" ,
170+ "true" ,
171+ ],
172+ condition = LaunchConfigurationEquals (
173+ "ros2_control_hardware_type" , "sim_ignition"
174+ ),
148175 )
149176
177+ # Clock Bridge
178+ sim_clock_bridge = Node (
179+ package = "ros_gz_bridge" ,
180+ executable = "parameter_bridge" ,
181+ arguments = ["/clock@rosgraph_msgs/msg/Clock[ignition.msgs.Clock" ],
182+ output = "screen" ,
183+ condition = LaunchConfigurationEquals (
184+ "ros2_control_hardware_type" , "sim_ignition"
185+ ),
186+ )
150187
151188 load_joint_state_broadcaster = ExecuteProcess (
152- cmd = ['ros2' , 'control' , 'load_controller' , '--set-state' , 'active' ,
153- 'joint_state_broadcaster' ],
154- output = 'screen'
189+ cmd = [
190+ "ros2" ,
191+ "control" ,
192+ "load_controller" ,
193+ "--set-state" ,
194+ "active" ,
195+ "joint_state_broadcaster" ,
196+ ],
197+ output = "screen" ,
155198 )
156199
157- panda_arm_controller_spawner = Node (
158- package = "controller_manager" ,
159- executable = "spawner" ,
160- arguments = ["panda_arm_controller" , "-c" , "/controller_manager" ],
200+ panda_arm_controller_spawner = ExecuteProcess (
201+ cmd = [
202+ "ros2" ,
203+ "control" ,
204+ "load_controller" ,
205+ "--set-state" ,
206+ "active" ,
207+ "panda_arm_controller" ,
208+ ],
209+ output = "screen" ,
161210 )
162211
163- panda_hand_controller_spawner = Node (
164- package = "controller_manager" ,
165- executable = "spawner" ,
166- arguments = ["panda_hand_controller" , "-c" , "/controller_manager" ],
212+ panda_hand_controller_spawner = ExecuteProcess (
213+ cmd = [
214+ "ros2" ,
215+ "control" ,
216+ "load_controller" ,
217+ "--set-state" ,
218+ "active" ,
219+ "panda_hand_controller" ,
220+ ],
221+ output = "screen" ,
167222 )
168223
169224 # Warehouse mongodb server
@@ -180,28 +235,40 @@ def generate_launch_description():
180235 condition = IfCondition (db_config ),
181236 )
182237
183- return LaunchDescription ([
184- tutorial_arg ,
185- db_arg ,
186- ros2_control_hardware_type ,
187- # Launch gazebo environment
188- IncludeLaunchDescription (
189- PythonLaunchDescriptionSource (
190- [os .path .join (get_package_share_directory ('ros_ign_gazebo' ),
191- 'launch' , 'ign_gazebo.launch.py' )]),
192- launch_arguments = [('gz_args' , [' -r -v 4 empty.sdf' ])]),
193- move_group_node ,
194- RegisterEventHandler (
195- event_handler = OnProcessExit (
196- target_action = ignition_spawn_entity ,
197- on_exit = [load_joint_state_broadcaster ,
198- panda_arm_controller_spawner ,
199- panda_hand_controller_spawner ,],
200- )
201- ),
202- rviz_node ,
203- rviz_node_tutorial ,
204- static_tf_node ,
205- robot_state_publisher ,
206- mongodb_server_node ,
207- ])
238+ return LaunchDescription (
239+ [
240+ tutorial_arg ,
241+ db_arg ,
242+ ros2_control_hardware_type ,
243+ declare_use_sim_time_cmd ,
244+ declare_initial_positions_file ,
245+ sim_clock_bridge ,
246+ # Launch gazebo environment
247+ IncludeLaunchDescription (
248+ PythonLaunchDescriptionSource (
249+ [
250+ os .path .join (
251+ get_package_share_directory ("ros_gz_sim" ),
252+ "launch" ,
253+ "gz_sim.launch.py" ,
254+ )
255+ ]
256+ ),
257+ launch_arguments = [("gz_args" , [" -r -v 4 empty.sdf" ])],
258+ condition = LaunchConfigurationEquals (
259+ "ros2_control_hardware_type" , "sim_ignition"
260+ ),
261+ ),
262+ move_group_node ,
263+ ignition_spawn_entity ,
264+ ros2_control_node ,
265+ load_joint_state_broadcaster ,
266+ panda_arm_controller_spawner ,
267+ panda_hand_controller_spawner ,
268+ rviz_node ,
269+ rviz_node_tutorial ,
270+ static_tf_node ,
271+ robot_state_publisher ,
272+ mongodb_server_node ,
273+ ]
274+ )
0 commit comments