#include <stdio.h>
#include <stdlib.h> #include "ros/ros.h" #include "std_msgs/MultiArrayLayout.h"
#include "std_msgs/MultiArrayDimension.h" #include "std_msgs/Int32MultiArray.h" int main(int argc, char **argv)
{ ros::init(argc, argv, "arrayPublisher"); ros::NodeHandle n; ros::Publisher pub = n.advertise<std_msgs::Int32MultiArray>("array", 100); while (ros::ok())
{
std_msgs::Int32MultiArray array;
//Clear array
array.data.clear();
//for loop, pushing data in the size of the array
for (int i = 0; i < 90; i++)
{
//assign array a random number between 0 and 255.
array.data.push_back(rand() % 255);
}
//Publish array
pub.publish(array);
//Let the world know
ROS_INFO("I published something!");
//Do this.
ros::spinOnce();
//Added a delay so not to spam
sleep(2);
} }
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iostream> #include "ros/ros.h" #include "std_msgs/MultiArrayLayout.h"
#include "std_msgs/MultiArrayDimension.h"
#include "std_msgs/Int32MultiArray.h" int Arr[90];
void arrayCallback(const std_msgs::Int32MultiArray::ConstPtr& array); int main(int argc, char **argv)
{ ros::init(argc, argv, "arraySubscriber"); ros::NodeHandle n; ros::Subscriber sub3 = n.subscribe("array", 100, arrayCallback); ros::spinOnce(); for(j = 1; j < 90; j++)
{
printf("%d, ", Arr[j]);
} printf("\n");
return 0;
} void arrayCallback(const std_msgs::Int32MultiArray::ConstPtr& array)
{ int i = 0;
// print all the remaining numbers
for(std::vector<int>::const_iterator it = array->data.begin(); it != array->data.end(); ++it)
{
Arr[i] = *it;
i++;
} return;
}

ros msg array的更多相关文章

  1. 7、创建ROS msg和srv

    一.msg和srv介绍 msg: msg文件使用简单的文本格式声明一个ROS message的各个域. 仅须要创建一个msg文件,就能够使用它来生成不同语言的message定义代码. srv:srv文 ...

  2. ros 学习 array 的添加

    array的添加,使用 arry[i]赋值时会出现段错误,需要使用array.push_back添加到数据中,在ros中array数组是以vector方式存储的. 例如: 包含数组的msg定义为: h ...

  3. ROS学习手记 - 7 创建ROS msg & srv

    至此,我们初步学习了ROS的基本工具,接下来一步步理解ROS的各个工作部件的创建和工作原理. 本文的详细文档:http://wenku.baidu.com/view/623f41b3376baf1ff ...

  4. 创建一个ROS msg

    1. msg •msg:msg文件是简单的文本文件,用于描述ROS中消息(消息的各个参数项).用于为不同的编程语言生成有关消息的源代码. •srv:描述服务的文件,由两部分组成:请求和反馈: msg文 ...

  5. 建立一个ROS msg and srv

    msg是一个描述ROS消息字段的简单的文本文件,它们经常用来为消息产生不同语言的源代码. srv文件描述一个服务,它由请求和响应两部分组成. msg文件被存储在一个包的msg目录下,srv文件被存储在 ...

  6. ROS学习笔记五:创建和使用ROS msg和srv

    1 msg和srv简介 1.1 msg文件 msg文件就是一个简单的text文件,其中每行有一个类型和名称,可用的类型如下: int8, int16, int32, int64 (plus uint* ...

  7. Creating a ROS msg and srv

    msg: msg files are simple text files that describe the fields of a ROS message. They are used to gen ...

  8. ros msg和srv使用

    在包文件中新建文件夹srv和msg,在这两个文件夹中新建test.msg,test.srv 修改apckage.xml 添加以下内容 <build_depend>:message_gene ...

  9. ROS教程

    Learning ROS 学习ROS Depending on your learning style and preferences, you can take two approaches to ...

随机推荐

  1. python中locals和globals函数

    参考:http://www.cnblogs.com/wanxsb/archive/2013/05/07/3064783.html Python有两个内置的函数,locals() 和globals(), ...

  2. Object类中的五种方法

    clone() Object类源码:protected native Object clone() throws CloneNotSupportedException; 这里有个问题:为什么Sun公司 ...

  3. 【转】C++ const用法 尽可能使用const

    http://www.cnblogs.com/xudong-bupt/p/3509567.html C++ const 允许指定一个语义约束,编译器会强制实施这个约束,允许程序员告诉编译器某值是保持不 ...

  4. PAT 1045 快速排序

    https://pintia.cn/problem-sets/994805260223102976/problems/994805278589960192 著名的快速排序算法里有一个经典的划分过程:我 ...

  5. json数据中的某一个字段进行快速排序quicksort

    快速排序(Quicksort)是对冒泡排序的一种改进,是一种分而治之算法归并排序的风格. 核心的思想就是通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小 ...

  6. jQuery - AJAX get()和post()方法

    jQuery get()和post()方法用于通过HTTP GET或POST请求从服务器请求数据. HTTP请求:GET VS POST 两种在客户端和服务器端进行请求-响应的常用方法是:GET和PO ...

  7. P4462 [CQOI2018]异或序列

    题目描述 已知一个长度为n的整数数列 a1,a2,...,ana_1,a_2,...,a_na1​,a2​,...,an​ ,给定查询参数l.r,问在 al,al+1,...,ara_l,a_{l+1 ...

  8. EOS docker开发环境

    EOS Wiki提供了有关如何使用docker容器编译最新版本代码的说明.但可能有它自己的一些问题,因此我们鼓励你在学习时引用下面镜像.这样最初会更容易,更快. 如果你还没有安装docker,请在此处 ...

  9. sublime text : The emmet plugin doesn't work when tab key was pressed

    Today, I switched my sublime text to version 3. And then I found that  the emmet plugin doesn't work ...

  10. C++——派生类中的访问——可见性问题

    C++中派生类对基类成员的访问形式主要有以下两种: 1.内部访问:由派生类中新增成员对基类继承来的成员的访问. 2.对象访问:在派生类外部,通过派生类的对象对从基类继承来的成员的访问.今天给大家介绍在 ...