在ROS中發(fā)布導(dǎo)航命令有三種方式(但其實本質(zhì)上都是話題發(fā)送)
一、使用Rviz進行導(dǎo)航
??最常見的導(dǎo)航是在Rviz中實現(xiàn)的導(dǎo)航,通過2D Nav Goal可以設(shè)置導(dǎo)航目標(biāo)點,但實際上2D Nav Goal會操作三個話題均有輸出:
??/move_base/current_goal
??/move_base/goal
??/move_base_simple/goal
??Rviz中導(dǎo)航操作的主要話題:/move_base_simple/goal
??Rviz中初始位姿操作的主要話題:/initialpose
二、使用終端發(fā)布導(dǎo)航命令
??向/move_base_simple中發(fā)數(shù)據(jù)
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中發(fā)數(shù)據(jù)
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}}}'
三、使用功能包代碼發(fā)布
??源代碼模板如下(這里只提供了.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()會阻塞當(dāng)前線程,直到有結(jié)果才會退出(一前/一后導(dǎo)航會先前,執(zhí)行完了再后)
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是有三個回調(diào)的:ac.sendGoal(goal, &doneCb, &activeCb, &feedbackCb);
參考http://wiki.ros.org/cn/actionlib_tutorials/Tutorials/Writing%20a%20Callback%20Based%20Simple%20Action%20Client
SimpleClientGoalState狀態(tài)如下:文章來源:http://www.zghlxwxcb.cn/news/detail-682800.html
參考:
??https://docs.ros.org/en/api/actionlib/html/classactionlib_1_1SimpleClientGoalState.html
??https://blog.csdn.net/abcwoabcwo/article/details/103536376文章來源地址http://www.zghlxwxcb.cn/news/detail-682800.html
到了這里,關(guān)于ROS中Navigation發(fā)布方式(3種)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!