forked from xArm-Developer/xarm_ros2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_realmove.launch.py
139 lines (123 loc) · 4.83 KB
/
demo_realmove.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
import os
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch_ros.actions import Node
from launch.actions import OpaqueFunction
from launch_ros.substitutions import FindPackageShare
from ament_index_python.packages import get_package_share_directory
from uf_ros_lib.uf_robot_utils import generate_ros2_control_params_temp_file
from uf_ros_lib.moveit_configs_builder import MoveItConfigsBuilder
def launch_setup(context, *args, **kwargs):
robot_ip = LaunchConfiguration('robot_ip')
dof = LaunchConfiguration('dof', default=7)
robot_type = LaunchConfiguration('robot_type', default='xarm')
prefix = LaunchConfiguration('prefix', default='')
hw_ns = LaunchConfiguration('hw_ns', default='xarm')
add_gripper = LaunchConfiguration('add_gripper', default=False)
add_vacuum_gripper = LaunchConfiguration('add_vacuum_gripper', default=False)
add_bio_gripper = LaunchConfiguration('add_bio_gripper', default=False)
xarm_type = '{}{}'.format(robot_type.perform(context), dof.perform(context) if robot_type.perform(context) in ('xarm', 'lite') else '')
# ros2_controllers_path
ros2_controllers_path = generate_ros2_control_params_temp_file(
os.path.join(get_package_share_directory('xarm_controller'), 'config', '{}_controllers.yaml'.format(xarm_type)),
prefix=prefix.perform(context),
add_gripper=add_gripper.perform(context) in ('True', 'true'),
add_bio_gripper=add_bio_gripper.perform(context) in ('True', 'true'),
robot_type=robot_type.perform(context)
)
moveit_config = MoveItConfigsBuilder(
context=context,
controllers_name='controllers',
robot_ip=robot_ip,
dof=dof,
robot_type=robot_type,
prefix=prefix,
hw_ns=hw_ns,
add_gripper=add_gripper,
add_vacuum_gripper=add_vacuum_gripper,
add_bio_gripper=add_bio_gripper,
ros2_control_plugin='uf_robot_hardware/UFRobotSystemHardware',
ros2_control_params=ros2_controllers_path,
).to_moveit_configs()
# Start the actual move_group node/action server
move_group_node = Node(
package='moveit_ros_move_group',
executable='move_group',
output='screen',
parameters=[moveit_config.to_dict()],
)
# Launch RViz
rviz_config = PathJoinSubstitution([FindPackageShare('xarm_moveit_config'), 'rviz', 'moveit.rviz'])
rviz_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='screen',
arguments=['-d', rviz_config],
parameters=[
moveit_config.robot_description,
moveit_config.robot_description_semantic,
moveit_config.robot_description_kinematics,
moveit_config.planning_pipelines,
moveit_config.joint_limits,
],
)
static_tf = Node(
package='tf2_ros',
executable='static_transform_publisher',
name='static_transform_publisher',
output='screen',
arguments=['0', '0', '0', '0', '0', '0', 'world', '{}link_base'.format(prefix.perform(context))],
)
# Publish TF
robot_state_publisher = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
output='screen',
parameters=[moveit_config.robot_description],
)
ros2_control_node = Node(
package='controller_manager',
executable='ros2_control_node',
parameters=[
moveit_config.robot_description,
ros2_controllers_path,
],
output='screen',
)
remappings = [
('follow_joint_trajectory', '{}{}_traj_controller/follow_joint_trajectory'.format(prefix.perform(context), xarm_type)),
]
controllers = ['{}{}_traj_controller'.format(prefix.perform(context), xarm_type)]
joint_state_publisher_node = Node(
package='joint_state_publisher',
executable='joint_state_publisher',
name='joint_state_publisher',
output='screen',
parameters=[{'source_list': ['{}{}/joint_states'.format(prefix.perform(context), hw_ns.perform(context))]}],
remappings=remappings,
)
controller_nodes = []
for controller in controllers:
controller_nodes.append(Node(
package='controller_manager',
executable='spawner',
output='screen',
arguments=[
controller,
'--controller-manager', '/controller_manager'
],
))
return [
robot_state_publisher,
joint_state_publisher_node,
move_group_node,
static_tf,
ros2_control_node,
rviz_node,
] + controller_nodes
def generate_launch_description():
return LaunchDescription([
OpaqueFunction(function=launch_setup)
])