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

Question about sending simple goal to navigation stack.

asked 2017-11-15 21:52:10 -0500

LucYang gravatar image

I read this answer about how to publish /move_base_simple/goal. But I want to do something further.

Here is my current setup:

First ran:

roslaunch turtlebot_bringup minimal.launch

roslaunch turtlebot_navigation amcl_demo_rplidar.launch map_file:=/home/ubuntu/maps/mymap.yaml

then I try to publish the goals:

rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped '{header: {stamp: now, frame_id: "map"}, pose: {position: {x: 1.0, y: 0.0, z: 0.0}, orientation: {w: 1.0}}}'

The robot moved.

Then I tried to do something further, so I wrote a node to publish the msg. Here is my code.

#include "std_msgs/String.h"
#include<ros/ros.h>
#include<geometry_msgs/PoseStamped.h>
#include <sstream>

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

  ros::init(argc, argv, "pub_goal");

  ros::NodeHandle nh;

  ros::Publisher pub = nh.advertise<geometry_msgs::PoseStamped>("/move_base_simple/goal",1) ;

  ros::Rate loop_rate(1);

  int count = 0;
  while (ros::ok())
  {

   geometry_msgs::PoseStamped goal;

   goal.header.frame_id="map";
   goal.pose.position.x=1;
   goal.pose.orientation.w=1;
   goal.pose.orientation.z=0;

   ROS_INFO("%lf",goal.pose.position.x);

   pub.publish(goal);

   ros::spinOnce();

   loop_rate.sleep();

   }


  return 0;
}

After actkin_make, I rosrun it, but something wired happened.

Here is the result:

luc@luc-ThinkPad-T450:~/catkin_ws$ rosrun goal_test publish_goal 
[ INFO] [1510794351.286271377]: 1.000000
[ INFO] [1510794352.286323753]: 1.000000
[ INFO] [1510794353.286425226]: 1.000000
[ INFO] [1510794354.286430381]: 1.000000
[ INFO] [1510794355.286429147]: 1.000000
[ INFO] [1510794356.286306929]: 1.000000

But the turtlebot2 is still.

Then I cancel the process by "ctrl+c", the turtlebot2 moved.

So, I am confused.

Could anyone please tell me how to publish a msg through a node to send simple goal to make my turtlebot2 move?

Sorry for my poor English.

edit retag flag offensive close merge delete

Comments

1

Could it be that you send new goals so fast that the navigation stack is still calculating the old goal when it gets replaced by a new one?

Humpelstilzchen gravatar image Humpelstilzchen  ( 2017-11-16 00:52:08 -0500 )edit

@Humpelstilzchen: that is most likely the case, yes.

@LucYang: move_base is going to need some time to plan new trajectories and start moving the robot. It probably cannot do that in 1 second.

gvdhoorn gravatar image gvdhoorn  ( 2017-11-16 01:28:01 -0500 )edit

Thank you! It is exactly the reason what you say.

LucYang gravatar image LucYang  ( 2017-11-16 05:56:35 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-11-16 05:58:11 -0500

LucYang gravatar image

I added

 ros::Duration d(5);

before

loop_rate.sleep();

It works.

edit flag offensive delete link more

Comments

I am new to ROS and I would like to try your code. but I failed running it using rosrun or a launch file. could you tell me how to run it ?

nora gravatar image nora  ( 2018-04-04 03:52:05 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2017-11-15 21:52:10 -0500

Seen: 894 times

Last updated: Nov 16 '17