-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from tkmtnt7000/add_result_cb
add displaying error msg method to controller-action-client in robot-interface.l
- Loading branch information
Showing
6 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ jobs: | |
git config --global --add safe.directory $GITHUB_WORKSPACE | ||
fi | ||
- name: Chcekout | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
- name: Run jsk_travis | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python | ||
|
||
|
||
import math | ||
import rospy | ||
import actionlib | ||
from control_msgs.msg import * | ||
|
||
|
||
class DummyJTA(object): | ||
# create messages that are used to publish feedback/result | ||
_feedback = FollowJointTrajectoryFeedback() | ||
_result = FollowJointTrajectoryResult() | ||
|
||
def __init__(self, robot='pr2'): | ||
self._as = actionlib.SimpleActionServer('dummy_controller/follow_joint_trajectory', FollowJointTrajectoryAction, execute_cb=self.execute_cb, auto_start = False) | ||
self._as.start() | ||
rospy.logwarn("Started Dummy Joint Trajectory Action Server") | ||
rospy.logwarn("If joint < 0, set aborted") | ||
rospy.logwarn("If joint >= 100, set preempted") | ||
|
||
# Return result based on real robot jta server. | ||
# https://github.com/jsk-ros-pkg/jsk_pr2eus/pull/460#issuecomment-975418370 | ||
def execute_cb(self, goal): | ||
if len(goal.trajectory.points) > 0 and len(goal.trajectory.points[0].positions) > 0: | ||
position = goal.trajectory.points[0].positions[0] * 180 / math.pi | ||
rospy.loginfo("Received {}".format(position)) | ||
self._as.publish_feedback(self._feedback) | ||
if robot == 'pr2': | ||
if position < 0: | ||
rospy.logwarn("Set aborted") | ||
self._result.error_code = FollowJointTrajectoryResult.GOAL_TOLERANCE_VIOLATED | ||
self._as.set_aborted(result=self._result) | ||
elif position >= 100: | ||
rospy.logwarn("Set preempted") | ||
self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL | ||
self._as.set_preempted(result=self._result) | ||
else: | ||
self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL | ||
self._as.set_succeeded(result=self._result) | ||
if robot == 'fetch': | ||
if position < 0: | ||
rospy.logwarn("Set aborted") | ||
self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL | ||
self._as.set_aborted( | ||
result=self._result, | ||
text='Controller manager forced preemption.') | ||
elif position >= 100: | ||
rospy.logwarn("Set preempted") | ||
self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL | ||
self._as.set_preempted( | ||
result=self._result, | ||
text='Trajectory preempted') | ||
else: | ||
self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL | ||
self._as.set_succeeded( | ||
result=self._result, | ||
text='Trajectory succeeded.') | ||
if robot == 'kinova': | ||
if position < 0: | ||
rospy.logwarn("Set aborted") | ||
self._result.error_code = FollowJointTrajectoryResult.PATH_TOLERANCE_VIOLATED | ||
self._result.error_string = 'After validation, trajectory execution failed in the arm with sub error code SUB_ERROR_NONE' | ||
self._as.set_aborted(result=self._result) | ||
elif position >= 100: | ||
rospy.logwarn("Set preempted") | ||
self._result.error_code = FollowJointTrajectoryResult.PATH_TOLERANCE_VIOLATED | ||
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' | ||
# NOTE: this line is not typo but kinova driver's behavior | ||
self._as.set_aborted(result=self._result) | ||
else: | ||
self._result.error_code = FollowJointTrajectoryResult.SUCCESSFUL | ||
self._as.set_succeeded(result=self._result) | ||
|
||
if __name__ == '__main__': | ||
rospy.init_node('dummy_jta') | ||
robot = rospy.get_param('~robot', 'pr2') | ||
server = DummyJTA(robot) | ||
rospy.spin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env | ||
|
||
(load "package://pr2eus/pr2-interface.l") | ||
(load "unittest.l") | ||
|
||
(init-unit-test) | ||
|
||
(defclass dummy-robot | ||
:super robot-model | ||
:slots (link-1 link-2 joint-1)) | ||
(defmethod dummy-robot | ||
(:init () | ||
(let () | ||
(send-super :init) | ||
(setq link-1 (instance bodyset-link :init (make-cascoords) | ||
:bodies (let ((b (make-cube 50 50 100))) | ||
(send b :set-color :red) (list b)))) | ||
(setq link-2 (instance bodyset-link :init (make-cascoords :pos #f(0 0 50)) | ||
:bodies (let ((b (make-cube 40 40 100 :pos #f(0 0 100)))) | ||
(send b :set-color :green) (list b)))) | ||
(setq joint-1 (instance rotational-joint :init :name "joint_1" | ||
:parent-link link-1 :child-link link-2 | ||
:axis :y :min *-inf* :max *inf*)) | ||
(setq links (list link-1 link-2)) | ||
(setq joint-list (list joint-1)) | ||
(send self :assoc link-1) | ||
(send link-1 :assoc link-2) | ||
(send self :init-ending))) | ||
(:joint_1 (&rest args) (forward-message-to joint-1 args)) | ||
) | ||
|
||
(defun dummy-robot () (instance dummy-robot :init)) | ||
|
||
(defclass dummy-robot-interface | ||
:super robot-interface | ||
:slots ()) | ||
(defmethod dummy-robot-interface | ||
(:init (&rest args) (send-super* :init :robot (dummy-robot) args)) | ||
(:default-controller | ||
() | ||
(list | ||
(list | ||
(cons :controller-action "dummy_controller/follow_joint_trajectory") | ||
(cons :controller-state "dummy_controller/state") | ||
(cons :action-type control_msgs::FollowJointTrajectoryAction) | ||
(cons :joint-names '("joint_1"))))) | ||
) | ||
|
||
(setq *robot* (dummy-robot)) | ||
(setq *ri* (instance dummy-robot-interface :init)) | ||
|
||
;; Tests | ||
;; Use :wait-interpolation after :angle-vector to call :action-result-cb | ||
|
||
(deftest test-abort | ||
(send *ri* :angle-vector #f(-100)) | ||
(send *ri* :wait-interpolation)) | ||
|
||
(deftest test-preempted | ||
(send *ri* :angle-vector #f(200)) | ||
(send *ri* :wait-interpolation)) | ||
|
||
(deftest test-suceeded | ||
(send *ri* :angle-vector #f(0)) | ||
(send *ri* :wait-interpolation)) | ||
|
||
(run-all-tests) | ||
(exit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<launch> | ||
<arg name="robot" default="pr2" /> | ||
|
||
<node pkg="pr2eus" type="dummy_jta_server.py" name="dummy_jta_server" > | ||
<rosparam subst_value="true"> | ||
robot: $(arg robot) | ||
</rosparam> | ||
</node> | ||
|
||
<!-- start test --> | ||
<test test-name="$(arg robot)_ri_test_arm" pkg="roseus" type="roseus" retry="1" | ||
args="$(find pr2eus)/test/ri-jta.l" /> | ||
</launch> |