Skip to content

Commit 47b0e3d

Browse files
committed
Move sjtc trajectory and illegal trajectory test to test_common, so it can be used by mock hardware test as well.
1 parent 3cc8a2c commit 47b0e3d

File tree

3 files changed

+92
-126
lines changed

3 files changed

+92
-126
lines changed

ur_robot_driver/test/integration_test_scaled_joint_controller.py

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
generate_driver_test_description,
5252
ROBOT_JOINTS,
5353
TIMEOUT_EXECUTE_TRAJECTORY,
54+
sjtc_trajectory_test,
55+
sjtc_illegal_trajectory_test,
5456
)
5557

5658

@@ -104,75 +106,10 @@ def test_start_scaled_jtc_controller(self):
104106
)
105107

106108
def test_trajectory(self, tf_prefix):
107-
"""Test robot movement."""
108-
self.assertTrue(
109-
self._controller_manager_interface.switch_controller(
110-
strictness=SwitchController.Request.BEST_EFFORT,
111-
deactivate_controllers=["passthrough_trajectory_controller"],
112-
activate_controllers=["scaled_joint_trajectory_controller"],
113-
).ok
114-
)
115-
# Construct test trajectory
116-
test_trajectory = [
117-
(Duration(sec=6, nanosec=0), [0.0 for j in ROBOT_JOINTS]),
118-
(Duration(sec=9, nanosec=0), [-0.5 for j in ROBOT_JOINTS]),
119-
(Duration(sec=12, nanosec=0), [-1.0 for j in ROBOT_JOINTS]),
120-
]
121-
122-
trajectory = JointTrajectory(
123-
joint_names=[tf_prefix + joint for joint in ROBOT_JOINTS],
124-
points=[
125-
JointTrajectoryPoint(positions=test_pos, time_from_start=test_time)
126-
for (test_time, test_pos) in test_trajectory
127-
],
128-
)
129-
130-
# Sending trajectory goal
131-
logging.info("Sending simple goal")
132-
goal_handle = self._scaled_follow_joint_trajectory.send_goal(trajectory=trajectory)
133-
self.assertTrue(goal_handle.accepted)
134-
135-
# Verify execution
136-
result = self._scaled_follow_joint_trajectory.get_result(
137-
goal_handle, TIMEOUT_EXECUTE_TRAJECTORY
138-
)
139-
self.assertEqual(result.error_code, FollowJointTrajectory.Result.SUCCESSFUL)
109+
sjtc_trajectory_test(self, tf_prefix)
140110

141111
def test_illegal_trajectory(self, tf_prefix):
142-
"""
143-
Test trajectory server.
144-
145-
This is more of a validation test that the testing suite does the right thing
146-
"""
147-
self.assertTrue(
148-
self._controller_manager_interface.switch_controller(
149-
strictness=SwitchController.Request.BEST_EFFORT,
150-
deactivate_controllers=["passthrough_trajectory_controller"],
151-
activate_controllers=["scaled_joint_trajectory_controller"],
152-
).ok
153-
)
154-
# Construct test trajectory, the second point wrongly starts before the first
155-
test_trajectory = [
156-
(Duration(sec=6, nanosec=0), [0.0 for j in ROBOT_JOINTS]),
157-
(Duration(sec=3, nanosec=0), [-0.5 for j in ROBOT_JOINTS]),
158-
]
159-
160-
trajectory = JointTrajectory(
161-
joint_names=[tf_prefix + joint for joint in ROBOT_JOINTS],
162-
points=[
163-
JointTrajectoryPoint(positions=test_pos, time_from_start=test_time)
164-
for (test_time, test_pos) in test_trajectory
165-
],
166-
)
167-
168-
# Send illegal goal
169-
logging.info("Sending illegal goal")
170-
goal_handle = self._scaled_follow_joint_trajectory.send_goal(
171-
trajectory=trajectory,
172-
)
173-
174-
# Verify the failure is correctly detected
175-
self.assertFalse(goal_handle.accepted)
112+
sjtc_illegal_trajectory_test(self, tf_prefix)
176113

177114
def test_trajectory_scaled(self, tf_prefix):
178115
"""Test robot movement."""

