dummy_jta_server.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
4 import math
5 import rospy
6 import actionlib
7 from control_msgs.msg import *
8 
9 
11  # create messages that are used to publish feedback/result
12  _feedback = FollowJointTrajectoryFeedback()
13  _result = FollowJointTrajectoryResult()
14 
15  def __init__(self, robot='pr2'):
16  self._as = actionlib.SimpleActionServer('dummy_controller/follow_joint_trajectory', FollowJointTrajectoryAction, execute_cb=self.execute_cb, auto_start = False)
17  self._as.start()
18  rospy.logwarn("Started Dummy Joint Trajectory Action Server")
19  rospy.logwarn("If joint < 0, set aborted")
20  rospy.logwarn("If joint >= 100, set preempted")
21 
22  # Return result based on real robot jta server.
23  # https://github.com/jsk-ros-pkg/jsk_pr2eus/pull/460#issuecomment-975418370
24  def execute_cb(self, goal):
25  if len(goal.trajectory.points) > 0 and len(goal.trajectory.points[0].positions) > 0:
26  position = goal.trajectory.points[0].positions[0] * 180 / math.pi
27  rospy.loginfo("Received {}".format(position))
28  self._as.publish_feedback(self._feedback)
29  if robot == 'pr2':
30  if position < 0:
31  rospy.logwarn("Set aborted")
32  self._result.error_code = FollowJointTrajectoryResult.GOAL_TOLERANCE_VIOLATED
33  self._as.set_aborted(result=self._result)
34  elif position >= 100:
35  rospy.logwarn("Set preempted")
36  self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL
37  self._as.set_preempted(result=self._result)
38  else:
39  self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL
40  self._as.set_succeeded(result=self._result)
41  if robot == 'fetch':
42  if position < 0:
43  rospy.logwarn("Set aborted")
44  self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL
45  self._as.set_aborted(
46  result=self._result,
47  text='Controller manager forced preemption.')
48  elif position >= 100:
49  rospy.logwarn("Set preempted")
50  self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL
51  self._as.set_preempted(
52  result=self._result,
53  text='Trajectory preempted')
54  else:
55  self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL
56  self._as.set_succeeded(
57  result=self._result,
58  text='Trajectory succeeded.')
59  if robot == 'kinova':
60  if position < 0:
61  rospy.logwarn("Set aborted")
62  self._result.error_code = FollowJointTrajectoryResult.PATH_TOLERANCE_VIOLATED
63  self._result.error_string = 'After validation, trajectory execution failed in the arm with sub error code SUB_ERROR_NONE'
64  self._as.set_aborted(result=self._result)
65  elif position >= 100:
66  rospy.logwarn("Set preempted")
67  self._result.error_code = FollowJointTrajectoryResult.PATH_TOLERANCE_VIOLATED
68  self._result.error_string = 'Trajectory execution failed in the arm with sub error code 55\nThe speed while executing\\n\ the trajectory was too damn high and caused the robot to stop.\n'
69  # NOTE: this line is not typo but kinova driver's behavior
70  self._as.set_aborted(result=self._result)
71  else:
72  self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL
73  self._as.set_succeeded(result=self._result)
74 
75 if __name__ == '__main__':
76  rospy.init_node('dummy_jta')
77  robot = rospy.get_param('~robot', 'pr2')
78  server = DummyJTA(robot)
79  rospy.spin()
object
msg
dummy_jta_server.DummyJTA._as
_as
Definition: dummy_jta_server.py:16
dummy_jta_server.DummyJTA._feedback
_feedback
Definition: dummy_jta_server.py:12
dummy_jta_server.DummyJTA.__init__
def __init__(self, robot='pr2')
Definition: dummy_jta_server.py:15
dummy_jta_server.DummyJTA.execute_cb
def execute_cb(self, goal)
Definition: dummy_jta_server.py:24
dummy_jta_server.DummyJTA._result
_result
Definition: dummy_jta_server.py:13
actionlib::SimpleActionServer
dummy_jta_server.DummyJTA
Definition: dummy_jta_server.py:10


pr2eus
Author(s): Kei Okada
autogenerated on Sun May 11 2025 02:39:49