Skip to content

Commit d6df554

Browse files
author
Felix Exner
committed
Improve result representation in example_move script
1 parent 63bce67 commit d6df554

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

ur_robot_driver/scripts/example_move.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from rclpy.action import ActionClient
4040

4141
from builtin_interfaces.msg import Duration
42+
from action_msgs.msg import GoalStatus
4243
from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
4344
from control_msgs.action import FollowJointTrajectory
4445
from control_msgs.msg import JointTolerance
@@ -135,7 +136,9 @@ def execute_trajectory(self, traj_name):
135136
goal.trajectory = self.goals[traj_name]
136137

137138
goal.goal_time_tolerance = Duration(sec=0, nanosec=500000000)
138-
goal.goal_tolerance = [JointTolerance(position=0.01, name=self.joints[i]) for i in range(6)]
139+
goal.goal_tolerance = [
140+
JointTolerance(position=0.01, velocity=0.01, name=self.joints[i]) for i in range(6)
141+
]
139142

140143
self._send_goal_future = self._action_client.send_goal_async(goal)
141144
self._send_goal_future.add_done_callback(self.goal_response_callback)
@@ -153,11 +156,16 @@ def goal_response_callback(self, future):
153156

154157
def get_result_callback(self, future):
155158
result = future.result().result
156-
self.get_logger().info(f"Done with result: {self.error_code_to_str(result.error_code)}")
157-
if result.error_code == FollowJointTrajectory.Result.SUCCESSFUL:
159+
status = future.result().status
160+
self.get_logger().info(f"Done with result: {self.status_to_str(status)}")
161+
if status == GoalStatus.STATUS_SUCCEEDED:
158162
time.sleep(2)
159163
self.execute_next_trajectory()
160164
else:
165+
if result.error_code != FollowJointTrajectory.Result.SUCCESSFUL:
166+
self.get_logger().error(
167+
f"Done with result: {self.error_code_to_str(result.error_code)}"
168+
)
161169
raise RuntimeError("Executing trajectory failed. " + result.error_string)
162170

163171
@staticmethod
@@ -175,6 +183,23 @@ def error_code_to_str(error_code):
175183
if error_code == FollowJointTrajectory.Result.GOAL_TOLERANCE_VIOLATED:
176184
return "GOAL_TOLERANCE_VIOLATED"
177185

186+
@staticmethod
187+
def status_to_str(error_code):
188+
if error_code == GoalStatus.STATUS_UNKNOWN:
189+
return "UNKNOWN"
190+
if error_code == GoalStatus.STATUS_ACCEPTED:
191+
return "ACCEPTED"
192+
if error_code == GoalStatus.STATUS_EXECUTING:
193+
return "EXECUTING"
194+
if error_code == GoalStatus.STATUS_CANCELING:
195+
return "CANCELING"
196+
if error_code == GoalStatus.STATUS_SUCCEEDED:
197+
return "SUCCEEDED"
198+
if error_code == GoalStatus.STATUS_CANCELED:
199+
return "CANCELED"
200+
if error_code == GoalStatus.STATUS_ABORTED:
201+
return "ABORTED"
202+
178203

179204
def main(args=None):
180205
rclpy.init(args=args)

0 commit comments

Comments
 (0)