ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

uint8[] field in message definition is empty when i echo the topic.

asked 2019-07-05 14:35:04 -0600

dimaluigi gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-07-06 02:16:23 -0600

gvdhoorn gravatar image

updated 2019-07-06 02:17:22 -0600

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.

edit flag offensive delete link more

Comments

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.

dimaluigi gravatar image dimaluigi  ( 2019-07-18 02:47:32 -0600 )edit

Question Tools

Stats

Asked: 2019-07-05 14:35:04 -0600

Seen: 782 times

Last updated: Jul 06 '19