Robotics StackExchange | Archived questions

Rosserial_Arduino : Array of Boolean error message

Dear all,

I'm having some trouble with the publishing of an array of boolean coming from an arduino using rosserial. The original idea was the following :

#include <ros.h>
#include <roskeepon/sensorstat.h>

ros::NodeHandle  nh;

roskeepon:: sensorstat buttonState;
ros::Publisher chatter1("buttons", &buttonState);

void setup(){
  nh.initNode();
  nh.advertise(chatter1);
  buttonState.sensorstat_length = 4; }

void loop(){
  for(int i=0 ; i <4;i++){
     buttonState.sensorstat[i] != buttonState.sensorstat[i]; }
  chatter1.publish( &buttonState);
  nh.spinOnce(); 
  delay(1000); 
}

with sensorstat.msg :

bool[] sensorstat

This should change the value of the boolean. But is doesn't, it just initialize a vector of 4 booleans which stay constant. changing the for loop into the following :

for(int i=0 ; i <4;i++){
  if (buttonState.sensorstat[i]){buttonState.sensorstat[i] = false; }
  else { buttonState.sensorstat[i] = true;}
}

but this gives following error when I try to make the serial connection :

[ERROR] [WallTime: 1397466438.097662] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

I tried several things : Like using an array of boolean to go through the loop. Which is later copied to buttonState.sensorstat. Same problem : every thing is good when the value is not changed during the loop, once the value starts changing the same error occurs.

I also tried to use the std_msgs / Int8MultiArray with 1 and 0, but the same problem occurs. everything is fine as long as the value doesn't change.

I searched for several days for a solution, also the web and the ROS forum, but I wasn't successful.

I use Hydro and run Ubuntu 12.04 on an Medion Akoya with kernel 3.2.0-60-generic.

I'm new to ROS and the community so I'm not sure of the question is appropriate...

Anyway : Thanks in advance!

Y2D2

Asked by Y2D2 on 2014-04-13 23:47:35 UTC

Comments

I never used rosserial but could it be the case that buttonState is the data you read from the arduino and when you try setting a value this value gets written to the arduino? Just create a new variable and write to this and then publish this.

Asked by BennyRe on 2014-04-14 03:20:30 UTC

First of all thank you for your reply : but I tried that too : Setting an global boolean array : button : boolean button[4] = {true, false, false, true};

And changing the for loop : for(int i=0 ; i <4;i++){ button[i] != button[i]; }

And then using following for loop (as the boolean array of arduino cannot be copied to the boolean array of the ros message.) : for (int i = 0; i<4; i++){ buttonState.sensorstat[i]= button[i]; }

But this gives the same result...

Or am I not understanding you correctly?

Asked by Y2D2 on 2014-04-14 08:14:43 UTC

I think you have got basically a fundamental problem with programming: Your first for loop for(int i=0 ; i <4;i++){ button[i] != button[i]; } does NOTHING, because you are comparing one boolean on inequality (which always will be false) and asign the result to nothing.

Asked by BennyRe on 2014-04-14 19:51:59 UTC

Second your programming style is far away from every C++ code style I've ever seen. No you didn't get me right. DO NOT WRITE to buttonState.sensorstat. Try this for (int i = 0; i<4; i++){ button[i] = buttonState.sensorstat[i]; } and then publish the button array.

Asked by BennyRe on 2014-04-14 19:54:05 UTC

Ok I saw what I did wrong with the boolean. it should have been button[i] = !button[i]; Still, the same problem occurs and what you suggest doesn't change the msg sent? it changes the internal variable button? Anyway I found something that works, though I'm puzzled why this works and the other one doesn't : I redeclared buttonState in the loop().

Asked by Y2D2 on 2014-04-14 23:51:45 UTC

Answers