ROS中发布导航命令有三种方式(但其实本质上都是话题发送)

一、使用Rviz进行导航

 最常见的导航是在Rviz中实现的导航,通过2D Nav Goal可以设置导航目标点,但实际上2D Nav Goal会操作三个话题均有输出:
  /move_base/current_goal
  /move_base/goal
  /move_base_simple/goal

  Rviz中导航操作的主要话题:/move_base_simple/goal
  Rviz中初始位姿操作的主要话题:/initialpose

二、使用终端发布导航命令

向/move_base_simple中发数据

rostopic pub /move_base_simple/goal  geometry_msgs/PoseStamped  '{header: {frame_id: "map"},pose: {position:{x: -1.8,y: 0,z: 0},orientation: {x: 0,y: 0,z: 0,w: 1}}}'

 向/move_base/current_goal中发数据

rostopic pub /move_base/current_goal  geometry_msgs/PoseStamped  '{header: {frame_id: "map"},pe: {position:{x: 1.8,y: 0,z: 0},orientation: {x: 0,y: 0,z: 0,w: 1}}}'

三、使用功能包代码发布

源代码模板如下(这里只提供了.cpp,还要配套的CMakeLists.txt和package.xml):

#include <move_base_msgs/MoveBaseAction.h> 
#include <actionlib/client/simple_action_client.h>
typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;

int main() {
    MoveBaseClient ac("move_base", true);
    // waitForResult()会阻塞当前线程,直到有结果才会退出(一前/一后导航会先前,执行完了再后)
    ac.waitForServer(ros::Duration(60));
    move_base_msgs::MoveBaseGoal goal;
    // 对goal进行填充
    ac.sendGoal(goal);
    ac.waitForResult(); 
    if (ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)         
        ROS_INFO("You have reached the goal!"); 
    else 
        ROS_INFO("The base failed for some reason"); return 0;
}

ac.sendGoal是有三个回调的:ac.sendGoal(goal, &doneCb, &activeCb, &feedbackCb);
参考http://wiki.ros.org/cn/actionlib_tutorials/Tutorials/Writing%20a%20Callback%20Based%20Simple%20Action%20Client

SimpleClientGoalState状态如下:


参考:
  https://docs.ros.org/en/api/actionlib/html/classactionlib_1_1SimpleClientGoalState.html
  https://blog.csdn.net/abcwoabcwo/article/details/103536376