Start the ur_robot_driver
In the last chapter we created a custom scene description containing our two robots. In order to make
that description usable to ros2_control and hence the ur_robot_driver, we need to add
control information. We will also add a custom launchfile to start up our demonstrator.
We will generate a new package called my_dual_robot_cell_control for that purpose.
Create a description with ros2_control tag
The first step is to create a description containing the control instructions:
1<?xml version="1.0"?>
2<robot name="my_dual_robot_cell" xmlns:xacro="http://ros.org/wiki/xacro">
3
4 <!--First, include the macro from our custom description-->
5 <xacro:include
6 filename="$(find my_dual_robot_cell_description)/urdf/my_dual_robot_cell_macro.xacro" />
7 <!--The driver already provides a control tag for the UR arm, we can directly include-->
8 <xacro:include filename="$(find ur_robot_driver)/urdf/ur.ros2_control.xacro" />
9
10 <!--We need to specify the arguments used for parametrizing our description-->
11 <xacro:arg name="alice_ur_type" default="ur3e" />
12 <xacro:arg name="alice_joint_limits_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/joint_limits.yaml" />
13 <xacro:arg name="alice_kinematics_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/default_kinematics.yaml" />
14 <xacro:arg name="alice_physical_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/physical_parameters.yaml" />
15 <xacro:arg name="alice_visual_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/visual_parameters.yaml" />
16
17 <xacro:arg name="bob_ur_type" default="ur5e" />
18 <xacro:arg name="bob_joint_limits_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/joint_limits.yaml" />
19 <xacro:arg name="bob_kinematics_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/default_kinematics.yaml" />
20 <xacro:arg name="bob_physical_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/physical_parameters.yaml" />
21 <xacro:arg name="bob_visual_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/visual_parameters.yaml" />
22
23 <xacro:arg name="alice_use_mock_hardware" default="false" />
24 <xacro:arg name="alice_mock_sensor_commands" default="false" />
25 <xacro:arg name="alice_robot_ip" default="192.168.57.101" />
26 <xacro:arg name="alice_reverse_port" default="50006" />
27 <xacro:arg name="alice_script_sender_port" default="50007" />
28 <xacro:arg name="alice_script_command_port" default="50010" />
29 <xacro:arg name="alice_trajectory_port" default="50009" />
30
31 <xacro:arg name="bob_use_mock_hardware" default="false" />
32 <xacro:arg name="bob_mock_sensor_commands" default="false" />
33 <xacro:arg name="bob_robot_ip" default="192.168.57.100" />
34 <xacro:arg name="bob_reverse_port" default="50001" />
35 <xacro:arg name="bob_script_sender_port" default="50002" />
36 <xacro:arg name="bob_script_command_port" default="50004" />
37 <xacro:arg name="bob_trajectory_port" default="50003" />
38
39 <xacro:arg name="headless_mode" default="false" />
40 <xacro:arg name="ur_script_filename" default="$(find ur_client_library)/resources/external_control.urscript" />
41 <xacro:arg name="ur_output_recipe_filename" default="$(find ur_robot_driver)/resources/rtde_output_recipe.txt" />
42 <xacro:arg name="ur_input_recipe_filename" default="$(find ur_robot_driver)/resources/rtde_input_recipe.txt" />
43
44
45 <link name="world" />
46
47 <xacro:my_dual_robot_cell
48 parent="world"
49 alice_ur_type="$(arg alice_ur_type)"
50 alice_joint_limits_parameters_file="$(arg alice_joint_limits_parameters_file)"
51 alice_kinematics_parameters_file="$(arg alice_kinematics_parameters_file)"
52 alice_physical_parameters_file="$(arg alice_physical_parameters_file)"
53 alice_visual_parameters_file="$(arg alice_visual_parameters_file)"
54 bob_ur_type="$(arg bob_ur_type)"
55 bob_joint_limits_parameters_file="$(arg bob_joint_limits_parameters_file)"
56 bob_kinematics_parameters_file="$(arg bob_kinematics_parameters_file)"
57 bob_physical_parameters_file="$(arg bob_physical_parameters_file)"
58 bob_visual_parameters_file="$(arg bob_visual_parameters_file)"
59 >
60 <origin xyz="0 0 1" rpy="0 0 0" />
61 </xacro:my_dual_robot_cell>
62
63 <xacro:ur_ros2_control
64 name="alice"
65 ur_type="$(arg alice_ur_type)"
66 tf_prefix="alice_"
67 kinematics_parameters_file="$(arg alice_kinematics_parameters_file)"
68 robot_ip="$(arg alice_robot_ip)"
69 script_filename="$(arg ur_script_filename)"
70 output_recipe_filename="$(arg ur_output_recipe_filename)"
71 input_recipe_filename="$(arg ur_input_recipe_filename)"
72 use_mock_hardware="$(arg alice_use_mock_hardware)"
73 mock_sensor_commands="$(arg alice_mock_sensor_commands)"
74 headless_mode="$(arg headless_mode)"
75 reverse_port="$(arg alice_reverse_port)"
76 script_sender_port="$(arg alice_script_sender_port)"
77 script_command_port="$(arg alice_script_command_port)"
78 trajectory_port="$(arg alice_trajectory_port)"
79 />
80
81 <xacro:ur_ros2_control
82 name="bob"
83 ur_type="$(arg bob_ur_type)"
84 tf_prefix="bob_"
85 kinematics_parameters_file="$(arg bob_kinematics_parameters_file)"
86 robot_ip="$(arg bob_robot_ip)"
87 script_filename="$(arg ur_script_filename)"
88 output_recipe_filename="$(arg ur_output_recipe_filename)"
89 input_recipe_filename="$(arg ur_input_recipe_filename)"
90 use_mock_hardware="$(arg bob_use_mock_hardware)"
91 mock_sensor_commands="$(arg bob_mock_sensor_commands)"
92 headless_mode="$(arg headless_mode)"
93 reverse_port="$(arg bob_reverse_port)"
94 script_sender_port="$(arg bob_script_sender_port)"
95 script_command_port="$(arg bob_script_command_port)"
96 trajectory_port="$(arg bob_trajectory_port)"
97 />
98
99</robot>
This URDF is very similar to the one we have already assembled. We simply need to include the ros2_control macro,
<xacro:include filename="$(find ur_robot_driver)/urdf/ur.ros2_control.xacro" />
define the necessary arguments that need to be passed to the macro,
<xacro:arg name="alice_use_mock_hardware" default="false" />
<xacro:arg name="alice_mock_sensor_commands" default="false" />
<xacro:arg name="alice_robot_ip" default="192.168.57.101" />
<xacro:arg name="alice_reverse_port" default="50006" />
<xacro:arg name="alice_script_sender_port" default="50007" />
<xacro:arg name="alice_script_command_port" default="50010" />
<xacro:arg name="alice_trajectory_port" default="50009" />
<xacro:arg name="bob_use_mock_hardware" default="false" />
<xacro:arg name="bob_mock_sensor_commands" default="false" />
<xacro:arg name="bob_robot_ip" default="192.168.57.100" />
<xacro:arg name="bob_reverse_port" default="50001" />
<xacro:arg name="bob_script_sender_port" default="50002" />
<xacro:arg name="bob_script_command_port" default="50004" />
<xacro:arg name="bob_trajectory_port" default="50003" />
<xacro:arg name="headless_mode" default="false" />
<xacro:arg name="ur_script_filename" default="$(find ur_client_library)/resources/external_control.urscript" />
<xacro:arg name="ur_output_recipe_filename" default="$(find ur_robot_driver)/resources/rtde_output_recipe.txt" />
<xacro:arg name="ur_input_recipe_filename" default="$(find ur_robot_driver)/resources/rtde_input_recipe.txt" />
and then call the macro by providing all the specified arguments.
<xacro:ur_ros2_control
name="alice"
ur_type="$(arg alice_ur_type)"
tf_prefix="alice_"
kinematics_parameters_file="$(arg alice_kinematics_parameters_file)"
robot_ip="$(arg alice_robot_ip)"
script_filename="$(arg ur_script_filename)"
output_recipe_filename="$(arg ur_output_recipe_filename)"
input_recipe_filename="$(arg ur_input_recipe_filename)"
use_mock_hardware="$(arg alice_use_mock_hardware)"
mock_sensor_commands="$(arg alice_mock_sensor_commands)"
headless_mode="$(arg headless_mode)"
reverse_port="$(arg alice_reverse_port)"
script_sender_port="$(arg alice_script_sender_port)"
script_command_port="$(arg alice_script_command_port)"
trajectory_port="$(arg alice_trajectory_port)"
/>
<xacro:ur_ros2_control
name="bob"
ur_type="$(arg bob_ur_type)"
tf_prefix="bob_"
kinematics_parameters_file="$(arg bob_kinematics_parameters_file)"
robot_ip="$(arg bob_robot_ip)"
script_filename="$(arg ur_script_filename)"
output_recipe_filename="$(arg ur_output_recipe_filename)"
input_recipe_filename="$(arg ur_input_recipe_filename)"
use_mock_hardware="$(arg bob_use_mock_hardware)"
mock_sensor_commands="$(arg bob_mock_sensor_commands)"
headless_mode="$(arg headless_mode)"
reverse_port="$(arg bob_reverse_port)"
script_sender_port="$(arg bob_script_sender_port)"
script_command_port="$(arg bob_script_command_port)"
trajectory_port="$(arg bob_trajectory_port)"
/>
Extract the calibration
One very important step is to extract each robot’s specific calibration and save it to our workcell’s startup package. For details, please refer to our documentation on extracting the calibration information. For now, we just copy the default ones for the UR3e and UR5e.
cp $(ros2 pkg prefix ur_description)/share/ur_description/config/ur3e/default_kinematics.yaml \
my_dual_robot_cell_control/config/alice_calibration.yaml
cp $(ros2 pkg prefix ur_description)/share/ur_description/config/ur5e/default_kinematics.yaml \
my_dual_robot_cell_control/config/bob_calibration.yaml
Create robot_state_publisher launchfile
To use the custom controlled description, we need to generate a launchfile loading that description
(Since it contains less / potentially different) arguments than the “default” one. In that
launchfile we need to start a robot_state_publisher (RSP) node that will get the description as a
parameter and redistribute it via the robot_description topic:
1from launch import LaunchDescription
2from launch.actions import DeclareLaunchArgument
3from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution
4from launch_ros.actions import Node
5from launch_ros.substitutions import FindPackageShare
6
7
8def generate_launch_description():
9 alice_ur_type = LaunchConfiguration("alice_ur_type")
10 bob_ur_type = LaunchConfiguration("bob_ur_type")
11
12 alice_robot_ip = LaunchConfiguration("alice_robot_ip")
13 bob_robot_ip = LaunchConfiguration("bob_robot_ip")
14
15 alice_use_mock_hardware = LaunchConfiguration("alice_use_mock_hardware")
16 alice_mock_sensor_commands = LaunchConfiguration("alice_mock_sensor_commands")
17 bob_use_mock_hardware = LaunchConfiguration("bob_use_mock_hardware")
18 bob_mock_sensor_commands = LaunchConfiguration("bob_mock_sensor_commands")
19
20 headless_mode = LaunchConfiguration("headless_mode")
21
22 alice_kinematics_parameters_file = LaunchConfiguration("alice_kinematics_parameters_file")
23 bob_kinematics_parameters_file = LaunchConfiguration("bob_kinematics_parameters_file")
24
25 robot_description_content = Command(
26 [
27 PathJoinSubstitution([FindExecutable(name="xacro")]),
28 " ",
29 PathJoinSubstitution(
30 [
31 FindPackageShare("my_dual_robot_cell_control"),
32 "urdf",
33 "my_dual_robot_cell_controlled.urdf.xacro",
34 ]
35 ),
36 " ",
37 "alice_robot_ip:=",
38 alice_robot_ip,
39 " ",
40 "bob_robot_ip:=",
41 bob_robot_ip,
42 " ",
43 "alice_ur_type:=",
44 alice_ur_type,
45 " ",
46 "bob_ur_type:=",
47 bob_ur_type,
48 " ",
49 "alice_use_mock_hardware:=",
50 alice_use_mock_hardware,
51 " ",
52 "bob_use_mock_hardware:=",
53 bob_use_mock_hardware,
54 " ",
55 "alice_kinematics_parameters_file:=",
56 alice_kinematics_parameters_file,
57 " ",
58 "bob_kinematics_parameters_file:=",
59 bob_kinematics_parameters_file,
60 " ",
61 "alice_mock_sensor_commands:=",
62 alice_mock_sensor_commands,
63 " ",
64 "bob_mock_sensor_commands:=",
65 bob_mock_sensor_commands,
66 " ",
67 "headless_mode:=",
68 headless_mode,
69 ]
70 )
71 robot_description = {"robot_description": robot_description_content}
72
73 declared_arguments = []
74 declared_arguments.append(
75 DeclareLaunchArgument(
76 "alice_ur_type",
77 description="Type/series of used UR robot.",
78 choices=[
79 "ur3",
80 "ur3e",
81 "ur5",
82 "ur5e",
83 "ur10",
84 "ur10e",
85 "ur16e",
86 "ur20",
87 "ur30",
88 ],
89 default_value="ur3e",
90 )
91 )
92 declared_arguments.append(
93 DeclareLaunchArgument(
94 "bob_ur_type",
95 description="Type/series of used UR robot.",
96 choices=[
97 "ur3",
98 "ur3e",
99 "ur5",
100 "ur5e",
101 "ur10",
102 "ur10e",
103 "ur16e",
104 "ur20",
105 "ur30",
106 ],
107 default_value="ur5e",
108 )
109 )
110 declared_arguments.append(
111 DeclareLaunchArgument(
112 "alice_robot_ip",
113 default_value="192.168.0.101",
114 description="IP address by which alice can be reached.",
115 )
116 )
117 declared_arguments.append(
118 DeclareLaunchArgument(
119 "bob_robot_ip",
120 default_value="192.168.0.100",
121 description="IP address by which bob can be reached.",
122 )
123 )
124 declared_arguments.append(
125 DeclareLaunchArgument(
126 "alice_kinematics_parameters_file",
127 default_value=PathJoinSubstitution(
128 [
129 FindPackageShare("my_dual_robot_cell_control"),
130 "config",
131 "alice_calibration.yaml",
132 ]
133 ),
134 description="The calibration configuration of alice.",
135 )
136 )
137 declared_arguments.append(
138 DeclareLaunchArgument(
139 "bob_kinematics_parameters_file",
140 default_value=PathJoinSubstitution(
141 [
142 FindPackageShare("my_dual_robot_cell_control"),
143 "config",
144 "bob_calibration.yaml",
145 ]
146 ),
147 description="The calibration configuration of bob.",
148 )
149 )
150 declared_arguments.append(
151 DeclareLaunchArgument(
152 "alice_use_mock_hardware",
153 default_value="false",
154 description="Start alice with mock hardware mirroring command to its states.",
155 )
156 )
157 declared_arguments.append(
158 DeclareLaunchArgument(
159 "bob_use_mock_hardware",
160 default_value="false",
161 description="Start bob with mock hardware mirroring command to its states.",
162 )
163 )
164 declared_arguments.append(
165 DeclareLaunchArgument(
166 "alice_mock_sensor_commands",
167 default_value="false",
168 description="Enable mock command interfaces for alice's sensors used for simple simulations. "
169 "Used only if 'use_mock_hardware' parameter is true.",
170 )
171 )
172 declared_arguments.append(
173 DeclareLaunchArgument(
174 "bob_mock_sensor_commands",
175 default_value="false",
176 description="Enable mock command interfaces for bob's sensors used for simple simulations. "
177 "Used only if 'use_mock_hardware' parameter is true.",
178 )
179 )
180 declared_arguments.append(
181 DeclareLaunchArgument(
182 "headless_mode",
183 default_value="false",
184 description="Enable headless mode for robot control",
185 )
186 )
187
188 return LaunchDescription(
189 declared_arguments
190 + [
191 Node(
192 package="robot_state_publisher",
193 executable="robot_state_publisher",
194 output="both",
195 parameters=[robot_description],
196 ),
197 ]
198 )
Before we can start our workcell we need to create a launchfile that will launch the two robot descriptions correctly.
Create start_robot launchfile
Here we create a launch file which will launch the driver with the correct description and robot state publisher, as well as start all of the controllers necessary to use the two robots.
1from launch import LaunchDescription
2from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
3from launch.conditions import IfCondition, UnlessCondition
4from launch.launch_description_sources import AnyLaunchDescriptionSource
5from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
6from launch_ros.actions import Node
7from launch_ros.parameter_descriptions import ParameterFile
8from launch_ros.substitutions import FindPackageShare
9
10
11def launch_setup():
12 # Initialize Arguments
13 alice_ur_type = LaunchConfiguration("alice_ur_type")
14 bob_ur_type = LaunchConfiguration("bob_ur_type")
15
16 alice_robot_ip = LaunchConfiguration("alice_robot_ip")
17 bob_robot_ip = LaunchConfiguration("bob_robot_ip")
18
19 # General arguments
20 controllers_file = LaunchConfiguration("controllers_file")
21 controller_spawner_timeout = LaunchConfiguration("controller_spawner_timeout")
22 description_launchfile = LaunchConfiguration("description_launchfile")
23 launch_rviz = LaunchConfiguration("launch_rviz")
24 rviz_config_file = LaunchConfiguration("rviz_config_file")
25 headless_mode = LaunchConfiguration("headless_mode")
26
27 # Robot specific arguments
28 alice_use_mock_hardware = LaunchConfiguration("alice_use_mock_hardware")
29 alice_mock_sensor_commands = LaunchConfiguration("alice_mock_sensor_commands")
30 alice_initial_joint_controller = LaunchConfiguration("alice_initial_joint_controller")
31 alice_activate_joint_controller = LaunchConfiguration("alice_activate_joint_controller")
32 alice_launch_dashboard_client = LaunchConfiguration("alice_launch_dashboard_client")
33
34 bob_use_mock_hardware = LaunchConfiguration("bob_use_mock_hardware")
35 bob_mock_sensor_commands = LaunchConfiguration("bob_mock_sensor_commands")
36 bob_initial_joint_controller = LaunchConfiguration("bob_initial_joint_controller")
37 bob_activate_joint_controller = LaunchConfiguration("bob_activate_joint_controller")
38 bob_launch_dashboard_client = LaunchConfiguration("bob_launch_dashboard_client")
39
40 # Single controller manager comprising of controllers for both arms
41 control_node = Node(
42 package="controller_manager",
43 executable="ros2_control_node",
44 parameters=[
45 LaunchConfiguration("update_rate_config_file"),
46 ParameterFile(controllers_file, allow_substs=True),
47 # We use the tf_prefix as substitution in there, so that's why we keep it as an
48 # argument for this launchfile
49 ],
50 output="screen",
51 )
52
53 alice_dashboard_client_node = Node(
54 package="ur_robot_driver",
55 condition=IfCondition(alice_launch_dashboard_client)
56 and UnlessCondition(alice_use_mock_hardware),
57 executable="dashboard_client",
58 name="dashboard_client",
59 namespace="alice",
60 output="screen",
61 emulate_tty=True,
62 parameters=[{"robot_ip": alice_robot_ip}],
63 )
64
65 bob_dashboard_client_node = Node(
66 package="ur_robot_driver",
67 condition=IfCondition(bob_launch_dashboard_client)
68 and UnlessCondition(bob_use_mock_hardware),
69 executable="dashboard_client",
70 name="dashboard_client",
71 namespace="bob",
72 output="screen",
73 emulate_tty=True,
74 parameters=[{"robot_ip": bob_robot_ip}],
75 )
76
77 alice_urscript_interface = Node(
78 package="ur_robot_driver",
79 executable="urscript_interface",
80 namespace="alice",
81 parameters=[{"robot_ip": alice_robot_ip}],
82 output="screen",
83 condition=UnlessCondition(alice_use_mock_hardware),
84 )
85
86 bob_urscript_interface = Node(
87 package="ur_robot_driver",
88 executable="urscript_interface",
89 namespace="bob",
90 parameters=[{"robot_ip": bob_robot_ip}],
91 output="screen",
92 condition=UnlessCondition(bob_use_mock_hardware),
93 )
94
95 alice_controller_stopper_node = Node(
96 package="ur_robot_driver",
97 executable="controller_stopper_node",
98 namespace="alice",
99 name="controller_stopper",
100 output="screen",
101 emulate_tty=True,
102 condition=UnlessCondition(alice_use_mock_hardware),
103 parameters=[
104 {"headless_mode": headless_mode},
105 {"joint_controller_active": alice_activate_joint_controller},
106 {
107 "consistent_controllers": [
108 "joint_state_broadcaster",
109 "alice_io_and_status_controller",
110 "bob_io_and_status_controller",
111 "alice_force_torque_sensor_broadcaster",
112 "bob_force_torque_sensor_broadcaster",
113 "alice_speed_scaling_state_broadcaster",
114 "bob_speed_scaling_state_broadcaster",
115 ]
116 },
117 ],
118 )
119
120 bob_controller_stopper_node = Node(
121 package="ur_robot_driver",
122 executable="controller_stopper_node",
123 namespace="bob",
124 name="controller_stopper",
125 output="screen",
126 emulate_tty=True,
127 condition=UnlessCondition(bob_use_mock_hardware),
128 parameters=[
129 {"headless_mode": headless_mode},
130 {"joint_controller_active": bob_activate_joint_controller},
131 {
132 "consistent_controllers": [
133 "joint_state_broadcaster",
134 "alice_io_and_status_controller",
135 "bob_io_and_status_controller",
136 "alice_force_torque_sensor_broadcaster",
137 "bob_force_torque_sensor_broadcaster",
138 "alice_speed_scaling_state_broadcaster",
139 "bob_speed_scaling_state_broadcaster",
140 ]
141 },
142 ],
143 )
144
145 rviz_node = Node(
146 package="rviz2",
147 condition=IfCondition(launch_rviz),
148 executable="rviz2",
149 name="rviz2",
150 output="log",
151 arguments=["-d", rviz_config_file],
152 )
153
154 # Spawn controllers
155 def controller_spawner(controllers, active=True):
156 inactive_flags = ["--inactive"] if not active else []
157 return Node(
158 package="controller_manager",
159 executable="spawner",
160 parameters=[
161 ParameterFile(controllers_file, allow_substs=True),
162 ],
163 arguments=[
164 "--controller-manager",
165 "/controller_manager",
166 "--controller-manager-timeout",
167 controller_spawner_timeout,
168 ]
169 + inactive_flags
170 + controllers,
171 )
172
173 controllers_active = [
174 "joint_state_broadcaster",
175 "alice_io_and_status_controller",
176 "bob_io_and_status_controller",
177 "alice_speed_scaling_state_broadcaster",
178 "bob_speed_scaling_state_broadcaster",
179 "alice_force_torque_sensor_broadcaster",
180 "bob_force_torque_sensor_broadcaster",
181 ]
182 controllers_inactive = [
183 "alice_forward_position_controller",
184 "bob_forward_position_controller",
185 ]
186
187 controller_spawners = [controller_spawner(controllers_active)] + [
188 controller_spawner(controllers_inactive, active=False)
189 ]
190
191 # There may be other controllers of the joints, but this is the initially-started one
192 alice_initial_joint_controller_spawner_started = Node(
193 package="controller_manager",
194 executable="spawner",
195 parameters=[
196 ParameterFile(controllers_file, allow_substs=True),
197 ],
198 arguments=[
199 alice_initial_joint_controller,
200 "-c",
201 "/controller_manager",
202 "--controller-manager-timeout",
203 controller_spawner_timeout,
204 ],
205 condition=IfCondition(alice_activate_joint_controller),
206 )
207 bob_initial_joint_controller_spawner_started = Node(
208 package="controller_manager",
209 executable="spawner",
210 parameters=[
211 ParameterFile(controllers_file, allow_substs=True),
212 ],
213 arguments=[
214 bob_initial_joint_controller,
215 "-c",
216 "/controller_manager",
217 "--controller-manager-timeout",
218 controller_spawner_timeout,
219 ],
220 condition=IfCondition(bob_activate_joint_controller),
221 )
222 alice_initial_joint_controller_spawner_stopped = Node(
223 package="controller_manager",
224 executable="spawner",
225 parameters=[
226 ParameterFile(controllers_file, allow_substs=True),
227 ],
228 arguments=[
229 alice_initial_joint_controller,
230 "-c",
231 "/controller_manager",
232 "--controller-manager-timeout",
233 controller_spawner_timeout,
234 "--inactive",
235 ],
236 condition=UnlessCondition(alice_activate_joint_controller),
237 )
238 bob_initial_joint_controller_spawner_stopped = Node(
239 package="controller_manager",
240 executable="spawner",
241 parameters=[
242 ParameterFile(controllers_file, allow_substs=True),
243 ],
244 arguments=[
245 bob_initial_joint_controller,
246 "-c",
247 "/controller_manager",
248 "--controller-manager-timeout",
249 controller_spawner_timeout,
250 "--inactive",
251 ],
252 condition=UnlessCondition(bob_activate_joint_controller),
253 )
254
255 rsp = IncludeLaunchDescription(
256 AnyLaunchDescriptionSource(description_launchfile),
257 launch_arguments={
258 "alice_robot_ip": alice_robot_ip,
259 "bob_robot_ip": bob_robot_ip,
260 "alice_ur_type": alice_ur_type,
261 "bob_ur_type": bob_ur_type,
262 }.items(),
263 )
264
265 nodes_to_start = [
266 control_node,
267 alice_dashboard_client_node,
268 bob_dashboard_client_node,
269 alice_controller_stopper_node,
270 bob_controller_stopper_node,
271 alice_urscript_interface,
272 bob_urscript_interface,
273 rsp,
274 rviz_node,
275 alice_initial_joint_controller_spawner_stopped,
276 bob_initial_joint_controller_spawner_stopped,
277 alice_initial_joint_controller_spawner_started,
278 bob_initial_joint_controller_spawner_started,
279 ] + controller_spawners
280
281 return nodes_to_start
282
283
284def generate_launch_description():
285 declared_arguments = []
286 # UR specific arguments
287 declared_arguments.append(
288 DeclareLaunchArgument(
289 "alice_ur_type",
290 description="Type/series of used UR robot.",
291 choices=[
292 "ur3",
293 "ur3e",
294 "ur5",
295 "ur5e",
296 "ur10",
297 "ur10e",
298 "ur16e",
299 "ur20",
300 "ur30",
301 ],
302 default_value="ur3e",
303 )
304 )
305 declared_arguments.append(
306 DeclareLaunchArgument(
307 "bob_ur_type",
308 description="Type/series of used UR robot.",
309 choices=[
310 "ur3",
311 "ur3e",
312 "ur5",
313 "ur5e",
314 "ur10",
315 "ur10e",
316 "ur16e",
317 "ur20",
318 "ur30",
319 ],
320 default_value="ur5e",
321 )
322 )
323 declared_arguments.append(
324 DeclareLaunchArgument(
325 "alice_robot_ip",
326 default_value="192.168.57.101",
327 description="IP address by which alice can be reached.",
328 )
329 )
330 declared_arguments.append(
331 DeclareLaunchArgument(
332 "bob_robot_ip",
333 default_value="192.168.57.100",
334 description="IP address by which bob can be reached.",
335 )
336 )
337
338 # General arguments
339 declared_arguments.append(
340 DeclareLaunchArgument(
341 "controllers_file",
342 default_value=PathJoinSubstitution(
343 [
344 FindPackageShare("my_dual_robot_cell_control"),
345 "config",
346 "combined_controllers.yaml",
347 ]
348 ),
349 description="YAML file with the controllers configuration.",
350 )
351 )
352 declared_arguments.append(
353 DeclareLaunchArgument(
354 "description_launchfile",
355 default_value=PathJoinSubstitution(
356 [
357 FindPackageShare("my_dual_robot_cell_control"),
358 "launch",
359 "rsp.launch.py",
360 ]
361 ),
362 description="Launchfile (absolute path) providing the description. "
363 "The launchfile has to start a robot_state_publisher node that "
364 "publishes the description topic.",
365 )
366 )
367 declared_arguments.append(
368 DeclareLaunchArgument(
369 "alice_use_mock_hardware",
370 default_value="false",
371 description="Start alice with mock hardware mirroring command to its states.",
372 )
373 )
374 declared_arguments.append(
375 DeclareLaunchArgument(
376 "bob_use_mock_hardware",
377 default_value="false",
378 description="Start bob with mock hardware mirroring command to its states.",
379 )
380 )
381 declared_arguments.append(
382 DeclareLaunchArgument(
383 "alice_mock_sensor_commands",
384 default_value="false",
385 description="Enable mock command interfaces for alice's sensors used for simple simulations. "
386 "Used only if 'use_mock_hardware' parameter is true.",
387 )
388 )
389 declared_arguments.append(
390 DeclareLaunchArgument(
391 "bob_mock_sensor_commands",
392 default_value="false",
393 description="Enable mock command interfaces for bob's sensors used for simple simulations. "
394 "Used only if 'use_mock_hardware' parameter is true.",
395 )
396 )
397 declared_arguments.append(
398 DeclareLaunchArgument(
399 "headless_mode",
400 default_value="false",
401 description="Enable headless mode for robot control for both arms.",
402 )
403 )
404 declared_arguments.append(
405 DeclareLaunchArgument(
406 "controller_spawner_timeout",
407 default_value="10",
408 description="Timeout used when spawning controllers.",
409 )
410 )
411 declared_arguments.append(
412 DeclareLaunchArgument(
413 "alice_initial_joint_controller",
414 default_value="alice_joint_trajectory_controller",
415 description="Initially loaded robot controller for the alice robot arm.",
416 )
417 )
418 declared_arguments.append(
419 DeclareLaunchArgument(
420 "bob_initial_joint_controller",
421 default_value="bob_joint_trajectory_controller",
422 description="Initially loaded robot controller for the bob robot arm.",
423 )
424 )
425 declared_arguments.append(
426 DeclareLaunchArgument(
427 "alice_activate_joint_controller",
428 default_value="true",
429 description="Activate loaded joint controller for the alice robot arm.",
430 )
431 )
432 declared_arguments.append(
433 DeclareLaunchArgument(
434 "bob_activate_joint_controller",
435 default_value="true",
436 description="Activate loaded joint controller for the bob robot arm.",
437 )
438 )
439 declared_arguments.append(
440 DeclareLaunchArgument("launch_rviz", default_value="true", description="Launch RViz?")
441 )
442 declared_arguments.append(
443 DeclareLaunchArgument(
444 "rviz_config_file",
445 default_value=PathJoinSubstitution(
446 [FindPackageShare("my_dual_robot_cell_description"), "rviz", "urdf.rviz"]
447 ),
448 description="RViz config file (absolute path) to use when launching rviz.",
449 )
450 )
451 declared_arguments.append(
452 DeclareLaunchArgument(
453 "alice_launch_dashboard_client",
454 default_value="true",
455 description="Launch Dashboard Client?",
456 )
457 )
458 declared_arguments.append(
459 DeclareLaunchArgument(
460 "bob_launch_dashboard_client",
461 default_value="true",
462 description="Launch Dashboard Client?",
463 )
464 )
465
466 declared_arguments.append(
467 DeclareLaunchArgument(
468 name="update_rate_config_file",
469 default_value=[
470 PathJoinSubstitution(
471 [
472 FindPackageShare("my_dual_robot_cell_control"),
473 "config",
474 ]
475 ),
476 "/",
477 "update_rate.yaml",
478 ],
479 )
480 )
481 return LaunchDescription(declared_arguments + launch_setup())
With that we can start the robot using
ros2 launch my_dual_robot_cell_control start_robots.launch.py alice_use_mock_hardware:=true bob_use_mock_hardware:=true
Testing everything
Before we can test our code, it’s essential to build and source our Colcon workspace:
#cd to your colcon workspace root, e.g.
cd ~/colcon_ws
#source and build your workspace
colcon build
source install/setup.bash
We can start the system in a mocked simulation
#start the driver with mocked hardware
ros2 launch my_dual_robot_cell_control start_robots.launch.py alice_use_mock_hardware:=true bob_use_mock_hardware:=true
Or to use it with a real robot:
#start the driver with real hardware (or the docker simulator included in this example)
ros2 launch my_dual_robot_cell_control start_robots.launch.py
Note
We extracted the calibration information from the robot and saved it in the
my_robot_cell_control package. If you have a different robot, you need to extract the
calibration information from that, and pass that to the launch file. Changing the ur_type
parameter only will lead to a wrong model, as it will still be using the example kinematics from
a UR3e and UR5e. To use a UR10e and UR20, for example, you can do
ros2 launch my_dual_robot_cell_control start_robots.launch.py bob_ur_type:=ur10e bob_use_mock_hardware:=true \
bob_kinematics_parameters_file:=$(ros2 pkg prefix ur_description)/share/ur_description/config/ur10e/default_kinematics.yaml \
alice_ur_type:=ur20 alice_use_mock_hardware:=true \
alice_kinematics_parameters_file:=$(ros2 pkg prefix ur_description)/share/ur_description/config/ur20/default_kinematics.yaml