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 拖曳列表 ...
随机推荐
- [HAOI2007]上升序列
Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ...
- NOIP提高组2010 乌龟棋
小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第N格是终点,游戏要求玩家控制一个乌龟棋子从起点出发走到终点. 乌 ...
- IDF实验室-CTF训练营-牛刀小试CTF
自从开始玩CTF后,发现这个游戏还是比较有意思,发现了一个练习场地IDF实验室:http://ctf.idf.cn/ 刷刷里面的题目,今天完成了其中的牛刀小试,分享一下解题思路: 1. 被改错的密码 ...
- Java并发编程之并发工具类
CountDownLatch CountDownLatch可以用于一个或多个线程等待其他线程完成操作. 示例代码 private static CountDownLatch c = new Count ...
- python文件转exe
.py文件转exe文件 1.软件说明: 用python写一个视频处理软件,用到的库是moviepy 2.所用软件: Python 3.6.5 32位 pycharm 专门的python编辑ide,推 ...
- sqlserver 判断字段是否为空字符串或者null
isnull(f.mzm,'')<>'' 不为null且不为‘’ not(f.mzm is null) 不为null
- idea Library XXXXXXXX has broken classes paths
点fix 然后全部 全部按- 删掉 一开始以为会影响很大 后来发现他地址错了都导不进 要是真要用到的时候也没用 还是要maven单独导进来
- AleNet模型笔记
谁创造了AlexNet? AlexNet是有Hinton大神的弟子Alex Krizhevsky提出的深度卷积神经网络.它可视为LeNet的更深更宽的版本. AlexNet主要用到的技术 成功使用Re ...
- 设计模式:HelloWorld之策略模式
一.概述 策略模式 定义了算法族,分别封装起来,让他们可以互相替换,此模式让算法的变化独立于使用算法的客户. 策略模式的三要素: 抽象策略角色: 策略类,通常由一个接口或者抽象类实现. 具体策略角色: ...
- 搭建一个交互式的前端构建环境.md
为了提高开发效率.减少重复的操作,现在几乎全部的前端项目都需要依赖一些构建工具来实现自动化打包,主流的有webpack, gulp, grunt等.加上各种各样的配置文件就会形成了一个相对复杂的构建环 ...