Rosserial_arduino: Ok with Float32MultiArray, not with Int32MultiArray [closed]

asked 2014-12-09 10:54:51 -0500

chambonm gravatar image

Hello, I am new to both Arduino and ROS.

I have connected 3 IR detectors (E18-D50NK) to my Arduino Mega 2560. I am using ROS-Indigo, standard installation on ubuntu

Here is the sketch I have uploaded:

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

std_msgs::Float32MultiArray obstacles_and_holes_msg;
ros::Publisher pub_obstacles_and_holes("obstacles_and_holes", &obstacles_and_holes_msg);
ros::NodeHandle nh;

// IR detectors
#define INFRA_NUM 3
#define INFRA_LATENCY 100
const int INFRA_Pins[INFRA_NUM] = {A0, A1, A2};

void setup()
{
  nh.initNode();                                               // ROS node publisher initialization
  obstacles_and_holes_msg.data_length = 3;                    // length of the message (8 IR detectors and 6 sonars)
  nh.advertise(pub_obstacles_and_holes);
}

long publisher_timer;

void loop()
{
    if (millis() > publisher_timer) {
      for(int i = 0; i<INFRA_NUM; ++i) {
        obstacles_and_holes_msg.data[i] = digitalRead(INFRA_Pins[i]);
        delay(INFRA_LATENCY);
      }
      publisher_timer = millis() + 1000;
      pub_obstacles_and_holes.publish( &obstacles_and_holes_msg );
    }
    nh.spinOnce();
}

As such, everything work: my rostopic terminal prints this every second if the sensors detects nothing:

layout:   
dim: []   data_offset: 0 
data: [1.0,1.0, 1.0]
---

However, when I replace Float32MultiArray by Int32MultiArray (to save memory), there's the following bug: rostopic always prints "0" for the first sensor.

Thank you in advance for your advices,

Best regards,

Marc

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2017-12-20 20:28:36.274600