使用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. [Luogu 3389]【模板】高斯消元法

    Description 给定一个线性方程组,对其求解 Input 第一行,一个正整数 n 第二至 n+1 行,每行 n+1 个整数,为a1,a2⋯an和 b,代表一组方程.1​​,a​2​​⋯a​n​ ...

  2. [HNOI2004]树的计数

    题目描述 输入输出格式 输入格式: 输入文件第一行是一个正整数n,表示树有n个结点.第二行有n个数,第i个数表示di,即树的第i个结点的度数.其中1<=n<=150,输入数据保证满足条件的 ...

  3. NOIP 2008 双栈排序

    题目描述 Tom最近在研究一个有趣的排序问题.如图所示,通过2个栈S1和S2,Tom希望借助以下4种操作实现将输入序列升序排序. 操作a 如果输入序列不为空,将第一个元素压入栈S1 操作b 如果栈S1 ...

  4. [Tjoi2013]最长上升子序列

    Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input 第一行一 ...

  5. 洛谷P2221 [HAOI2012]高速公路

    线段树 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> ...

  6. poj2975 Nim 胜利的方案数

    Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5545   Accepted: 2597 Description N ...

  7. UESTC 618 无平方因子数 ( 莫比乌斯)

    UESTC 618 题意:求1到n中无平方因子数的个数 Sample Input 3  1  10  30 Sample Output 1  7  19 思路:与前面的BZOJ 2440相似 #inc ...

  8. 浙大patB习题的一点总结

    嘛嘛,patB的习题已经结束了,这些基本上没有啥特别难的,但还是有几道特别坑爹的题(o(╯□╰)o),还是把这些题的代码打包上传吧.

  9. sqlserver 取日期年份月份

    select convert(varchar(10),datepart(YYYY,a.fssj)) as years,--得到年份convert(varchar(10),datepart(mm,a.f ...

  10. gulp将多张小图自动合成雪碧图

    最近一直在做移动端的改版项目,做之前老大就跟我说了好几次,说这次改版一定要用雪碧图减少一个页面的图片的请求次数,能加快页面的加载速度就一定要加快,我说可以.因为之前的项目开发时间过短,也没有时间去慢慢 ...