11#!/usr/bin/env python3
22
33import os
4+ import xacro
45import yaml
56
67from launch import LaunchDescription
7- from launch .actions import IncludeLaunchDescription
8- from launch .launch_description_sources import PythonLaunchDescriptionSource
8+ from launch .actions import ExecuteProcess , RegisterEventHandler , TimerAction
9+ from launch .event_handlers import OnProcessExit
910from launch_ros .actions import Node
1011from ament_index_python .packages import get_package_share_directory
1112
@@ -24,26 +25,47 @@ def load_yaml(package_name, file_path):
2425
2526def generate_launch_description ():
2627
27- base_dir = os .path .dirname (__file__ )
28-
2928 # =========================
30- # WORLD + ROBOT
29+ # WORLD (HARMONIC)
3130 # =========================
3231
33- world_launch = IncludeLaunchDescription (
34- PythonLaunchDescriptionSource (
35- os . path . join ( base_dir , "world.launch.py" )
36- )
32+ world_path = os . path . join (
33+ get_package_share_directory ( "robotiq_description" ),
34+ "world" ,
35+ "warehouse_arm_harmonic.world"
3736 )
3837
39- robot_launch = IncludeLaunchDescription (
40- PythonLaunchDescriptionSource (
41- os .path .join (base_dir , "robot.launch.py" )
42- )
38+ gz = ExecuteProcess (
39+ cmd = ["gz" , "sim" , "-r" , "-v" , "4" , world_path ],
40+ output = "screen"
4341 )
4442
4543 # =========================
46- # MOVEIT PARAMS
44+ # ROBOT DESCRIPTION (CLAVE)
45+ # =========================
46+
47+ xacro_file = "/home/ws/src/Industrial/ros2_SimRealRobotControl_gz/packages/ur5/ros2srrc_ur5_gazebo/urdf/ur5_robotiq_2f85.urdf.xacro"
48+
49+ pkg_share_dir = get_package_share_directory ("ur5_gripper_description" )
50+ controllers_file = os .path .join (pkg_share_dir , "config" , "ur5_controllers.yaml" )
51+
52+ robot_description_content = xacro .process_file (
53+ xacro_file ,
54+ mappings = {
55+ "ur_type" : "ur5" ,
56+ "name" : "ur" ,
57+ "prefix" : "" ,
58+ "use_fake_hardware" : "false" ,
59+ "sim_gazebo" : "false" ,
60+ "sim_gz" : "true" ,
61+ "simulation_controllers" : controllers_file ,
62+ },
63+ ).toxml ()
64+
65+ robot_description = {"robot_description" : robot_description_content }
66+
67+ # =========================
68+ # SRDF + KINEMATICS
4769 # =========================
4870
4971 robot_description_semantic = {
@@ -60,47 +82,180 @@ def generate_launch_description():
6082 )
6183 }
6284
63- common_params = {}
64- common_params .update (robot_description_semantic )
65- common_params .update (kinematics_yaml )
85+ # =========================
86+ # ROBOT STATE PUBLISHER
87+ # =========================
88+
89+ robot_state_publisher = Node (
90+ package = "robot_state_publisher" ,
91+ executable = "robot_state_publisher" ,
92+ output = "screen" ,
93+ parameters = [robot_description , {"use_sim_time" : True }],
94+ )
95+
96+ static_tf = Node (
97+ package = "tf2_ros" ,
98+ executable = "static_transform_publisher" ,
99+ arguments = ["0" , "0" , "0.9" , "0" , "0" , "0" , "world" , "base_link" ],
100+ parameters = [{"use_sim_time" : True }],
101+ )
102+
103+ # =========================
104+ # SPAWN ROBOT (HARMONIC)
105+ # =========================
106+
107+ spawn_robot = Node (
108+ package = "ros_gz_sim" ,
109+ executable = "create" ,
110+ arguments = [
111+ "-topic" , "robot_description" ,
112+ "-name" , "ur5" ,
113+ "-x" , "0.0" ,
114+ "-y" , "0.0" ,
115+ "-z" , "0.9" ,
116+ ],
117+ output = "screen" ,
118+ )
119+
120+ # =========================
121+ # CLOCK BRIDGE
122+ # =========================
123+
124+ clock_bridge = Node (
125+ package = "ros_gz_bridge" ,
126+ executable = "parameter_bridge" ,
127+ arguments = ["/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock" ],
128+ parameters = [{"use_sim_time" : True }],
129+ )
130+
131+ # =========================
132+ # CONTROLLERS
133+ # =========================
134+
135+ joint_state_broadcaster = Node (
136+ package = "controller_manager" ,
137+ executable = "spawner" ,
138+ arguments = ["joint_state_broadcaster" ],
139+ )
140+
141+ joint_trajectory_controller = Node (
142+ package = "controller_manager" ,
143+ executable = "spawner" ,
144+ arguments = ["joint_trajectory_controller" ],
145+ )
146+
147+ gripper_controller = Node (
148+ package = "controller_manager" ,
149+ executable = "spawner" ,
150+ arguments = ["gripper_controller" ],
151+ )
152+
153+ # =========================
154+ # MOVE GROUP (IGUAL QUE CLASSIC)
155+ # =========================
66156
67- common_params .update ({
68- "use_sim_time" : True ,
69- "ROB_PARAM" : "ur5" ,
70- "EE_PARAM" : "robotiq_2f85" ,
71- "ENV_PARAM" : "gazebo" ,
72- })
157+ move_group = Node (
158+ package = "moveit_ros_move_group" ,
159+ executable = "move_group" ,
160+ output = "screen" ,
161+ parameters = [
162+ robot_description ,
163+ robot_description_semantic ,
164+ kinematics_yaml ,
165+ {"use_sim_time" : True },
166+ ],
167+ )
73168
74169 # =========================
75- # NODES
170+ # INTERFACES (CLÁSICO)
76171 # =========================
77172
173+ common_params = [
174+ robot_description ,
175+ robot_description_semantic ,
176+ kinematics_yaml ,
177+ {"use_sim_time" : True },
178+ {"ROB_PARAM" : "ur5" },
179+ {"EE_PARAM" : "robotiq_2f85" },
180+ {"ENV_PARAM" : "gazebo" },
181+ ]
182+
183+ move_node = Node (
184+ package = "ros2srrc_execution" ,
185+ executable = "move" ,
186+ output = "screen" ,
187+ parameters = common_params ,
188+ )
189+
78190 robmove_node = Node (
79191 package = "ros2srrc_execution" ,
80192 executable = "robmove" ,
81193 output = "screen" ,
82- parameters = [ common_params ] ,
194+ parameters = common_params ,
83195 )
84196
85197 robpose_node = Node (
86198 package = "ros2srrc_execution" ,
87199 executable = "robpose" ,
88200 output = "screen" ,
89- parameters = [ common_params ] ,
201+ parameters = common_params ,
90202 )
91203
92- move_node = Node (
93- package = "ros2srrc_execution" ,
94- executable = "move" ,
95- output = "screen" ,
96- parameters = [common_params ],
97- )
204+ # =========================
205+ # SECUENCIA (CLAVE)
206+ # =========================
98207
99208 return LaunchDescription ([
100- world_launch ,
101- robot_launch ,
102209
103- robmove_node ,
104- robpose_node ,
105- move_node
210+ gz ,
211+ robot_state_publisher ,
212+ static_tf ,
213+ clock_bridge ,
214+
215+ spawn_robot ,
216+
217+ RegisterEventHandler (
218+ OnProcessExit (
219+ target_action = spawn_robot ,
220+ on_exit = [joint_state_broadcaster ],
221+ )
222+ ),
223+
224+ RegisterEventHandler (
225+ OnProcessExit (
226+ target_action = joint_state_broadcaster ,
227+ on_exit = [joint_trajectory_controller ],
228+ )
229+ ),
230+
231+ RegisterEventHandler (
232+ OnProcessExit (
233+ target_action = joint_trajectory_controller ,
234+ on_exit = [gripper_controller ],
235+ )
236+ ),
237+
238+ RegisterEventHandler (
239+ OnProcessExit (
240+ target_action = spawn_robot ,
241+ on_exit = [
242+ TimerAction (
243+ period = 2.0 ,
244+ actions = [move_group ],
245+ )
246+ ],
247+ )
248+ ),
249+
250+ RegisterEventHandler (
251+ OnProcessExit (
252+ target_action = spawn_robot ,
253+ on_exit = [
254+ TimerAction (
255+ period = 4.0 ,
256+ actions = [move_node , robmove_node , robpose_node ],
257+ )
258+ ],
259+ )
260+ ),
106261 ])
0 commit comments