安装
sudo apt-get install ros-indigo-rosserial-windows
sudo apt-get install ros-indigo-rosserial-server
编译
rosrun rosserial_windows make_libraries.py my_library
运行后会产生一个my_library文件夹,在my_library这个文件夹下会生成ros_lib文件夹
Windows下创建代码工程
复制ubuntu下my_library的ros_lib文件夹至windows系统
Windows系统下安装VisualStudio 2013
创建C++工程(rosserial_hello_world),选项中不要选择预编译
添加ros_lib至工程文件夹
VS2013工程配置
将ros_lib文件夹下没有子文件夹的所有文件复制一份至工程目录下
在VS2013属性中配置附加包含目录
代码
#include "stdafx.h"
#include
#include
#include "ros.h"
#include
#include
using std::string;
int _tmain (int argc, _TCHAR * argv[])
{
ros::NodeHandle nh;
char *ros_master = "1.2.3.4"; //ROS的IP地址
printf ("Connecting to server at %s\n", ros_master);
nh.initNode (ros_master);
printf ("Advertising cmd_vel message\n");
geometry_msgs::Twist twist_msg;
ros::Publisher cmd_vel_pub ("cmd_vel", &twist_msg);
nh.advertise (cmd_vel_pub);
printf ("Go robot go!\n");
while (1)
{
twist_msg.linear.x = 5.1;
twist_msg.linear.y = 0;
twist_msg.linear.z = 0;
twist_msg.angular.x = 0;
twist_msg.angular.y = 0;
twist_msg.angular.z = -1.8;
cmd_vel_pub.publish (&twist_msg);
nh.spinOnce ();
Sleep (100);
}
printf ("All done!\n");
return 0;
}
ROS端启动服务
$roscore
$rosrun rosserial_server socket_node
rostopic echo /cmd_vel
启动客户端
参考