1- """
2- Pick Place Harmonic - Robot Launcher
3- Wraps spawn_robot_warehouse.launch.py
4- """
1+ #!/usr/bin/env python3
52
63import os
4+ import xacro
5+
76from launch import LaunchDescription
8- from launch .actions import IncludeLaunchDescription
9- from launch .launch_description_sources import PythonLaunchDescriptionSource
7+ from launch .actions import TimerAction , RegisterEventHandler
8+ from launch .event_handlers import OnProcessExit
9+ from launch_ros .actions import Node
1010from ament_index_python .packages import get_package_share_directory
1111
1212
1313def generate_launch_description ():
1414
15- try :
16- ur5_gripper_pkg = get_package_share_directory ("ur5_gripper_description" )
17- except Exception as e :
18- print (f"ERROR: Cannot find ur5_gripper_description package: { e } " )
19- print ("Make sure packages are built in /home/ws" )
20- raise
15+ pkg_share_dir = get_package_share_directory ("ur5_gripper_description" )
16+
17+ # =========================
18+ # URDF (XACRO)
19+ # =========================
20+
21+ xacro_file = os .path .join (
22+ pkg_share_dir , "urdf" , "ur5_robotiq85_gripper.urdf.xacro"
23+ )
24+
25+ controllers_file = os .path .join (
26+ pkg_share_dir , "config" , "ur5_controllers.yaml"
27+ )
28+
29+ robot_description_content = xacro .process_file (
30+ xacro_file ,
31+ mappings = {
32+ "ur_type" : "ur5" ,
33+ "name" : "ur" ,
34+ "prefix" : "" ,
35+ "use_fake_hardware" : "false" ,
36+ "sim_gazebo" : "false" ,
37+ "sim_gz" : "true" ,
38+ "simulation_controllers" : controllers_file ,
39+ },
40+ ).toxml ()
41+
42+ robot_description = {"robot_description" : robot_description_content }
2143
22- warehouse_launch_file = os .path .join (
23- ur5_gripper_pkg , "launch" , "spawn_robot_warehouse.launch.py"
44+ # =========================
45+ # ROBOT STATE PUBLISHER
46+ # =========================
47+
48+ robot_state_publisher = Node (
49+ package = "robot_state_publisher" ,
50+ executable = "robot_state_publisher" ,
51+ name = "robot_state_publisher" , # evita duplicados raros
52+ output = "screen" ,
53+ parameters = [robot_description , {"use_sim_time" : True }],
54+ )
55+
56+ # =========================
57+ # SPAWN ENTITY
58+ # =========================
59+
60+ spawn_entity = Node (
61+ package = "ros_gz_sim" ,
62+ executable = "create" ,
63+ arguments = [
64+ "-topic" , "robot_description" ,
65+ "-name" , "ur5_robotiq" ,
66+ "-allow_renaming" , "true" ,
67+ "-x" , "0.0" ,
68+ "-y" , "0.0" ,
69+ "-z" , "0.9" ,
70+ ],
71+ output = "screen" ,
2472 )
2573
26- print (f"Including launch file: { warehouse_launch_file } " )
74+ # =========================
75+ # TF
76+ # =========================
2777
28- warehouse_launch = IncludeLaunchDescription (
29- PythonLaunchDescriptionSource (warehouse_launch_file ),
30- launch_arguments = {
31- "launch_rviz" : "false" ,
32- }.items (),
78+ static_tf = Node (
79+ package = "tf2_ros" ,
80+ executable = "static_transform_publisher" ,
81+ arguments = ["0" , "0" , "0.9" , "0" , "0" , "0" , "world" , "base_link" ],
82+ output = "screen" ,
83+ parameters = [{"use_sim_time" : True }],
3384 )
3485
35- return LaunchDescription ([warehouse_launch ])
86+ # =========================
87+ # CLOCK
88+ # =========================
89+
90+ gz_ros2_bridge_clock = Node (
91+ package = "ros_gz_bridge" ,
92+ executable = "parameter_bridge" ,
93+ arguments = ["/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock" ],
94+ output = "screen" ,
95+ parameters = [{"use_sim_time" : True }],
96+ )
97+
98+ # =========================
99+ # CONTROLLERS
100+ # =========================
101+
102+ load_joint_state_broadcaster = Node (
103+ package = "controller_manager" ,
104+ executable = "spawner" ,
105+ arguments = [
106+ "joint_state_broadcaster" ,
107+ "--controller-manager" ,
108+ "/controller_manager" ,
109+ ],
110+ output = "screen" ,
111+ )
112+
113+ load_joint_trajectory_controller = Node (
114+ package = "controller_manager" ,
115+ executable = "spawner" ,
116+ arguments = [
117+ "joint_trajectory_controller" ,
118+ "--param-file" ,
119+ controllers_file ,
120+ "-c" ,
121+ "/controller_manager" ,
122+ ],
123+ output = "screen" ,
124+ )
125+
126+ load_gripper_controller = Node (
127+ package = "controller_manager" ,
128+ executable = "spawner" ,
129+ arguments = [
130+ "gripper_controller" ,
131+ "--param-file" ,
132+ controllers_file ,
133+ "-c" ,
134+ "/controller_manager" ,
135+ ],
136+ output = "screen" ,
137+ )
138+
139+ # =========================
140+ # DELAYS
141+ # =========================
142+
143+ delay_spawn = TimerAction (period = 3.0 , actions = [spawn_entity ])
144+
145+ delay_jsb = RegisterEventHandler (
146+ OnProcessExit (
147+ target_action = spawn_entity ,
148+ on_exit = [load_joint_state_broadcaster ],
149+ )
150+ )
151+
152+ delay_jtc = RegisterEventHandler (
153+ OnProcessExit (
154+ target_action = load_joint_state_broadcaster ,
155+ on_exit = [load_joint_trajectory_controller ],
156+ )
157+ )
158+
159+ delay_gc = RegisterEventHandler (
160+ OnProcessExit (
161+ target_action = load_joint_trajectory_controller ,
162+ on_exit = [load_gripper_controller ],
163+ )
164+ )
165+
166+ return LaunchDescription ([
167+ robot_state_publisher ,
168+ static_tf ,
169+ gz_ros2_bridge_clock ,
170+
171+ delay_spawn ,
172+ delay_jsb ,
173+ delay_jtc ,
174+ delay_gc ,
175+ ])
0 commit comments