0
$\begingroup$

Rosanswers logo

Hi everybody i'm currently using an arduino board (MKR WAN 1300) as a ROS node, In the arduino sketch i'm using a custom message type named "RosInfo" and i want him to publish this type of msg to a topic named "/fromarduino".The message definition of RosInfo is the following;

uint32 id   
uint8 lenght
uint8[] value
uint64 timestamp

the problem is that: all the fields seems to work fine but the value field is empty when i try to echo the topic in the command line:


id: 21
lenght: 2
value: []
timestamp: 1562351536
---
id: 20
lenght: 2
value: []
timestamp: 1562351536
---

In the arduino sketch i'm filling the RosInfo obj this way

  ros_pkt.id = buff_toROS[tailR].id;
  ros_pkt.timestamp = buff_toROS[tailR].timestamp;
  ros_pkt.lenght = buff_toROS[tailR].len;

  int i=0;
  
  for(i=0; i<=ros_pkt.lenght; i++){
    ros_pkt.value[i]= buff_toROS[tailR].value[i];
  }
  
  fromarduino.publish(ros_pkt);

buff_toROS is an array that i'm using like a circulare queue:

typedef struct raw_data{
   unsigned char value[8];
   unsigned int id;
   unsigned char len;
   unsigned long timestamp;
} raw_data;

unsigned char headR = 0;
unsigned char tailR = 0;
unsigned int countR = 0;
raw_data buff_toROS[10];

I literally tried as many methods as possible to fill the ros_pkt,value but no one seems to be releted to the the fact that it is empty. Hope that someone could help me. I apologize in advance if I have not asked the question correctly but it is my first on this forum. Thank you all.


Originally posted by dimaluigi on ROS Answers with karma: 3 on 2019-07-05

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I don't really understand your code, but I believe you're not initialising your value field correctly on the rosserial side.

This question: #q203529 shows how to properly do that.

Refer also to rosserial/Overview/Limitations - Arrays for some more information on that topic and see rosserial/Overview/Messages for some more examples.


Originally posted by gvdhoorn with karma: 86574 on 2019-07-06

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by dimaluigi on 2019-07-18:
Thank you so much.The #q203529 is what i needed. The problem was the value_length fiedl that is not part of the actual definition of my message but is implicit. I was filling the vector without inizializing it so the length was always 0.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.