How to send Array Message from Arduino to ROS Topic ?
Hi Buddy, I'm newbie in ROS and i trying to send data from arduino to Ros Topic. I have send string and integer type. But in Array type i have a small problem. This is my source code:
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <ros.h>
#include <std_msgs/Int32MultiArray.h>
#include <string.h>
//Creating Nodehandle
ros::NodeHandle nh;
//Declaring String variable
std_msgs::Int32MultiArray msg_arr;
int value[2] = {12,96};
//Defining Publisher
ros::Publisher Pub_Arr("Arduino_Publish", &msg_arr);
void setup(){
//Initializing node
nh.initNode();
//Start advertising
nh.advertise(Pub_Arr);
}
void loop(){
msg_arr.data = value[2];
msg_arr.data_length =2;
Pub_Arr.publish(&msg_arr);
nh.spinOnce();
delay(10);
}
Then i check topic:
rostopic echo /Arduino_Publish
And i get:
layout:
dim: []
data_offset: 0
data: []
---
layout:
dim: []
data_offset: 0
data: []
---
layout:
dim: []
data_offset: 0
data: []
---
I mean i was send nothing. So, how can i fix this ? Thank you !