使用rosserial_windows实现windows与ROS master发送与接收消息(适用版本hydro,indigo,jade,kinetic

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

主要代码:

#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

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

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

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

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

这里例子具体说明一下,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-

ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息的更多相关文章

  1. 需求:过滤下面这个网页里共723行 校对中里 行数为两位数的 行 并设置sz和rz在Windows和Linux之间发送和接收文件不用搭FTP

    需求:过滤下面这个网页里共723行 校对中里 行数为两位数的 行 并设置sz和rz在Windows和Linux之间发送和接收文件不用搭FTP 需求:过滤下面这个网页里共723行 校对中里 行数为两位数 ...

  2. ROS 用 roboware实现节点信息发送和接收

    在ros下实现节点编程,实现一个节点发送消息,另一个节点接收.实现方式有多种,可以直接在命令窗口创建工作空间包以及节点,用catkin_make进行编译,添加.bash路径,然后执行rosrun  p ...

  3. Windows Azure NotificationHub+Firebase Cloud Message 实现消息推动(付源码)

    前期项目一直用的是Windows azure NotificationHub+Google Cloud Message 实现消息推送, 但是GCM google已经不再推荐使用,慢慢就不再维护了, 现 ...

  4. 【ActiveMQ】ActiveMQ在Windows的安装,以及点对点的消息发送案例

    公司最近会用MQ对某些业务进行处理,所以,这次我下载了apache-activemq-5.12.0-bin把玩下. 基于练习方便需要,使用Windows的版本. 参考的优秀文章: activemq的几 ...

  5. Windows程序设计--(三)窗口与消息

    3.1 窗口的创建 3.1.1 系统结构概述 所谓「Windows给程序发送消息」,是指Windows呼叫程序中的一个函数,该函数的参数描述了这个特定消息.这种位于Windows程序中的函数称为「窗口 ...

  6. 三.jenkins 在windows上配置master 和 agent(slave)

    参考链接: https://wiki.jenkins-ci.org/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+mach ...

  7. ROS知识(5)----消息与服务的示例

    ROS中已经定义了较多的标准类型的消息,你可以用在这些标准类型的消息上再自定义自己的消息类型.这个在复杂数据传输很有用,例如节点和服务器进行交互时,就可能用到传输多个参数到服务器,并返回相应的结果.为 ...

  8. Windows Phone 8.1 发送http 网络请求。

    在windows phone 8.1 中可以用 HttpClient 类来发送http 请求. 例子: try { Uri uri = new Uri(@"http://api.map.ba ...

  9. Windows 系统消息范围和前缀,以及消息大全

    Windows系统定义的消息类别消息标识符前缀 消息分类ABM 应用桌面工具栏消息BM 按钮控件消息CB 组合框控件消息CBEM 扩展组合框控件消息CDM 通用对话框消息DBT 设备消息DL 拖曳列表 ...

随机推荐

  1. 机器学习基石:01 The Learning Problem

    什么时候适合用机器学习算法? 1.存在某种规则/模式,能够使性能提升,比如准确率: 2.这种规则难以程序化定义,人难以给出准确定义: 3.存在能够反映这种规则的资料. 所以,机器学习就是设计算法A,从 ...

  2. python3.6安装PyQt5

    1.安装环境: python3.6 win8系统 2.安装方法 直接在windows cmd命令行(不需要进入python命令行模式)内输入 pip install PyQt5 等一会就行了. 用pi ...

  3. [HAOI 2012]音量调节

    Description 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都要改变一次音量.在演出开始之前,他已经做好了一个列表,里面写着在每首歌开始之前他想要改 ...

  4. 【BZOJ3506】【Cqoi2014】排序机械臂

    传送门(因为BZOJ上没有题面...所以放的是luogu的) 题意:你需要维护一个序列,支持区间翻转与查询区间最小. 解题思路:由于区间最小实际上每一次就是对应的整个数列的第k小,因此可以直接预处理解 ...

  5. ●HDU 2871 Memory Control(Splay)

    ●赘述题目 四种操作: ○Reset:将整个内存序列清空. ○New a:在尽量靠左的位置新建一个长度为a的内存块,并输出改内存块起始位置.(各个内存块即使相邻也不会合并..) ○Free a:将a点 ...

  6. bzoj 3998: [TJOI2015]弦论

    Description 对于一个给定长度为N的字符串,求它的第K小子串是什么. Input 第一行是一个仅由小写英文字母构成的字符串S 第二行为两个整数T和K,T为0则表示不同位置的相同子串算作一个. ...

  7. JSON.NET的Self referencing loop detected with type的原因以及解决办法

    模型中有循环引用是很常见的.例如,以下模型显示双向导航属性: : public class Category : { : public Category() : { : Products = new ...

  8. React Native 系列(三) -- 项目结构介绍

    前言 本系列是基于React Native版本号0.44.3写的,相信大家看了本系列前面两篇文章之后,对于React Native的代码应该能看懂一点点了吧.本篇文章将带着大家来认识一下React N ...

  9. 去掉Bootstrap fileinput缩略图上面的上传删除按钮?

  10. JPA 的 CascadeType 属性 和 FetchType属性 和 各种映射关系

    代码地址:https://gitee.com/a247292980/lgp20151222 CascadeType CascadeType.PERSIST级联新增(又称级联保存): CascadeTy ...