Rosserial arduino MultiArray subscriber ploblem.

asked 2022-02-19 01:49:23 -0600

CHA42 gravatar image

I'm running an Arduino board with rosserial that connects to raspberry pi board and connects with my laptop running Matlab Simulink rosnode that publishing Joystick data ( 0 or 1 when moving joystick analog) using UInt64MultiArray. Matlab rosnode can send data into ros network when I check with rostopic echo. but when I run Arduino, it didn't respond with the data I send and error like this Lost sync with device, restarting.

this is rostopic echo data.

Layout     
Dim           
DataOffset :  0
Data   :  [1, 0, 0, 0, 0, 0, 0, 0]

this is the code I wrote.

#include <ros.h>
#include <std_msgs/UInt64MultiArray.h>

ros::NodeHandle  nh;

void messageCb( const std_msgs::UInt64MultiArray& JOY){

digitalWrite(2,JOY.data[0]);
digitalWrite(3,JOY.data[1]);
digitalWrite(4,JOY.data[2]);
digitalWrite(5,JOY.data[3]);
digitalWrite(6,JOY.data[4]);
digitalWrite(7,JOY.data[5]);
digitalWrite(8,JOY.data[6]);
digitalWrite(9,JOY.data[7]);

}

ros::Subscriber<std_msgs::UInt64MultiArray> sub("JOY", &messageCb );

void setup()
{ 
Serial.begin(9600);
nh.getHardware()->setBaud(9600);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);

nh.initNode();
nh.subscribe(sub);
}

void loop()
{  
nh.spinOnce();
delay(10);
 }

i'm using Arduino uno (ATMEGA328P) and raspberry pi 4 model B (4 gb RAM) with ubuntu 20.04 with ros noetic.

edit retag flag offensive close merge delete