use MultiArray in rosserial
Hi All
Can we use std_msgs MultiArray in rosserial?
I'm trying following code, but it doesn't work.
The topic has no data.
We are using rosserial of revision 133:db62c6309a50 tip.
Does anyone have suggestion?
#include <ros.h>
#include <std_msgs/Int16.h>
#include <std_msgs/Int16MultiArray.h>
#include <WProgram.h>
#include <Servo.h>
ros::NodeHandle nh;
std_msgs::Int16MultiArray thermo;
ros::Publisher thermo_pub("thermo", &thermo);
char dim0_label[] = "thermo";
void setup()
{
nh.initNode();
thermo.layout.dim = (std_msgs::MultiArrayDimension *)
malloc(sizeof(std_msgs::MultiArrayDimension) * 2);
thermo.layout.dim[0].label = dim0_label;
thermo.layout.dim[0].size = 8;
thermo.layout.dim[0].stride = 1*8;
thermo.layout.data_offset = 0;
thermo.data = (int *)malloc(sizeof(int)*8);
nh.advertise(thermo_pub);
}
void loop()
{
for(int i = 0; i < 8; i++){
thermo.data[i] = analogRead(i);
}
thermo_pub.publish( &thermo );
nh.spinOnce();
delay(500);
}
the rostopic echo returns
tsuda@tsuda-laptop:~$ rostopic echo /thermo
layout:
dim: []
data_offset: 0
data: []
---