1+ import os
2+ from launch import LaunchDescription
3+ from launch .actions import DeclareLaunchArgument
4+ from launch .substitutions import LaunchConfiguration
5+ from launch_ros .actions import Node
6+ from launch .conditions import UnlessCondition
7+ from launch_ros .parameter_descriptions import ParameterValue
8+ from launch .substitutions import Command
9+ from ament_index_python .packages import get_package_share_directory
10+
11+ def generate_launch_description ():
12+
13+ is_sim_arg = DeclareLaunchArgument (
14+ "is_sim" ,
15+ default_value = "True"
16+ )
17+
18+ is_sim = LaunchConfiguration ("is_sim" )
19+
20+ robot_description = ParameterValue (
21+ Command ([
22+ "xacro " ,
23+ os .path .join (
24+ get_package_share_directory ("manipulator_description" ),
25+ "urdf" ,
26+ "manipulator.urdf.xacro" ,
27+ ),
28+ ]
29+ ),
30+ value_type = str ,
31+ )
32+
33+ robot_state_publisher_node = Node (
34+ package = 'robot_state_publisher' ,
35+ executable = 'robot_state_publisher' ,
36+ condition = UnlessCondition (is_sim ),
37+ parameters = [{"robot_description" : robot_description }],
38+ )
39+
40+ controller_manager = Node (
41+ package = "controller_manager" ,
42+ executable = "ros2_control_node" ,
43+ parameters = [
44+ {"robot_description" : robot_description ,
45+ "use_sim_time" : is_sim },
46+ os .path .join (
47+ get_package_share_directory ("manipulator_controller" ),
48+ "config" ,
49+ "manipulator_controllers.yaml"
50+ )
51+ ],
52+ condition = UnlessCondition (is_sim ),
53+ )
54+
55+ joint_state_broadcaster_spawner = Node (
56+ package = "controller_manager" ,
57+ executable = "spawner" ,
58+ arguments = ["joint_state_broadcaster" , "--controller-manager" , "/controller_manager" ],
59+ )
60+
61+ arm_controller_spawner = Node (
62+ package = "controller_manager" ,
63+ executable = "spawner" ,
64+ arguments = ["arm_controller" , "--controller-manager" , "/controller_manager" ],
65+ )
66+
67+ gripper_controller_spawner = Node (
68+ package = "controller_manager" ,
69+ executable = "spawner" ,
70+ arguments = ["gripper_controller" , "--controller-manager" , "/controller_manager" ],
71+ )
72+
73+ return LaunchDescription ([
74+ is_sim_arg ,
75+ robot_state_publisher_node ,
76+ controller_manager ,
77+ joint_state_broadcaster_spawner ,
78+ arm_controller_spawner ,
79+ gripper_controller_spawner
80+ ])
0 commit comments