0
$\begingroup$

Rosanswers logo

Hi to everyone, i'm using a class in which some methods call actions as SimpleActionClient. I create a node in the same executable i create the class instance and leave if the signal handling. When i press ctrl+c , the executable stops but the action is completed anyway. The code is:

self.__move_base_action = actionlib.SimpleActionClient('/sweepee/move_base', MoveBaseAction)
.....
try:
        while True:
            self.__move_base_action.wait_for_server()
            goal = MoveBaseGoal()
            goal.target_pose.header.frame_id = "map_sweepee"
            print("moving to : ",pos_in[0], pos_in[1], pos_in[2], pos_in[3])
            goal.target_pose.header.stamp = rospy.Time.now()
            goal.target_pose.pose.position.x = pos_in[0]
            goal.target_pose.pose.position.y = pos_in[1]
            goal.target_pose.pose.orientation.z = pos_in[2]
            goal.target_pose.pose.orientation.w = pos_in[3]

            self.__move_base_action.send_goal(goal)
            wait = self.__move_base_action.wait_for_result()
            if not wait:
                self.__move_base_action.cancel_all_goals()
                rospy.logerr("Action server interrupted!")
                return False
            else:
                return self.__move_base_action.get_result()
    except KeyboardInterrupt:
        self.__move_base_action.cancel_all_goals()
        return False

The code actually executes the line: self.__move_base_action.cancel_all_goals() but the action is not stopping. Any idea on why? Thanks


Originally posted by muttidrhummer on ROS Answers with karma: 71 on 2019-10-10

Post score: 1

$\endgroup$

2 Answers 2

1
$\begingroup$

Rosanswers logo

The problem is most likely that at the point where cancel_all_goals() is called, ROS has already shut down. This prevents any actionlib messages from ever reaching your server.


Originally posted by gvdhoorn with karma: 86574 on 2019-10-10

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

Hello,

Take a look at http://wiki.ros.org/rospy/Overview/Initialization%20and%20Shutdown

The part 2.2 :

Registering shutdown hooks

rospy.on_shutdown(h)

    Register handler to be called when rospy process begins shutdown. h is a function that takes no arguments. 

def myhook():
  print "shutdown time!"

rospy.on_shutdown(myhook)

You should be able to call your function self.__move_base_action.cancel_all_goals() in this shutdown hook, that's called before the node is closed.


Originally posted by lmathieu with karma: 591 on 2019-10-10

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by muttidrhummer on 2019-10-11:
Thanks, i already tried this but it does't work actually. If i call class.__move_base_action.cancel_all_goals(), python says " instance has no attribute '__move_base_action' Thanks"

Comment by muttidrhummer on 2019-10-11:
OK, it works. I forgot that python adds a name in front of double underscored methods. Thanks

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.