Skip to content

Commit e7e47d5

Browse files
committed
Added arguments to test launch
Added arguments when launching the test: - Added robot ip - Added launch_ursim to choose whether or not to launch ursim when running the test. - If the arguments are not provided the behavior is the same as before adding the arguments. Ensure that the scaled joint trajectory controller is running, before sending the motion.
1 parent 2ca4fd1 commit e7e47d5

File tree

3 files changed

+152
-8
lines changed

3 files changed

+152
-8
lines changed

ur_robot_driver/test/dashboard_client.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import rclpy
3636
from launch import LaunchDescription
3737
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
38+
from launch.conditions import IfCondition
3839
from launch.launch_description_sources import PythonLaunchDescriptionSource
3940
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
4041
from launch_ros.substitutions import FindPackagePrefix, FindPackageShare
@@ -69,7 +70,25 @@ def generate_test_description():
6970
)
7071
)
7172

73+
declared_arguments.append(
74+
DeclareLaunchArgument(
75+
"robot_ip",
76+
default_value="192.168.56.101",
77+
description="IP address of used UR robot.",
78+
)
79+
)
80+
81+
declared_arguments.append(
82+
DeclareLaunchArgument(
83+
"launch_ursim",
84+
default_value="true",
85+
description="Launches the ursim when running the test if yes",
86+
)
87+
)
88+
7289
ur_type = LaunchConfiguration("ur_type")
90+
robot_ip = LaunchConfiguration("robot_ip")
91+
launch_ursim = LaunchConfiguration("launch_ursim")
7392

7493
dashboard_client = IncludeLaunchDescription(
7594
PythonLaunchDescriptionSource(
@@ -82,9 +101,10 @@ def generate_test_description():
82101
)
83102
),
84103
launch_arguments={
85-
"robot_ip": "192.168.56.101",
104+
"robot_ip": robot_ip,
86105
}.items(),
87106
)
107+
88108
ursim = ExecuteProcess(
89109
cmd=[
90110
PathJoinSubstitution(
@@ -101,6 +121,7 @@ def generate_test_description():
101121
],
102122
name="start_ursim",
103123
output="screen",
124+
condition=IfCondition(launch_ursim),
104125
)
105126

106127
return LaunchDescription(declared_arguments + [ReadyToTest(), dashboard_client, ursim])
@@ -159,7 +180,10 @@ def test_switch_on(self):
159180
# Wait until the robot is booted completely
160181
end_time = time.time() + 10
161182
mode = RobotMode.DISCONNECTED
162-
while mode != RobotMode.POWER_OFF and time.time() < end_time:
183+
while (
184+
mode not in (RobotMode.POWER_OFF, RobotMode.IDLE, RobotMode.RUNNING)
185+
and time.time() < end_time
186+
):
163187
time.sleep(0.1)
164188
result = self.call_dashboard_service("get_robot_mode", GetRobotMode.Request())
165189
self.assertTrue(result.success)

ur_robot_driver/test/robot_driver.py

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
IncludeLaunchDescription,
4545
RegisterEventHandler,
4646
)
47+
from launch.conditions import IfCondition, UnlessCondition
4748
from launch.event_handlers import OnProcessExit
4849
from launch.launch_description_sources import PythonLaunchDescriptionSource
4950
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
@@ -57,6 +58,7 @@
5758
from ur_dashboard_msgs.srv import GetRobotMode
5859
from ur_msgs.msg import IOStates
5960
from ur_msgs.srv import SetIO
61+
from controller_manager_msgs.srv import ListControllers
6062

6163
TIMEOUT_WAIT_SERVICE = 10
6264
TIMEOUT_WAIT_SERVICE_INITIAL = 60
@@ -90,7 +92,25 @@ def generate_test_description(tf_prefix):
9092
)
9193
)
9294

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+
93111
ur_type = LaunchConfiguration("ur_type")
112+
robot_ip = LaunchConfiguration("robot_ip")
113+
launch_ursim = LaunchConfiguration("launch_ursim")
94114

95115
robot_driver = IncludeLaunchDescription(
96116
PythonLaunchDescriptionSource(
@@ -109,7 +129,9 @@ def generate_test_description(tf_prefix):
109129
"start_joint_controller": "false",
110130
"tf_prefix": tf_prefix,
111131
}.items(),
132+
condition=IfCondition(launch_ursim),
112133
)
134+
113135
ursim = ExecuteProcess(
114136
cmd=[
115137
PathJoinSubstitution(
@@ -126,22 +148,48 @@ def generate_test_description(tf_prefix):
126148
],
127149
name="start_ursim",
128150
output="screen",
151+
condition=IfCondition(launch_ursim),
129152
)
153+
130154
wait_dashboard_server = ExecuteProcess(
131155
cmd=[
132156
PathJoinSubstitution(
133157
[FindPackagePrefix("ur_robot_driver"), "bin", "wait_dashboard_server.sh"]
134-
)
158+
),
135159
],
136160
name="wait_dashboard_server",
137161
output="screen",
162+
condition=IfCondition(launch_ursim),
138163
)
164+
139165
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),
141188
)
142189

143190
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]
145193
)
146194

147195

