Unable to update data field of Float32MultiArray std msg
I am trying to publish a float array. To do this, I am utilizing the Float32MultiArray std message:
#include <ros.h>
#include <std_msgs/Float32MultiArray.h>
float values[3] = {1.0, 2.0, 3.0};
ros::NodeHandle nh;
std_msgs::Float32MultiArray array_msg;
ros::Publisher pub("array_publisher", &array_msg);
void setup() {
nh.initNode();
nh.advertise(pub);
}
void loop(){
array_msg.data = values;
pub.publish(&array_msg);
nh.spinOnce();
delay(1000);
}
However, when I rostopic echo the publisher, the message is empty i.e. the data field is unpopulated:
rostopic echo /array_publisher
layout:
dim: []
data_offset: 0
data: []
On arduino, I think you also need to set the array length, but I don't remember how to do it offhand.
Take a look at array section on the limitations of
rosserial
page.