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

Goals skipped while sending multiple goals to navigation-stack

asked 2022-06-03 01:52:12 -0500

Rahulwashere gravatar image

updated 2022-07-26 15:43:34 -0500

lucasw gravatar image

Hello, so i have been writing a node based on simple action client in ROS that sends a list of goals to navigation stack one by one. the issue is some goals are skipped, looks like the move_base server gets the goal, plans a path (it is shown on RViz) and then immediately skips it and processes another goal, so what happens is that some goals are processed some are not. here is the code:

#include <iostream>
#include <ros/ros.h>
#include <move_base/move_base.h>
#include <actionlib/client/simple_action_client.h>
#include <vector>

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


int main(int argc, char **argv){



    ROS_INFO("Simulation is begining");

    // initialize the node
    ros::init(argc, argv, "xbot_planner");
    // declare the client
    xbotclient op("move_base",true);

    std::vector <std::vector<float>> mcn_cord_nd_orent{{9,9.3,1,0},{3.5,9.3,1,0},{-3,9.3,1,0},{-9,9.3,1,0},{9,9.3,1,0},{3.5,9.3,1,0},{-3,9.3,1,0},{-9,9.3,1,0},{7.2,-6,-0.707,0.707},{3,-6,-0.707,0.707},{-1.4,-6,-0.707,0.707},{-6,-6,-0.707,0.707}};


    while(!op.waitForServer(ros::Duration(5.0))){

        ROS_INFO("waiting for move base server to come up"); 
    }
    ros::Time startTime = ros::Time::now();
    ros::Duration cycleDuration(600);
    int i = 0;

    while(ros::Time::now() < startTime+cycleDuration){

        move_base_msgs::MoveBaseGoal goal1;
        goal1.target_pose.header.frame_id = "map";
        goal1.target_pose.header.stamp = ros::Time::now();

        goal1.target_pose.pose.position.x = mcn_cord_nd_orent[i][0];
        goal1.target_pose.pose.position.y = mcn_cord_nd_orent[i][1];
        goal1.target_pose.pose.orientation.z = mcn_cord_nd_orent[i][2];
        goal1.target_pose.pose.orientation.w = mcn_cord_nd_orent[i][3];

        ROS_INFO("SENDING GOAL");

        op.sendGoal(goal1);
        ROS_INFO("goal 1 sent");

        op.waitForResult();
        if(op.getState() == actionlib::SimpleClientGoalState::SUCCEEDED){
            ROS_INFO("OPERATION completed");
            i = i + 1;
        }
        else{
            ROS_INFO("operation failed");
            return 0;
        }
        if (i == 7){
            i = 0;
        }

}
return 0;

}

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-07-26 01:34:10 -0500

Rahulwashere gravatar image

I found what was wrong with the above code, i needed to slow down the node, for some reason(not clear to me) move_base server takes a little more time to refresh the new goal, so when a newer goal is given the client already thinks it has succeeded which was a message from previous goal state. by slowing down the node we give enough time for goal state to be refreshed. it may not be the ideal solution but it worked pretty fine for me. just add the following line at the end of node.it makes node sleep for 1 second.

ros::Duration(1.0).sleep();

edit flag offensive delete link more

Comments

Thanks for sharing your workaround. You could probably sleep() for a lot less time if it was important to your application.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-07-27 12:44:32 -0500 )edit
0

answered 2022-06-03 13:39:00 -0500

Mike Scheutzow gravatar image

Your code increments variable i twice every time through the loop.

edit flag offensive delete link more

Comments

Hi, i removed that second i incremental element. the problem is move_base server registers the next goal, it will also show a path on Rviz, like usual, but then it will immediately abandon that goal and move to next one and execute that. i hope you get the issue.

Rahulwashere gravatar image Rahulwashere  ( 2022-06-04 00:39:01 -0500 )edit

I don't see any obvious problem with your revised code. move_base thinks it reached the goal (because a failure or abort would cause your ros node to exit.) In move_base, which local planner are you using and what goal tolerance have you set?

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-06-04 10:10:05 -0500 )edit

I am using DWA planner. and my tolerances are pretty much the standard ones. i don't think the issue is tolerances though. if i give a single goal through RViz, robot goes and orients perfectly fine. Its just that robot does take the goal but it skips them and moves to another goal thereby executing some goals and some not. sorry for replying so late as my laptop was under repair

Rahulwashere gravatar image Rahulwashere  ( 2022-07-20 01:22:52 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2022-06-03 01:52:12 -0500

Seen: 162 times

Last updated: Jul 26 '22