ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

官方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

  1. Open Visual Studio
  2. File -> New Project

  3. Find the Win32 Console Application under Installed -> Templates -> Visual C++ -> Win32

  4. Give your project a name. We'll use rosserial_hello_world
  5. 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
  • rosserial_hello_world/
  • 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 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:

    Then add the ros_lib folder to your includes path by:

    1. Right-click on the rosserial_hello_world project in the Solution Explorer and go to Properties
    2. Under C/C++, add "../ros_lib" to the Additional Include Directories property

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

     ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

     ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

     

    主要代码:


    如果报错,请认真核查是否严格按步骤进行,编译成功后,如下:

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    rospc端,启动一个小海龟接收消息:

    ~$ roscore
    ~$ rosrun turtlesim turtlesim_node
    ~$ rosrun rosserial_server socket_node /cmd_vel:=/turtle1/cmd_vel

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    4 在Visual Studio Project中添加并使用ros_lib接收消息

    过程和发送消息类似,具体如下:

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    这个例子和发送类似不详细叙述。

    5 在Visual Studio Project中添加并使用ros_lib收发消息

    这里例子具体说明一下,rospc接收手机发送的速度消息后发送给winpc,winpc再转发给rospc控制小海龟或turblebot运动。


    ros:

    ~$ roslaunch turtlebot_gazebo turtlebot_world.launch
    ~$ rostopic echo /cmd_vel_winpc

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息

    ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息


    -End-


    相关文章:

    • 2021-08-16
    • 2021-10-12
    • 2021-12-05
    • 2021-07-03
    • 2022-12-23
    • 2022-01-07
    • 2022-12-23
    猜你喜欢
    • 2022-12-23
    • 2022-12-23
    • 2021-11-23
    • 2021-10-22
    • 2022-12-23
    • 2022-12-23
    • 2021-06-24
    相关资源
    相似解决方案