Skip to content

Commit

Permalink
Merge pull request #673 from Affonso-Gui/fix_actionilb_preempt_status
Browse files Browse the repository at this point in the history
Fix case function misuse in simple-action-server :set-preempted
  • Loading branch information
k-okada committed Jan 25, 2023
2 parents f29889f + 930ca9c commit bc103da
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
14 changes: 8 additions & 6 deletions roseus/euslisp/actionlib.l
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@
(:get-state ()
(let (state)
(setq state (send (send comm-state :latest-goal-status) :status))
(case state
(actionlib_msgs::GoalStatus::*recalling*
(cond
((= state actionlib_msgs::GoalStatus::*recalling*)
(setq state actionlib_msgs::GoalStatus::*pending*))
(actionlib_msgs::GoalStatus::*preempting*
((= state actionlib_msgs::GoalStatus::*preempting*)
(setq state actionlib_msgs::GoalStatus::*active*)))
state))
(:get-goal-status-text () (send (send comm-state :latest-goal-status) :text))
Expand Down Expand Up @@ -350,11 +350,13 @@
(:set-preempted
(&optional (msg (send self :result)) (text ""))
(ros::ros-info ";; Cancel Goal ~A" (send goal-id :id))
(case status
((actionlib_msgs::GoalStatus::*pending* actionlib_msgs::GoalStatus::*recalling*)
(cond
((or (= status actionlib_msgs::GoalStatus::*pending*)
(= status actionlib_msgs::GoalStatus::*recalling*))
(setq status actionlib_msgs::GoalStatus::*recalled*)
)
((actionlib_msgs::GoalStatus::*active* actionlib_msgs::GoalStatus::*preepmpting*)
((or (= status actionlib_msgs::GoalStatus::*active*)
(= status actionlib_msgs::GoalStatus::*preempting*))
(setq status actionlib_msgs::GoalStatus::*preempted*)
))
(send self :publish-result msg text))
Expand Down
37 changes: 37 additions & 0 deletions roseus/test/test-simple-server-cancel.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env roseus
;;;
;;;

(require :unittest "lib/llib/unittest.l")
(ros::load-ros-package "actionlib")
;;;
;;;
(init-unit-test)

(defun cancel-cb (server goal)
(send server :set-preempted))

(deftest test-server-cancel ()
(let* ((server (instance ros::simple-action-server :init
"/cancel_test" actionlib::TestAction
:execute-cb #'cancel-cb))
(client (instance ros::simple-action-client :init
"/cancel_test" actionlib::TestAction))
(goal (instance actionlib::TestActionGoal :init)))

(send client :wait-for-server)
(send client :send-goal goal)
;; wait until the message is received
(while (not (send server :is-active))
(ros::sleep)
(send server :spin-once))
(send server :worker)
(send client :spin-once)
(ros::ros-info "action server returned with status: ~S" (send client :get-state))
(assert (equal actionlib_msgs::GoalStatus::*PREEMPTED*
(send client :get-state)))))))

(ros::roseus "server_cancel")
(run-all-tests)

(exit)
3 changes: 3 additions & 0 deletions roseus/test/test-simple-server-cancel.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<launch>
<test test-name="simple_server_cancel" pkg="roseus" type="roseus" args="$(find roseus)/test/test-simple-server-cancel.l" />
</launch>

0 comments on commit bc103da

Please sign in to comment.