ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Cancel rospy action with Ctrl+C

asked 2019-10-10 12:22:37 -0600

muttidrhummer gravatar image

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)
        while True:
            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 =
            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]

            wait = self.__move_base_action.wait_for_result()
            if not wait:
                rospy.logerr("Action server interrupted!")
                return False
                return self.__move_base_action.get_result()
    except KeyboardInterrupt:
        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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2019-10-10 13:39:21 -0600


Take a look at

The part 2.2 :

Registering shutdown hooks


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

def myhook():
  print "shutdown time!"


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.

edit flag offensive delete link more


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"

muttidrhummer gravatar image muttidrhummer  ( 2019-10-11 02:54:52 -0600 )edit

OK, it works. I forgot that python adds a name in front of double underscored methods. Thanks

muttidrhummer gravatar image muttidrhummer  ( 2019-10-11 02:58:41 -0600 )edit

answered 2019-10-10 12:39:20 -0600

gvdhoorn gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-10-10 12:22:37 -0600

Seen: 905 times

Last updated: Oct 10 '19