How to cancel a move_base goal using smach SimpleActionState?
Hello,
I am using smach with a SimpleActionState to send navigation goals to move_base with:
StateMachine.add('GO_TO_DOCKING_ZONE',SimpleActionState('move_base',MoveBaseAction, goal_cb = goal_callback, result_cb=goToDocking_result_cb),transitions = {'succeeded':'IR_MONITOR'})
And I would like to cancel this goal. I know that the way to do that is with cancel_goal function, but I do not how to call it using smach.
Any suggestions?
Best regards,
Teresa
Asked by tseco on 2016-04-29 05:20:06 UTC
Answers
Hello! I got a solution, perhaps it is not the best one but it works.
I added a generic state to the smach state machine:
StateMachine.add('CANCEL', CancelGoal(), transitions={'cancel_outcome':'cancel_aborted'})
The CancelGoal function implemented consits of publishing an empty goal in the /move_base/cancel topic:
class CancelGoal(smach.State):
def __init__(self):
smach.State.__init__(self, outcomes=['cancel_outcome'])
self.cancel_pub = rospy.Publisher('move_base/cancel', GoalID, queue_size=10)
def execute(self, userdata):
setCancelState(True)
goalId = GoalID()
self.cancel_pub.publish(goalId)
return 'cancel_outcome'
I hope this helps.
Best regards, Teresa
Asked by tseco on 2016-12-01 04:13:31 UTC
Comments
Its not working. Any update? This cmd worksnrostopic pub /move_base/cancel actionlib_msgs/GoalID -- {} but from python script the goal is not cancled.
Asked by dinesh on 2021-09-25 13:41:11 UTC
Comments
Hello Teresa, I have the same question, I want to cancel a goal when the robot "finds" something, did you get any solution?
Asked by mcamp on 2016-11-30 14:41:00 UTC