44
44
IncludeLaunchDescription ,
45
45
RegisterEventHandler ,
46
46
)
47
+ from launch .conditions import IfCondition , UnlessCondition
47
48
from launch .event_handlers import OnProcessExit
48
49
from launch .launch_description_sources import PythonLaunchDescriptionSource
49
50
from launch .substitutions import LaunchConfiguration , PathJoinSubstitution
57
58
from ur_dashboard_msgs .srv import GetRobotMode
58
59
from ur_msgs .msg import IOStates
59
60
from ur_msgs .srv import SetIO
61
+ from controller_manager_msgs .srv import ListControllers
60
62
61
63
TIMEOUT_WAIT_SERVICE = 10
62
64
TIMEOUT_WAIT_SERVICE_INITIAL = 60
@@ -90,7 +92,25 @@ def generate_test_description(tf_prefix):
90
92
)
91
93
)
92
94
95
+ declared_arguments .append (
96
+ DeclareLaunchArgument (
97
+ "robot_ip" ,
98
+ default_value = "192.168.56.101" ,
99
+ description = "IP address of used UR robot." ,
100
+ )
101
+ )
102
+
103
+ declared_arguments .append (
104
+ DeclareLaunchArgument (
105
+ "launch_ursim" ,
106
+ default_value = "true" ,
107
+ description = "Launches the ursim when running the test if True" ,
108
+ )
109
+ )
110
+
93
111
ur_type = LaunchConfiguration ("ur_type" )
112
+ robot_ip = LaunchConfiguration ("robot_ip" )
113
+ launch_ursim = LaunchConfiguration ("launch_ursim" )
94
114
95
115
robot_driver = IncludeLaunchDescription (
96
116
PythonLaunchDescriptionSource (
@@ -109,7 +129,9 @@ def generate_test_description(tf_prefix):
109
129
"start_joint_controller" : "false" ,
110
130
"tf_prefix" : tf_prefix ,
111
131
}.items (),
132
+ condition = IfCondition (launch_ursim ),
112
133
)
134
+
113
135
ursim = ExecuteProcess (
114
136
cmd = [
115
137
PathJoinSubstitution (
@@ -126,22 +148,48 @@ def generate_test_description(tf_prefix):
126
148
],
127
149
name = "start_ursim" ,
128
150
output = "screen" ,
151
+ condition = IfCondition (launch_ursim ),
129
152
)
153
+
130
154
wait_dashboard_server = ExecuteProcess (
131
155
cmd = [
132
156
PathJoinSubstitution (
133
157
[FindPackagePrefix ("ur_robot_driver" ), "bin" , "wait_dashboard_server.sh" ]
134
- )
158
+ ),
135
159
],
136
160
name = "wait_dashboard_server" ,
137
161
output = "screen" ,
162
+ condition = IfCondition (launch_ursim ),
138
163
)
164
+
139
165
driver_starter = RegisterEventHandler (
140
- OnProcessExit (target_action = wait_dashboard_server , on_exit = robot_driver )
166
+ OnProcessExit (target_action = wait_dashboard_server , on_exit = robot_driver ),
167
+ condition = IfCondition (launch_ursim ),
168
+ )
169
+
170
+ robot_driver_no_wait = IncludeLaunchDescription (
171
+ PythonLaunchDescriptionSource (
172
+ PathJoinSubstitution (
173
+ [FindPackageShare ("ur_robot_driver" ), "launch" , "ur_control.launch.py" ]
174
+ )
175
+ ),
176
+ launch_arguments = {
177
+ "robot_ip" : robot_ip ,
178
+ "ur_type" : ur_type ,
179
+ "launch_rviz" : "false" ,
180
+ "controller_spawner_timeout" : str (TIMEOUT_WAIT_SERVICE_INITIAL ),
181
+ "initial_joint_controller" : "scaled_joint_trajectory_controller" ,
182
+ "headless_mode" : "true" ,
183
+ "launch_dashboard_client" : "false" ,
184
+ "start_joint_controller" : "false" ,
185
+ "tf_prefix" : tf_prefix ,
186
+ }.items (),
187
+ condition = UnlessCondition (launch_ursim ),
141
188
)
142
189
143
190
return LaunchDescription (
144
- declared_arguments + [ReadyToTest (), wait_dashboard_server , ursim , driver_starter ]
191
+ declared_arguments
192
+ + [ReadyToTest (), wait_dashboard_server , ursim , driver_starter , robot_driver_no_wait ]
145
193
)
146
194
147
195
@@ -184,6 +232,7 @@ def init_robot(self):
184
232
"/dashboard_client/get_robot_mode" : GetRobotMode ,
185
233
"/controller_manager/switch_controller" : SwitchController ,
186
234
"/io_and_status_controller/resend_robot_program" : Trigger ,
235
+ "/controller_manager/list_controllers" : ListControllers ,
187
236
}
188
237
self .service_clients .update (
189
238
{
@@ -282,6 +331,9 @@ def io_msg_cb(msg):
282
331
283
332
def test_trajectory (self , tf_prefix ):
284
333
"""Test robot movement."""
334
+ # Wait for controller to be active
335
+ self .waitForController ("scaled_joint_trajectory_controller" )
336
+
285
337
# Construct test trajectory
286
338
test_trajectory = [
287
339
(Duration (sec = 6 , nanosec = 0 ), [0.0 for j in ROBOT_JOINTS ]),
@@ -320,6 +372,9 @@ def test_illegal_trajectory(self, tf_prefix):
320
372
321
373
This is more of a validation test that the testing suite does the right thing
322
374
"""
375
+ # Wait for controller to be active
376
+ self .waitForController ("scaled_joint_trajectory_controller" )
377
+
323
378
# Construct test trajectory, the second point wrongly starts before the first
324
379
test_trajectory = [
325
380
(Duration (sec = 6 , nanosec = 0 ), [0.0 for j in ROBOT_JOINTS ]),
@@ -347,6 +402,9 @@ def test_illegal_trajectory(self, tf_prefix):
347
402
348
403
def test_trajectory_scaled (self , tf_prefix ):
349
404
"""Test robot movement."""
405
+ # Wait for controller to be active
406
+ self .waitForController ("scaled_joint_trajectory_controller" )
407
+
350
408
# Construct test trajectory
351
409
test_trajectory = [
352
410
(Duration (sec = 6 , nanosec = 0 ), [0.0 for j in ROBOT_JOINTS ]),
@@ -442,6 +500,25 @@ def get_result(self, action_name, goal_response, timeout):
442
500
else :
443
501
raise Exception (f"Exception while calling action: { future_res .exception ()} " )
444
502
503
+ def waitForController (
504
+ self , controller_name , controller_status = "active" , timeout = TIMEOUT_WAIT_SERVICE
505
+ ):
506
+ controller_running = False
507
+ end_time = time .time () + timeout
508
+ while controller_running is False and time .time () < end_time :
509
+ time .sleep (1 )
510
+ response = self .call_service (
511
+ "/controller_manager/list_controllers" , ListControllers .Request ()
512
+ )
513
+ for controller in response .controller :
514
+ if controller .name == controller_name :
515
+ controller_running = controller .state == controller_status
516
+
517
+ if controller_running is False :
518
+ raise Exception (
519
+ f"Controller { controller_name } did not reach controller state { controller_status } within timeout of { timeout } "
520
+ )
521
+
445
522
446
523
def waitForService (node , srv_name , srv_type , timeout = TIMEOUT_WAIT_SERVICE ):
447
524
client = node .create_client (srv_type , srv_name )
0 commit comments