22from launch import LaunchDescription
33from launch .actions import DeclareLaunchArgument , IncludeLaunchDescription , RegisterEventHandler
44from launch .substitutions import LaunchConfiguration
5- from launch .conditions import IfCondition , UnlessCondition
5+ from launch .conditions import IfCondition , UnlessCondition , LaunchConfigurationNotEquals , LaunchConfigurationEquals
66from launch_ros .actions import Node
77from launch .actions import ExecuteProcess
88from launch .event_handlers import OnProcessExit
@@ -24,8 +24,22 @@ def generate_launch_description():
2424
2525 ros2_control_hardware_type = DeclareLaunchArgument (
2626 "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]" ,
27+ default_value = "mock_components" ,
28+ description = "ROS2 control hardware interface type to use for the launch file" ,
29+ choices = ['mock_components' , 'isaac' , 'sim_ignition' ]
30+ )
31+
32+ declare_initial_positions_file = DeclareLaunchArgument (
33+ "initial_positions_file" ,
34+ default_value = "initial_positions.yaml" ,
35+ description = "Initial joint positions to use for ros2_control fake components and simulation -- expected to be a yaml file inside the config directory" ,
36+ )
37+
38+ use_sim_time = LaunchConfiguration ("use_sim_time" )
39+ declare_use_sim_time_cmd = DeclareLaunchArgument (
40+ "use_sim_time" ,
41+ default_value = "False" ,
42+ description = "Use simulation (Gazebo) clock if True" ,
2943 )
3044
3145 moveit_config = (
@@ -35,6 +49,9 @@ def generate_launch_description():
3549 mappings = {
3650 "ros2_control_hardware_type" : LaunchConfiguration (
3751 "ros2_control_hardware_type"
52+ ),
53+ "initial_positions_file" : LaunchConfiguration (
54+ "initial_positions_file"
3855 )
3956 },
4057 )
@@ -52,7 +69,8 @@ def generate_launch_description():
5269 package = "moveit_ros_move_group" ,
5370 executable = "move_group" ,
5471 output = "log" ,
55- parameters = [moveit_config .to_dict ()],
72+ parameters = [moveit_config .to_dict (),
73+ {"use_sim_time" : use_sim_time }],
5674 arguments = ["--ros-args" , "--log-level" , "fatal" ], # MoveIt is spamming the log because of unknown '*_mimic' joints
5775 )
5876
@@ -89,6 +107,7 @@ def generate_launch_description():
89107 moveit_config .planning_pipelines ,
90108 moveit_config .robot_description_kinematics ,
91109 moveit_config .joint_limits ,
110+ {"use_sim_time" : use_sim_time },
92111 ],
93112 condition = UnlessCondition (tutorial_mode ),
94113 )
@@ -99,6 +118,7 @@ def generate_launch_description():
99118 executable = "static_transform_publisher" ,
100119 name = "static_transform_publisher" ,
101120 output = "log" ,
121+ parameters = [{"use_sim_time" : use_sim_time }],
102122 arguments = ["0.0" , "0.0" , "0.0" , "0.0" , "0.0" , "0.0" , "world" , "panda_link0" ],
103123 )
104124
@@ -108,62 +128,59 @@ def generate_launch_description():
108128 executable = "robot_state_publisher" ,
109129 name = "robot_state_publisher" ,
110130 output = "both" ,
111- parameters = [moveit_config .robot_description ],
131+ parameters = [moveit_config .robot_description ,
132+ {"use_sim_time" : use_sim_time }],
112133 )
113134
114- # NOTE: Comment out ros2_control for now
115135 # 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" ,
135- ),
136- mappings = {"ros2_control_hardware_type" : "sim_ignition" }
136+ ros2_controllers_path = os .path .join (
137+ get_package_share_directory ("moveit_resources_panda_moveit_config" ),
138+ "config" ,
139+ "ros2_controllers.yaml" ,
140+ )
141+ ros2_control_node = Node (
142+ package = "controller_manager" ,
143+ executable = "ros2_control_node" ,
144+ parameters = [moveit_config .robot_description , ros2_controllers_path ],
145+ output = "screen" ,
146+ condition = LaunchConfigurationNotEquals ("ros2_control_hardware_type" , "sim_ignition" )
137147 )
138148
139149 ignition_spawn_entity = Node (
140150 package = 'ros_gz_sim' ,
141151 executable = 'create' ,
142152 output = 'screen' ,
143- arguments = [
144- # '-string', robot_description_config.toxml(),
145- '-topic' , 'robot_description' ,
153+ arguments = ['-topic' , 'robot_description' ,
146154 '-name' , 'panda' ,
147155 '-allow-renaming' , 'true' ],
156+ condition = LaunchConfigurationEquals ("ros2_control_hardware_type" , "sim_ignition" )
148157 )
149158
159+ # Clock Bridge
160+ sim_clock_bridge = Node (
161+ package = "ros_gz_bridge" ,
162+ executable = "parameter_bridge" ,
163+ arguments = ["/clock@rosgraph_msgs/msg/Clock[ignition.msgs.Clock" ],
164+ output = "screen" ,
165+ condition = LaunchConfigurationEquals ("ros2_control_hardware_type" , "sim_ignition" )
166+ )
150167
151168 load_joint_state_broadcaster = ExecuteProcess (
152169 cmd = ['ros2' , 'control' , 'load_controller' , '--set-state' , 'active' ,
153170 'joint_state_broadcaster' ],
154171 output = 'screen'
155172 )
156173
157- panda_arm_controller_spawner = Node (
158- package = "controller_manager" ,
159- executable = "spawner" ,
160- arguments = [ "panda_arm_controller" , "-c" , "/controller_manager" ],
174+ panda_arm_controller_spawner = ExecuteProcess (
175+ cmd = [ 'ros2' , 'control' , 'load_controller' , '--set-state' , 'active' ,
176+ 'panda_arm_controller' ] ,
177+ output = 'screen'
161178 )
162179
163- panda_hand_controller_spawner = Node (
164- package = "controller_manager" ,
165- executable = "spawner" ,
166- arguments = [ "panda_hand_controller" , "-c" , "/controller_manager" ],
180+ panda_hand_controller_spawner = ExecuteProcess (
181+ cmd = [ 'ros2' , 'control' , 'load_controller' , '--set-state' , 'active' ,
182+ 'panda_hand_controller' ] ,
183+ output = 'screen'
167184 )
168185
169186 # Warehouse mongodb server
@@ -184,21 +201,22 @@ def generate_launch_description():
184201 tutorial_arg ,
185202 db_arg ,
186203 ros2_control_hardware_type ,
204+ declare_use_sim_time_cmd ,
205+ declare_initial_positions_file ,
206+ sim_clock_bridge ,
187207 # Launch gazebo environment
188208 IncludeLaunchDescription (
189209 PythonLaunchDescriptionSource (
190210 [os .path .join (get_package_share_directory ('ros_ign_gazebo' ),
191211 'launch' , 'ign_gazebo.launch.py' )]),
192- launch_arguments = [('gz_args' , [' -r -v 4 empty.sdf' ])]),
212+ launch_arguments = [('gz_args' , [' -r -v 4 empty.sdf' ])],
213+ condition = LaunchConfigurationEquals ("ros2_control_hardware_type" , "sim_ignition" )),
193214 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- ),
215+ ignition_spawn_entity ,
216+ ros2_control_node ,
217+ load_joint_state_broadcaster ,
218+ panda_arm_controller_spawner ,
219+ panda_hand_controller_spawner ,
202220 rviz_node ,
203221 rviz_node_tutorial ,
204222 static_tf_node ,
0 commit comments