目前已经正式支持ROS1和ROS2
在windows系统使用ROS:https://cloud.tencent.com/developer/article/1387067
官方wiki地址汇总请参考:http://blog.csdn.net/zhangrelay/article/details/52705019
调试视频链接:http://v.youku.com/v_show/id_XMTc0MzUxMjE3Mg
在windows系统下有大量的软硬件支持,有些难以移植到Ubuntu系统供ROS使用,如果使得ROS master和windows pc之间进行高效通信,这就可能需要使用rosserial_windows功能包,它可以实现从windows接收和发送ROS消息。在windows端,需要使用Visual Studios Solution,基本流程如下:
(1)使用ROS功能包生成ros_lib
(2)在Visual Studios Solution中使用ros_lib
(3)编写代码使用ros_lib实现和ROS master连接,并收发消息
(4)在Ubuntu端启动rosserial_server socket
(5)编译并运行windows app
在ubuntu安装相应功能包,如下:
~$ sudo apt-get install ros-kinetic-rosserial-windows ros-kinetic-rosserial-server
生成ros_lib,这是windows必须文件:
~$ rosrun rosserial_windows make_libraries.py ros_lib
新建一个win32工程如下,具体如下,细节请参考官方教程:
Copy the ros_lib folder into the rosserial_hello_world project folder. The folder structure should look like:
- ... all of the rosserial generated code, including folders for all of the message packages
- rosserial\_hello\_world/
- [ReadMe](http://wiki.ros.org/ReadMe).txt
- rosserial\_hello\_world.cpp
- rosserial\_hello\_world.vcxproj
- rosserial\_hello\_world.vcxproj.filters
- stdafx.cpp
- stdafx.h
- targetver.h
- rosserial\_hello\_world.opensdf
- rosserial\_hello\_world.sdf
- rosserial\_hello\_world.sln
- rosserial\_hello\_world.v12.suo
Add all of the files in the ros_lib folder that aren't in subfolders to your project. As of writing this, those are:
Then add the ros_lib folder to your includes path by:
主要代码:
#include "stdafx.h"
#include <string>
#include <stdio.h>
#include "ros.h"
#include <geometry_msgs/Twist.h>
#include <windows.h>
using std::string;
int _tmain(int argc, _TCHAR* argv[])
{
ros::NodeHandle nh;
char *ros_master = "192.168.1.102";
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 = 0.4;
twist_msg.linear.y = 0;
twist_msg.linear.z = 0;
twist_msg.angular.x = 0;
twist_msg.angular.y = 0;
twist_msg.angular.z = 0.2;
cmd_vel_pub.publish (&twist_msg);
nh.spinOnce ();
Sleep (100);
}
printf ("All done!\n");
return 0;
}
如果报错,请认真核查是否严格按步骤进行,编译成功后,如下:
rospc端,启动一个小海龟接收消息:
~$ roscore
~$ rosrun turtlesim turtlesim_node
~$ rosrun rosserial_server socket_node /cmd_vel:=/turtle1/cmd_vel
过程和发送消息类似,具体如下:
这个例子和发送类似不详细叙述。
这里例子具体说明一下,rospc接收手机发送的速度消息后发送给winpc,winpc再转发给rospc控制小海龟或turblebot运动。
#include "stdafx.h"
#include <string>
#include <stdio.h>
#include "ros.h"
#include <geometry_msgs/Twist.h>
#include <windows.h>
using std::string;
geometry_msgs::Twist twist_msg;
void cmd_vel_angular_callback (const geometry_msgs::Twist & cmd_vel)
{
printf ("接收手机cmd_vel %f, %f, %f, %f, %f, %f\n",
cmd_vel.linear.x, cmd_vel.linear.y, cmd_vel.linear.z,
cmd_vel.angular.x, cmd_vel.angular.y, cmd_vel.angular.z);
twist_msg=cmd_vel;
}
int _tmain(int argc, _TCHAR* argv[])
{
ros::NodeHandle nh;
char *ros_master = "192.168.1.102";
printf ("正在连接 %s\n", ros_master);
nh.initNode (ros_master);
ros::Subscriber < geometry_msgs::Twist >
poseSub ("cmd_vel", &cmd_vel_angular_callback);
nh.subscribe (poseSub);
printf ("等待接受消息\n");
printf ("转发cmd_vel_winpc消息 \n");
ros::Publisher cmd_vel_pub ("cmd_vel_winpc", &twist_msg);
nh.advertise (cmd_vel_pub);
while (1)
{
cmd_vel_pub.publish (&twist_msg);
nh.spinOnce ();
Sleep (100);
}
printf ("All done!\n");
return 0;
}
ros:
~$ roslaunch turtlebot_gazebo turtlebot_world.launch
~$ rostopic echo /cmd_vel_winpc
-End-