1.安装
官网打不开,翻墙也打不开
https://download.csdn.net/download/weixin_41977332/11257308
安装包直接安装就可
2.使用和填坑
1.新建或打开原有工作区
2.在工作区SRC文件夹下,新建ROS功能包,命名为 test std_msgs roscpp,第一项为功能包名,后两项为依赖项。
3.在test功能包的SRC文件下,新建hello.cpp文件,命名后加入新的可执行文件中(第二项)
4.粘贴如下代码:
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream> int main(int argc, char **argv) {
ros::init(argc,argv,"example");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("message",1000);
ros::Rate loop_rate(10);
while(ros::ok())
{
std_msgs::String msg;
std::stringstream ss;
ss << "Hello world!";
msg.data=ss.str();
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
5.点击左上角的锤子进行编译
若输出栏:
Remote Arguments not configured!
那么改变你的左上角锤子符号后面的选择菜单栏,将Remote Deploy改为DeBug
再点击锤子进行编译,编译通过,显示如下信息:
6.点击上方菜单栏ROS,运行roscore
7.在下方出现的终端中,点击右侧的加号新开一个终端
8.执行 rosrun test hello
若结果为:
那么执行source devel/setup.bash
后重新执行 rosrun test hello
此时:
9. 执行rostopc list
可以查看生成的话题
10. 执行rostopc echo /message
输出话题信息