ur_robot_driver/test/test_common.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
Load,
5959
)
6060
from ur_msgs.srv import SetIO, GetRobotSoftwareVersion, SetForceMode
61+
from builtin_interfaces.msg import Duration
62+
from control_msgs.action import FollowJointTrajectory
63+
from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
6164

6265
TIMEOUT_WAIT_SERVICE = 10
6366
TIMEOUT_WAIT_SERVICE_INITIAL = 120 # If we download the docker image simultaneously to the tests, it can take quite some time until the dashboard server is reachable and usable.
@@ -302,6 +305,79 @@ class ForceModeInterface(
302305
pass
303306

304307

308+
def sjtc_trajectory_test(tester, tf_prefix):
309+
"""Test robot movement."""
310+
tester.assertTrue(
311+
tester._controller_manager_interface.switch_controller(
312+
strictness=SwitchController.Request.BEST_EFFORT,
313+
deactivate_controllers=["passthrough_trajectory_controller"],
314+
activate_controllers=["scaled_joint_trajectory_controller"],
315+
).ok
316+
)
317+
# Construct test trajectory
318+
test_trajectory = [
319+
(Duration(sec=6, nanosec=0), [0.0 for j in ROBOT_JOINTS]),
320+
(Duration(sec=9, nanosec=0), [-0.5 for j in ROBOT_JOINTS]),
321+
(Duration(sec=12, nanosec=0), [-1.0 for j in ROBOT_JOINTS]),
322+
]
323+
324+
trajectory = JointTrajectory(
325+
joint_names=[tf_prefix + joint for joint in ROBOT_JOINTS],
326+
points=[
327+
JointTrajectoryPoint(positions=test_pos, time_from_start=test_time)
328+
for (test_time, test_pos) in test_trajectory
329+
],
330+
)
331+
332+
# Sending trajectory goal
333+
logging.info("Sending simple goal")
334+
goal_handle = tester._scaled_follow_joint_trajectory.send_goal(trajectory=trajectory)
335+
tester.assertTrue(goal_handle.accepted)
336+
337+
# Verify execution
338+
result = tester._scaled_follow_joint_trajectory.get_result(
339+
goal_handle, TIMEOUT_EXECUTE_TRAJECTORY
340+
)
341+
tester.assertEqual(result.error_code, FollowJointTrajectory.Result.SUCCESSFUL)
342+
343+
344+
def sjtc_illegal_trajectory_test(tester, tf_prefix):
345+
"""
346+
Test trajectory server.
347+
348+
This is more of a validation test that the testing suite does the right thing
349+
"""
350+
tester.assertTrue(
351+
tester._controller_manager_interface.switch_controller(
352+
strictness=SwitchController.Request.BEST_EFFORT,
353+
deactivate_controllers=["passthrough_trajectory_controller"],
354+
activate_controllers=["scaled_joint_trajectory_controller"],
355+
).ok
356+
)
357+
# Construct test trajectory, the second point wrongly starts before the first
358+
test_trajectory = [
359+
(Duration(sec=6, nanosec=0), [0.0 for j in ROBOT_JOINTS]),
360+
(Duration(sec=3, nanosec=0), [-0.5 for j in ROBOT_JOINTS]),
361+
]
362+
363+
trajectory = JointTrajectory(
364+
joint_names=[tf_prefix + joint for joint in ROBOT_JOINTS],
365+
points=[
366+
JointTrajectoryPoint(positions=test_pos, time_from_start=test_time)
367+
for (test_time, test_pos) in test_trajectory
368+
],
369+
)
370+
371+
# Send illegal goal
372+
logging.info("Sending illegal goal")
373+
goal_handle = tester._scaled_follow_joint_trajectory.send_goal(
374+
trajectory=trajectory,
375+
)
376+
377+
# Verify the failure is correctly detected
378+
tester.assertFalse(goal_handle.accepted)
379+
380+
305381
def _declare_launch_arguments():
306382
declared_arguments = []
307383

ur_robot_driver/test/test_mock_hardware.py

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,13 @@
3131
import sys
3232
import time
3333
import unittest
34-
import logging
3534

3635
import launch_testing
3736
import pytest
3837
import rclpy
3938
from rclpy.node import Node
40-
from builtin_interfaces.msg import Duration
4139
from control_msgs.action import FollowJointTrajectory
4240
from controller_manager_msgs.srv import SwitchController
43-
from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
44-
4541

4642
sys.path.append(os.path.dirname(__file__))
4743
from test_common import ( # noqa: E402
@@ -50,8 +46,8 @@
5046
IoStatusInterface,
5147
ConfigurationInterface,
5248
generate_mock_hardware_test_description,
53-
ROBOT_JOINTS,
54-
TIMEOUT_EXECUTE_TRAJECTORY,
49+
sjtc_trajectory_test,
50+
sjtc_illegal_trajectory_test,
5551
)
5652

5753

@@ -104,66 +100,23 @@ def test_get_robot_software_version(self):
104100
)
105101

