There are three ways to issue navigation commands in ROS (but in fact they are all topic sending)
1. Use Rviz for navigation
The most common navigation is the navigation implemented in Rviz. The navigation target point can be set through 2D Nav Goal, but in fact 2D Nav Goal will operate three topics and output: /move_base/current_goal /move_base/goal /
move_base_simple
/
goal
The main topic of navigation operations in Rviz: /move_base_simple/goal
The main topic of initial pose operations in Rviz: /initialpose
2. Use the terminal to issue navigation commands
Send data to /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}}}'
Send data to /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}}}'
3. Release using function package code
The source code template is as follows (only .cpp is provided here, as well as supporting CMakeLists.txt and 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.sendGoalThere are three callbacks: ac.sendGoal(goal, &doneCb, &activeCb, &feedbackCb);
refer to http://wiki.ros.org/cn/actionlib_tutorials/Tutorials/Writing%20a%20Callback%20Based%20Simple%20Action%20Client
SimpleClientGoalStateThe status is as follows:
Reference:
https://docs.ros.org/en/api/actionlib/html/classactionlib_1_1SimpleClientGoalState.html
https://blog.csdn.net/abcwoabcwo/article/details/103536376