Skip to content

Commit 5a206cd

Browse files
author
Felix Exner
committed
specifically initialize robot before trajectory test
1 parent bebc46e commit 5a206cd

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

ur_robot_driver/test/trajectory_test.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import rospy
77
import actionlib
88
from control_msgs.msg import FollowJointTrajectoryAction, FollowJointTrajectoryGoal, FollowJointTrajectoryResult
9+
from ur_dashboard_msgs.msg import SetModeAction, SetModeGoal, RobotMode
10+
from std_srvs.srv import Trigger, TriggerRequest
911
from trajectory_msgs.msg import JointTrajectoryPoint
1012

1113
PKG = 'ur_rtde_driver'
@@ -26,7 +28,31 @@ def __init__(self, *args):
2628
"Could not reach controller action. Make sure that the driver is actually running."
2729
" Msg: {}".format(err))
2830

29-
# rospy.sleep(5)
31+
self.init_robot()
32+
33+
def init_robot(self):
34+
"""Make sure the robot is booted and ready to receive commands"""
35+
mode_client = actionlib.SimpleActionClient(
36+
'/ur_hardware_interface/set_mode', SetModeAction)
37+
timeout = rospy.Duration(30)
38+
try:
39+
mode_client.wait_for_server(timeout)
40+
except rospy.exceptions.ROSException as err:
41+
self.fail(
42+
"Could not reach set_mode action. Make sure that the driver is actually running."
43+
" Msg: {}".format(err))
44+
goal = SetModeGoal()
45+
goal.target_robot_mode = RobotMode.RUNNING
46+
goal.play_program = False # we use headless mode during tests
47+
48+
mode_client.send_goal(goal)
49+
mode_client.wait_for_result()
50+
51+
self.assertTrue(mode_client.get_result().success)
52+
53+
send_program_srv = rospy.ServiceProxy("/ur_hardware_interface/resend_robot_program", Trigger)
54+
send_program_srv.call()
55+
rospy.sleep(5)
3056

3157
def test_trajectory(self):
3258
"""Test robot movement"""

0 commit comments

Comments
 (0)