ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息
使用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
- 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
- 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:
- 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
主要代码:
#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发送与接收消息的更多相关文章
- 需求:过滤下面这个网页里共723行 校对中里 行数为两位数的 行 并设置sz和rz在Windows和Linux之间发送和接收文件不用搭FTP
需求:过滤下面这个网页里共723行 校对中里 行数为两位数的 行 并设置sz和rz在Windows和Linux之间发送和接收文件不用搭FTP 需求:过滤下面这个网页里共723行 校对中里 行数为两位数 ...
- ROS 用 roboware实现节点信息发送和接收
在ros下实现节点编程,实现一个节点发送消息,另一个节点接收.实现方式有多种,可以直接在命令窗口创建工作空间包以及节点,用catkin_make进行编译,添加.bash路径,然后执行rosrun p ...
- Windows Azure NotificationHub+Firebase Cloud Message 实现消息推动(付源码)
前期项目一直用的是Windows azure NotificationHub+Google Cloud Message 实现消息推送, 但是GCM google已经不再推荐使用,慢慢就不再维护了, 现 ...
- 【ActiveMQ】ActiveMQ在Windows的安装,以及点对点的消息发送案例
公司最近会用MQ对某些业务进行处理,所以,这次我下载了apache-activemq-5.12.0-bin把玩下. 基于练习方便需要,使用Windows的版本. 参考的优秀文章: activemq的几 ...
- Windows程序设计--(三)窗口与消息
3.1 窗口的创建 3.1.1 系统结构概述 所谓「Windows给程序发送消息」,是指Windows呼叫程序中的一个函数,该函数的参数描述了这个特定消息.这种位于Windows程序中的函数称为「窗口 ...
- 三.jenkins 在windows上配置master 和 agent(slave)
参考链接: https://wiki.jenkins-ci.org/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+mach ...
- ROS知识(5)----消息与服务的示例
ROS中已经定义了较多的标准类型的消息,你可以用在这些标准类型的消息上再自定义自己的消息类型.这个在复杂数据传输很有用,例如节点和服务器进行交互时,就可能用到传输多个参数到服务器,并返回相应的结果.为 ...
- Windows Phone 8.1 发送http 网络请求。
在windows phone 8.1 中可以用 HttpClient 类来发送http 请求. 例子: try { Uri uri = new Uri(@"http://api.map.ba ...
- Windows 系统消息范围和前缀,以及消息大全
Windows系统定义的消息类别消息标识符前缀 消息分类ABM 应用桌面工具栏消息BM 按钮控件消息CB 组合框控件消息CBEM 扩展组合框控件消息CDM 通用对话框消息DBT 设备消息DL 拖曳列表 ...
随机推荐
- php代码审计之变量覆盖
变量覆盖一般由这四个函数引起 <?php $b=3; $a = array('b' => '1' ); extract($a,EXTR_OVERWRITE); print_r($b); / ...
- [NOI 2014]动物园
Description 题库链接 \(t\) 组询问.每组询问给出一个字符串 \(S\) .要求求出一个 \(num\) 数组一一对于字符串 \(S\) 的前 \(i\) 个字符构成的子串,既是它的后 ...
- [HNOI2007]分裂游戏
Description 聪聪和睿睿最近迷上了一款叫做分裂的游戏. 该游戏的规则试: 共有 n 个瓶子, 标号为 0,1,2.....n-1, 第 i 个瓶子中装有 p[i]颗巧克力豆,两个人轮流取豆子 ...
- ●BZOJ 2434: [Noi2011]阿狸的打字机
●赘述题目 (题意就不赘述了) ●解法: ●我先想的一个比较暴力的方法(要TLE): (ac自动机)先求出last数组(参见刘汝佳的解释:last[j]:表示j节点沿着失配指针往回走时,遇到的下一个单 ...
- ●BZOJ 3238 [Ahoi2013]差异
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3238 题解: 后缀数组套路深. 问题转化为求出任意两个后缀的LCP之和 在计算贡献时,各种不 ...
- ●BZOJ 3622 已经没有什么好害怕的了
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3622 题解: 容斥,dp1).可以求出需要多少对"糖果>药片"(K ...
- [NOI2011]
来自FallDream的博客,未经允许,请勿转载,谢谢. 省选完挂.但是善良的教练今天丢了一套NOI2011给我们训练 6道题233(虽然一道题做过了,一道题普及组的都会,就算是4道吧) 熬了一天,总 ...
- Gradle学习之基础篇
一.gradle基础概念 Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建工具.Gradle抛弃了基于各种繁琐的XML,使用一种基于Groovy的特定领域语言( ...
- 毕业回馈-89C51之GPIO使用(流水灯)
今天分享一个89c51制作的8位流水灯案例.使用Proteus仿真. 同上一遍文章不同.上一篇文章中对于GPIO操作主要是位操作,即sbit led1=P0^0;其中P0^0代表p0.0这个引脚,然后 ...
- Linux学习之CentOS(二)--初识linux的一些常用命令(基础命令)
初次学习linux系统,首先也得会一些linux的基本命令.至少要先学会开启和关闭系统吧!我称为 基础命令! linux命令是对Linux系统进行管理的命令.对于Linux系统来说,无论是中央处理器. ...