Ask Your Question

How to send a new goal (MoveBaseGoal) without interrupting the node (python)?

asked 2019-08-15 05:13:43 -0600

Dimi gravatar image

Hello to everyone.

When I want to send a goal(x,y) using the code below, everything works fine. The robot is moving towards the predefined goal. However my node stops working while MoveBase is under process.

So, if I desire to move to a new goal (before the previous goal come to an end), how can I send this new goal without interrupting the whole node ??

   client = actionlib.SimpleActionClient('move_base', MoveBaseAction)
   goal = [x_goal, y_goal] # x,y are obtained by a function .. NOT always same x,y
   goal = MoveBaseGoal()
   goal.target_pose.header.frame_id = "map"
   goal.target_pose.header.stamp =
   goal.target_pose.pose = Pose(Point(x_goal, y_goal, 0.000), Quaternion(0, 0, 0, 1))
   #Sends the goal to the action server.
   #Waits for the server to finish performing the action.
   wait = client.wait_for_result()
   #If the result doesn't arrive, assume the Server is not available

Do I need to use a kind of feedback callback ? If so, would you please provide me a template of how I'm supposed to do it in Python ?

Thanks !!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-08-15 07:25:39 -0600

pavel92 gravatar image

Your node execution is blocked by wait = client.wait_for_result() which waits for one of actionlib states to be returned. One way to solve your problem is to cancel the current navigation goal. Here is an example how to do this. This will cancel the current goal and then you can send a new one. You can either cancel it "manually" as in the suggested answer or just write your own logic based on which you can publish to the same topic to cancel the goal.

edit flag offensive delete link more


Thanks for your answer. My desire is to solve this issue by coding and not "manually". In order to build my own logic as you mention, it has to be a very specific structure of how I should use a kind of callback I guess in which the new goals will be accepted every time-step. It's very weird that there's a lack of examples (i.e. Templates) in Python for that matter.

Dimi gravatar image Dimi  ( 2019-08-16 09:42:04 -0600 )edit

well if you check the example then you will see that the goal is cancelled by just publishing to a topic. You can implement this logic into your code (you just need a publisher that will publish actionlib_msgs::GoalID message when needed). As for the logic it depends on your use case, so we need more information in order to help you. For example you can use RViz 2D Nav Goal plugin for giving goals (this one automatically cancels the previous one), or just get rid of the wait = client.wait_for_result() line that causes your node to wait for the result since in the code example that you have shown you are not processing the result state.

pavel92 gravatar image pavel92  ( 2019-08-19 02:27:37 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-08-15 05:13:43 -0600

Seen: 849 times

Last updated: Aug 15 '19