106102
def test_start_scaled_jtc_controller(self):
103+
# Deactivate controller, if it is not already
107104
self.assertTrue(
108105
self._controller_manager_interface.switch_controller(
109106
strictness=SwitchController.Request.BEST_EFFORT,
107+
deactivate_controllers=["scaled_joint_trajectory_controller"],
108+
).ok
109+
)
110+
# Activate controller
111+
self.assertTrue(
112+
self._controller_manager_interface.switch_controller(
113+
strictness=SwitchController.Request.STRICT,
110114
activate_controllers=["scaled_joint_trajectory_controller"],
111115
).ok
112116
)
113117

114118
def test_trajectory(self, tf_prefix):
115-
"""Test robot movement."""
116-
# Construct test trajectory
117-
test_trajectory = [
118-
(Duration(sec=6, nanosec=0), [0.0 for j in ROBOT_JOINTS]),
119-
(Duration(sec=9, nanosec=0), [-0.5 for j in ROBOT_JOINTS]),
120-
(Duration(sec=12, nanosec=0), [-1.0 for j in ROBOT_JOINTS]),
121-
]
122-
123-
trajectory = JointTrajectory(
124-
joint_names=[tf_prefix + joint for joint in ROBOT_JOINTS],
125-
points=[
126-
JointTrajectoryPoint(positions=test_pos, time_from_start=test_time)
127-
for (test_time, test_pos) in test_trajectory
128-
],
129-
)
130-
131-
# Sending trajectory goal
132-
logging.info("Sending simple goal")
133-
goal_handle = self._scaled_follow_joint_trajectory.send_goal(trajectory=trajectory)
134-
self.assertTrue(goal_handle.accepted)
135-
136-
# Verify execution
137-
result = self._scaled_follow_joint_trajectory.get_result(
138-
goal_handle, TIMEOUT_EXECUTE_TRAJECTORY
139-
)
140-
self.assertEqual(result.error_code, FollowJointTrajectory.Result.SUCCESSFUL)
119+
sjtc_trajectory_test(self, tf_prefix)
141120

142121
def test_illegal_trajectory(self, tf_prefix):
143-
"""
144-
Test trajectory server.
145-
146-
This is more of a validation test that the testing suite does the right thing
147-
"""
148-
# Construct test trajectory, the second point wrongly starts before the first
149-
test_trajectory = [
150-
(Duration(sec=6, nanosec=0), [0.0 for j in ROBOT_JOINTS]),
151-
(Duration(sec=3, nanosec=0), [-0.5 for j in ROBOT_JOINTS]),
152-
]
153-
154-
trajectory = JointTrajectory(
155-
joint_names=[tf_prefix + joint for joint in ROBOT_JOINTS],
156-
points=[
157-
JointTrajectoryPoint(positions=test_pos, time_from_start=test_time)
158-
for (test_time, test_pos) in test_trajectory
159-
],
160-
)
161-
162-
# Send illegal goal
163-
logging.info("Sending illegal goal")
164-
goal_handle = self._scaled_follow_joint_trajectory.send_goal(
165-
trajectory=trajectory,
166-
)
167-
168-
# Verify the failure is correctly detected
169-
self.assertFalse(goal_handle.accepted)
122+
sjtc_illegal_trajectory_test(self, tf_prefix)

0 commit comments

Comments
 (0)