Ask Your Question
0

sending a sequence of goals to move_base

asked 2015-06-10 07:36:27 -0500

Naman gravatar image

Hi all,

I have a mobile robot which is navigating around a room and it can go from start to goal without any issues. Now, I want to send a sequence of goals to move_base so that once the robot reaches its first goal, it automatically starts moving to its second goal and so on. One way which I can think of is to send a second goal when the robot reaches its first goal but how can I know that the robot has reached its first goal automatically? Does it publish anything on any topic once it reaches the goal or is any flag set or changed? Does anyone have any idea about how can it be done or is there a better way to send a sequence of goals to move_base so that the robot just keeps on going from one goal to another?

Any help will be appreciated.

Thanks in advance.
Naman Kumar

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-06-10 10:20:38 -0500

David Lu gravatar image

You should use the Action API of move_base.

edit flag offensive delete link more

Comments

Progtologist gravatar imageProgtologist ( 2015-06-10 13:39:18 -0500 )edit

Thanks a lot!

Naman gravatar imageNaman ( 2015-06-10 16:27:05 -0500 )edit

can you please give information how you coped with this problem ?

Developer gravatar imageDeveloper ( 2018-05-28 15:57:10 -0500 )edit
1

answered 2018-05-01 06:33:30 -0500

atas gravatar image

Hi, I modified the famous tutorial that sends goal to move_base. The code sends 5 different goals sequantially. Hope this helps

#include <ros/ros.h>
    #include <move_base_msgs/MoveBaseAction.h>
    #include <actionlib/client/simple_action_client.h>
    #include <iostream>
    #include <array>

    typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;

    int x [5] = { 1, 2, 2, 4, 4}; 
    int y [5] = {0, 0 ,2 , 2, 4};

    int lenght0f_Array = sizeof(x) / sizeof(x[0]);


    int main(int argc, char** argv){
      ros::init(argc, argv, "simple_navigation_goals");

      //tell the action client that we want to spin a thread by default
      MoveBaseClient ac("move_base", true);

      //wait for the action server to come up
      while(!ac.waitForServer(ros::Duration(5.0))){
        ROS_INFO("Waiting for the move_base action server to come up");
      }

      move_base_msgs::MoveBaseGoal goal;

      //we'll send a goal to the robot to move 1 meter forward
      goal.target_pose.header.frame_id = "base_link";
      goal.target_pose.header.stamp = ros::Time::now();
      for( int i = 0; i < lenght0f_Array; i = i + 1 ) {


        goal.target_pose.pose.position.x = x[i];
        goal.target_pose.pose.orientation.w = y[i];
      ROS_INFO("Sending goal");
      ac.sendGoal(goal);

      ac.waitForResult();

      if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
        ROS_INFO("Hooray, the base moved 1 meter forward");
      else
        ROS_INFO("The base failed to move forward 1 meter for some reason");
       }


      return 0;
    }
edit flag offensive delete link more

Comments

hello, when I tried your code, i got the following error:

error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

aarontan gravatar imageaarontan ( 2018-06-06 18:39:23 -0500 )edit

I have directed the question here

aarontan gravatar imageaarontan ( 2018-06-16 15:24:58 -0500 )edit

Hi! Isn't it your for loop is just overwriting the same variable and in the end ActionClient simply sends location 5 meters away? What is the purpose of this code?

kurshakuz gravatar imagekurshakuz ( 2019-07-14 11:54:45 -0500 )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

2 followers

Stats

Asked: 2015-06-10 07:36:27 -0500

Seen: 1,823 times

Last updated: May 01 '18