-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsm_bringup.launch.py
144 lines (126 loc) · 4.59 KB
/
psm_bringup.launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from launch import LaunchDescription
from launch.substitutions import Command, PathJoinSubstitution, FindExecutable, LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from launch_ros.descriptions import ParameterValue
from launch.actions import RegisterEventHandler, DeclareLaunchArgument
from launch.event_handlers import OnProcessExit
def generate_launch_description():
# Get the URDF Xacro file
urdf_arg = DeclareLaunchArgument(
"urdf",
default_value="psm.classic.urdf.xacro",
description="Name of the URDF file",
)
# Get the tool name
tool_arg = DeclareLaunchArgument(
"tool",
default_value="sca",
description="Name of the tool",
choices=["blade", "caudier_blade", "caudier", "sca_blade", "sca", "snake", "P420006", "SF826001"],
)
# Get robot description via xacro
robot_description = {
"robot_description": ParameterValue(
Command([
PathJoinSubstitution([FindExecutable(name="xacro")]),
" ",
PathJoinSubstitution(
[FindPackageShare("psm_description"), "urdf", LaunchConfiguration("urdf")]
),
" ",
"tool:=", LaunchConfiguration("tool")
]),
value_type=str
)
}
# Controller Configuration File Generator
controller_yaml_generator = Node(
package="psm_description",
executable="generate_controller.py",
output="screen",
arguments=[LaunchConfiguration("urdf"), LaunchConfiguration("tool")]
)
# Path to the controller configuration file
controller_file = "psm.controllers.yaml"
# Path to the controller configuration file
controller_config = PathJoinSubstitution(
[FindPackageShare("psm_description"), "config", controller_file]
)
# For ros2_control_node
controller_manager = Node(
package="controller_manager",
executable="ros2_control_node",
output="screen",
parameters=[controller_config, {'use_sim_time': True}],
remappings=[('~/robot_description', '/robot_description')]
)
# For robot_state_publisher
robot_state_publisher = Node(
package="robot_state_publisher",
executable="robot_state_publisher",
output="screen",
parameters=[robot_description, {'publish_robot_description': True, 'use_sim_time': True}],
)
# Load joint state broadcaster
load_joint_state_broadcaster = Node(
package='controller_manager',
executable='spawner',
arguments=['joint_state_broadcaster', '--controller-manager', '/controller_manager'],
parameters=[{'use_sim_time': True}],
output='screen',
)
# Load the joint group position controller
load_joint_group_position_controller = Node(
package='controller_manager',
executable='spawner',
arguments=['forward_position_controller', '--controller-manager', '/controller_manager'],
output='screen',
)
# Joint Position Controller Node
joint_position_controller = Node(
package="psm_description",
executable="psm_joint_controller",
output="screen",
parameters=[{'use_sim_time': True}]
)
# Path to the RViz file
psm_rviz_file = PathJoinSubstitution(
[FindPackageShare("psm_description"), "rviz", "psm_description.rviz"]
)
# For RViz
rviz_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='screen',
parameters=[{'use_sim_time': True}],
arguments=['-d', psm_rviz_file],
)
# Delay rviz start after `joint_state_broadcaster`
delay_rviz_after_joint_state_broadcaster_spawner = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=load_joint_state_broadcaster,
on_exit=[rviz_node],
)
)
# Delay till controller.yaml is generated
delay_till_controller_yaml_generator = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=controller_yaml_generator,
on_exit=[
robot_state_publisher,
controller_manager,
load_joint_state_broadcaster,
load_joint_group_position_controller,
joint_position_controller,
delay_rviz_after_joint_state_broadcaster_spawner
],
)
)
return LaunchDescription([
urdf_arg,
tool_arg,
controller_yaml_generator,
delay_till_controller_yaml_generator,
])