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

chambonm's profile - activity

2015-08-03 23:34:48 -0500 received badge  Famous Question (source)
2015-02-05 14:54:42 -0500 received badge  Notable Question (source)
2015-01-30 12:13:03 -0500 received badge  Popular Question (source)
2014-12-09 11:00:44 -0500 asked a question Rosserial_arduino: Ok with Float32MultiArray, not with Int32MultiArray

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