@@ -184,6 +232,7 @@ def init_robot(self):
184232
"/dashboard_client/get_robot_mode": GetRobotMode,
185233
"/controller_manager/switch_controller": SwitchController,
186234
"/io_and_status_controller/resend_robot_program": Trigger,
235+
"/controller_manager/list_controllers": ListControllers,
187236
}
188237
self.service_clients.update(
189238
{
@@ -282,6 +331,9 @@ def io_msg_cb(msg):
282331

283332
def test_trajectory(self, tf_prefix):
284333
"""Test robot movement."""
334+
# Wait for controller to be active
335+
self.waitForController("scaled_joint_trajectory_controller")
336+
285337
# Construct test trajectory
286338
test_trajectory = [
287339
(Duration(sec=6, nanosec=0), [0.0 for j in ROBOT_JOINTS]),
@@ -320,6 +372,9 @@ def test_illegal_trajectory(self, tf_prefix):
320372
321373
This is more of a validation test that the testing suite does the right thing
322374
"""
375+
# Wait for controller to be active
376+
self.waitForController("scaled_joint_trajectory_controller")
377+
323378
# Construct test trajectory, the second point wrongly starts before the first
324379
test_trajectory = [
325380
(Duration(sec=6, nanosec=0), [0.0 for j in ROBOT_JOINTS]),
@@ -347,6 +402,9 @@ def test_illegal_trajectory(self, tf_prefix):
347402

348403
def test_trajectory_scaled(self, tf_prefix):
349404
"""Test robot movement."""
405+
# Wait for controller to be active
406+
self.waitForController("scaled_joint_trajectory_controller")
407+
350408
# Construct test trajectory
351409
test_trajectory = [
352410
(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):
442500
else:
443501
raise Exception(f"Exception while calling action: {future_res.exception()}")
444502

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+
445522

446523
def waitForService(node, srv_name, srv_type, timeout=TIMEOUT_WAIT_SERVICE):
447524
client = node.create_client(srv_type, srv_name)

ur_robot_driver/test/urscript_interface.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
IncludeLaunchDescription,
4141
RegisterEventHandler,
4242
)
43+
from launch.conditions import IfCondition, UnlessCondition
4344
from launch.event_handlers import OnProcessExit
4445
from launch.launch_description_sources import PythonLaunchDescriptionSource
4546
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
@@ -79,7 +80,25 @@ def generate_test_description():
7980
)
8081
)
8182

83+
declared_arguments.append(
84+
DeclareLaunchArgument(
85+
"robot_ip",
86+
default_value="192.168.56.101",
87+
description="IP address of used UR robot.",
88+
)
89+
)
90+
91+
declared_arguments.append(
92+
DeclareLaunchArgument(
93+
"launch_ursim",
94+
default_value="true",
95+
description="Launches the ursim when running the test if True",
96+
)
97+
)
98+
8299
ur_type = LaunchConfiguration("ur_type")
100+
robot_ip = LaunchConfiguration("robot_ip")
101+
launch_ursim = LaunchConfiguration("launch_ursim")
83102

84103
robot_driver = IncludeLaunchDescription(
85104
PythonLaunchDescriptionSource(
@@ -97,6 +116,7 @@ def generate_test_description():
97116
"launch_dashboard_client": "false",
98117
"start_joint_controller": "false",
99118
}.items(),
119+
condition=IfCondition(launch_ursim),
100120
)
101121

102122
ursim = ExecuteProcess(
@@ -115,24 +135,47 @@ def generate_test_description():
115135
],
116136
name="start_ursim",
117137
output="screen",
138+
condition=IfCondition(launch_ursim),
118139
)
119140

120141
wait_dashboard_server = ExecuteProcess(
121142
cmd=[
122143
PathJoinSubstitution(
123144
[FindPackagePrefix("ur_robot_driver"), "bin", "wait_dashboard_server.sh"]
124-
)
145+
),
125146
],
126147
name="wait_dashboard_server",
127148
output="screen",
149+
condition=IfCondition(launch_ursim),
128150
)
129151

130152
driver_starter = RegisterEventHandler(
131-
OnProcessExit(target_action=wait_dashboard_server, on_exit=robot_driver)
153+
OnProcessExit(target_action=wait_dashboard_server, on_exit=robot_driver),
154+
condition=IfCondition(launch_ursim),
155+
)
156+
157+
robot_driver_no_wait = IncludeLaunchDescription(
158+
PythonLaunchDescriptionSource(
159+
PathJoinSubstitution(
160+
[FindPackageShare("ur_robot_driver"), "launch", "ur_control.launch.py"]
161+
)
162+
),
163+
launch_arguments={
164+
"robot_ip": robot_ip,
165+
"ur_type": ur_type,
166+
"launch_rviz": "false",
167+
"controller_spawner_timeout": str(TIMEOUT_WAIT_SERVICE_INITIAL),
168+
"initial_joint_controller": "scaled_joint_trajectory_controller",
169+
"headless_mode": "true",
170+
"launch_dashboard_client": "false",
171+
"start_joint_controller": "false",
172+
}.items(),
173+
condition=UnlessCondition(launch_ursim),
132174
)
133175

134176
return LaunchDescription(
135-
declared_arguments + [ReadyToTest(), wait_dashboard_server, driver_starter, ursim]
177+
declared_arguments
178+
+ [ReadyToTest(), wait_dashboard_server, ursim, driver_starter, robot_driver_no_wait]
136179
)
137180

138181

0 commit comments

Comments
 (0)