Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add displaying error msg method to controller-action-client in robot-interface.l #460

Merged
merged 28 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b7c660e
add displaying error msg method to controller-action-client
tkmtnt7000 Jun 11, 2021
25a6da0
fix typo in robot-interface.l
tkmtnt7000 Jun 11, 2021
0c38069
Display error code in :action-result-cb
tkmtnt7000 Jun 11, 2021
4cea577
add dummy_jta_server.py and pr2-ri-jta for example code of #460
k-okada Nov 19, 2021
9f9d389
Add pr2, fetch and kinova's actual jta behavior
708yamaguchi Nov 22, 2021
aec2985
Add jta test for pr2, fetch and kinova
708yamaguchi Nov 22, 2021
0ac1d0b
Publish feedback in DummyJTA
708yamaguchi Nov 23, 2021
a43e553
use :status for checking error
tkmtnt7000 Nov 23, 2021
4f33570
delete global function controller-result-error-to-string
tkmtnt7000 Nov 23, 2021
e8e2a40
fix typo
tkmtnt7000 Nov 24, 2021
9e4907f
change log level in a specific case
tkmtnt7000 Nov 24, 2021
9315d5a
Update action-result-cb to make safer against other types of actions
tkmtnt7000 Nov 24, 2021
2e52976
Update indent in :add-result-cb
tkmtnt7000 Nov 24, 2021
7f8fbd0
not displaying warning when succeeded
tkmtnt7000 Nov 24, 2021
f4cbe84
use cond in place of unless and when
tkmtnt7000 Nov 24, 2021
25c8abe
Merge branch 'master' into add_result_cb
k-okada Nov 24, 2021
ddfd204
delete action type checking and returning from function
tkmtnt7000 Nov 24, 2021
1ae2de4
replace similar code
tkmtnt7000 Nov 24, 2021
99fde4d
return-from when follow joint trajectory succeeded
tkmtnt7000 Nov 24, 2021
8e827f9
change order to simplify cond clause
tkmtnt7000 Nov 24, 2021
f6f919a
Merge branch 'master' into add_result_cb
tkmtnt7000 Apr 27, 2022
73e30b0
Merge branch 'master' into add_result_cb
tkmtnt7000 Jun 17, 2022
6df961c
[pr2eus] Use goal-to-status-to-string to show status message
tkmtnt7000 Oct 18, 2022
4899f6f
Merge branch 'master' into add_result_cb
tkmtnt7000 Oct 18, 2022
81ebea6
[pr2eus] fix github action
tkmtnt7000 Oct 18, 2022
2ce0b4c
[pr2eus] Use string
tkmtnt7000 Oct 18, 2022
dbbb3d8
specify full version of actions/Checkout for github
k-okada Oct 15, 2022
46d738c
Merge branch 'master' into add_result_cb
k-okada Oct 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pr2eus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ if(CATKIN_ENABLE_TESTING)
endif()
add_rostest(test/pr2-ri-test-simple.launch)
add_rostest(test/robot-init-test.test) # this uses pr2
add_rostest(test/ri-jta.test ARGS robot:=pr2)
add_rostest(test/ri-jta.test ARGS robot:=fetch)
add_rostest(test/ri-jta.test ARGS robot:=kinova)
endif()
add_rostest(test/robot-no-clock.test)
add_rostest(test/default-ri-test.test)
Expand Down
52 changes: 52 additions & 0 deletions pr2eus/robot-interface.l
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,58 @@
(:time-to-finish ()
(ros::ros-debug "[~A] time-to-finish ~A" ros::name-space time-to-finish)
time-to-finish)
(:action-result-cb (msg)
"
display error messages from [depending on robots]/follow_joint_trajectory/result
"
;; The following error messages will not appear for the first (send *ri* :angle-vector)
;; To display it, use :wait-interpolation or (ros::spin-once groupname)
(let ((status-num (send (send msg :status) :status))
(status-word '(PENDING
tkmtnt7000 marked this conversation as resolved.
Show resolved Hide resolved
ACTIVE
PREEMPTED
SUCCEEDED
ABORTED
REJECTED
PREEMPTING
RECALLING
RECALLED
LOST))
(status-text (send (send msg :status) :text))
(error-code nil)
(error-word '(SUCCESSFUL
INVALID_GOAL
INVALID_JOINTS
OLD_HEADER_TIMESTAMP
PATH_TOLERANCE_VIOLATED
GOAL_TOLERANCE_VIOLATED)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make these strings to avoid making new symbols?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but since there has been no mapping between these strings and error_code yet, we will have to send a pull request to roseus or something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I was unclear. I mean:

(let ((error-word '("SUCCESSFUL"
                    "INVALID_GOAL"
                    "INVALID_JOINTS"
                    "OLD_HEADER_TIMESTAMP"
                    "PATH_TOLERANCE_VIOLATED"
                    "GOAL_TOLERANCE_VIOLATED")))
  ...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I see.
I updated in 2ce0b4c

;; status
(cond ((not (or (= status-num 3) (= status-num 8)))
tkmtnt7000 marked this conversation as resolved.
Show resolved Hide resolved
(ros::ros-error "joint trajectory status: ~A~%"
(cons status-num (elt status-word status-num)))
(unless (string= "" status-text)
(ros::ros-error "~A~%" status-text)))
((= status-num 8)
(ros::ros-warn "joint trajectory status: ~A~%"
(cons status-num (elt status-word status-num)))
(unless (string= "" status-text)
(ros::ros-warn "~A~%" status-text))))
tkmtnt7000 marked this conversation as resolved.
Show resolved Hide resolved
;; error_code and error_string
(cond ((derivedp msg control_msgs::FollowJointTrajectoryActionResult)
;; e.g. pr2_controllers_msgs/JointTrajectoryActionResult does not have :error_code
(setq error-code (send (send msg :result) :error_code))
(when (< error-code 0)
(ros::ros-error "error_code: ~A~%"
(cons error-code (elt error-word (* -1 error-code))))
(unless (string= "" (send (send msg :result) :error_string))
(ros::ros-error "~A~%" (send (send msg :result) :error_string)))))
((= status-num 3)) ;; when succeeded not displaying warning
tkmtnt7000 marked this conversation as resolved.
Show resolved Hide resolved
(t
(ros::ros-warn "~A ~A ~A"
"Result message type is not"
"control_msgs/FollowJointTrajectoryActionResult."
"So error_code is not displaying."))))
(send-super :action-result-cb msg))
(:action-feedback-cb (msg)
(let ((finish-time) (current-time))
(ros::ros-debug "[~A] feedback-cb ~A" ros::name-space msg)
Expand Down
79 changes: 79 additions & 0 deletions pr2eus/test/dummy_jta_server.py
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()
68 changes: 68 additions & 0 deletions pr2eus/test/ri-jta.l
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)
13 changes: 13 additions & 0 deletions pr2eus/test/ri-jta.test
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>