Value received in Arduino is always 0 [closed]
Hi all,
So I have two ROS nodes, one in c++ and another in Arduino. I built a custom message (DataToArduino.h) in the c++ node in which i send two int arrays and one string to the arduino:
Then, in the arduino node I wanted to be able to take those values out, like intensity[0], intensity[1], etc, so I did the following:
#include <projecto/DataToArduino.h>
#include <ros.h>
#include <std_msgs/Int64.h>
ros::NodeHandle nh;
int duration[10];
int location[10];
int x;
void messageCb( const projecto::DataToArduino& subscMsg){
for(int j=0;j<10;j++)
{
duration[j] = subscMsg.intensity[j];
location[j] = subscMsg.location[j];
}
x = duration[5];
}
std_msgs::Int64 test;
ros::Subscriber<projecto::DataToArduino> s("chatter", &messageCb);
ros::Publisher p("my_topic", &test);
void setup()
{
nh.initNode();
nh.subscribe(s);
nh.advertise(p);
}
void loop()
{
test.data = x;
p.publish( &test );
nh.spinOnce();
}
I created a publisher topic so I could see some data to check if what I was receiving was ok. However, when I checked the echo of the topic in the terminal the result was always data 0 and I don't understand why.
Do you have any idea in what the problem can be and any suggestions?
Thank you so much!
Update: I thank that what happened is that my communication with ROS and Arduino stopped working, but I don't know why, since it worked fine before...
My c++ code works well with another c++ node, so I assume the problem is in the arduino part.