官方wiki地址汇总请参考:http://blog.csdn.net/zhangrelay/article/details/52705019
调试视频链接:http://v.youku.com/v_show/id_XMTc0MzUxMjE3Mg
1 简介
在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
2 生成ros_lib
在ubuntu安装相应功能包,如下:
~$ sudo apt-get install ros-kinetic-rosserial-windows ros-kinetic-rosserial-server
生成ros_lib,这是windows必须文件:
~$ rosrun rosserial_windows make_libraries.py ros_lib
3 在Visual Studio Project中添加并使用ros_lib发送消息
新建一个win32工程如下,具体如下,细节请参考官方教程:
Create a new Win32 Console Application
- Open Visual Studio
File -> New Project
Find the Win32 Console Application under Installed -> Templates -> Visual C++ -> Win32
- Give your project a name. We'll use rosserial_hello_world
- You will probably want to turn off precompile headers. The project should work with them enabled, but precompiled headers have caused problems in the past.
Copy ros_lib into the project
Copy the ros_lib folder into the rosserial_hello_world project folder. The folder structure should look like:
- rosserial_hello_world/
- ipch/
- ros_lib/
- ros.h
WindowsSocket.cpp
- ... all of the rosserial generated code, including folders for all of the message packages
ReadMe.txt
Add ros_lib to project
Add all of the files in the ros_lib folder that aren't in subfolders to your project. As of writing this, those are:
- ros.h
- duration.cpp
- time.cpp
WindowsSocket.cpp
Then add the ros_lib folder to your includes path by:
- Right-click on the rosserial_hello_world project in the Solution Explorer and go to Properties
- Under C/C++, add "../ros_lib" to the Additional Include Directories property
主要代码:
如果报错,请认真核查是否严格按步骤进行,编译成功后,如下:
rospc端,启动一个小海龟接收消息:
~$ roscore~$ rosrun turtlesim turtlesim_node~$ rosrun rosserial_server socket_node /cmd_vel:=/turtle1/cmd_vel
4 在Visual Studio Project中添加并使用ros_lib接收消息
过程和发送消息类似,具体如下:
这个例子和发送类似不详细叙述。
5 在Visual Studio Project中添加并使用ros_lib收发消息
这里例子具体说明一下,rospc接收手机发送的速度消息后发送给winpc,winpc再转发给rospc控制小海龟或turblebot运动。
ros:
~$ roslaunch turtlebot_gazebo turtlebot_world.launch~$ rostopic echo /cmd_vel_winpc
-End-