Robotics StackExchange | Archived questions

Value received in Arduino is always 0

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.

Asked by jonagf on 2017-03-30 04:22:09 UTC

Comments

Answers

Solved! So apparently the problem was that even thought that another ros node could receive two int64 arrays, the arduino couldn't (it was probably too big). What I did after reinstalling ros and rosserial, was change the message type to uint8[] instead and now it works fine :) I didn't know there was some kind of limitation on data that we could sent (still don't know if its true), but well, since it works perfectly now I'm gonna leave it this way!

Asked by jonagf on 2017-04-03 04:19:33 UTC

Comments