Ask Your Question

rosserial multi-array issue

asked 2018-03-16 17:26:50 -0500

vai gravatar image

Here is the relevant parts of my Arduino code:

   #include <Arduino.h>
#include "TeensyThreads.h"

// for ROS
#include <ros.h>
#include <std_msgs/Int16.h>
#include <std_msgs/Int16MultiArray.h>

volatile int liDARfront = -1;
volatile int liDARleft = -1;
volatile int liDARright = -1;

// ROS Variables
ros::NodeHandle  nh;

std_msgs::Int16 front_msg;
std_msgs::Int16 left_msg;
std_msgs::Int16 right_msg;

std_msgs::Int16MultiArray lidar; //multiarray

ros::Publisher range_front("lidar/range_front", &front_msg);
ros::Publisher range_left("lidar/range_left", &left_msg);
ros::Publisher range_right("lidar/range_right", &right_msg);

ros::Publisher lidar_pub("lidarArray", &lidar); //multiarray

void setup()
    Serial1.begin(115200); // HW Serial for TFmini Front
    Serial2.begin(115200); // HW Serial for TFmini Left
    Serial3.begin(115200); // HW Serial for TFmini Right
    Serial.begin(115200); // Serial output through USB to computer

    delay (100); // Give a little time for things to start

    // init ros node

    // for multiarray
    lidar.layout.dim = (std_msgs::MultiArrayDimension *)
    malloc(sizeof(std_msgs::MultiArrayDimension) * 2);
    lidar.layout.dim[0].label = "lidar";
    lidar.layout.dim[0].size = 2;
    lidar.layout.dim[0].stride = 1*2;
    lidar.layout.data_offset = 0;
    lidar.layout.dim_length = 1;
    lidar.data_length = 8; = (int *)malloc(sizeof(int)*2);

void loop()
  delay(10);  // Don't want to read too often as TFmini samples at 100Hz

  // publish to ROS = liDARfront; = liDARleft; = liDARright;

  // collect to one topic[0] = liDARfront;[1] = liDARleft;[2] = liDARright;

  range_front.publish( &front_msg );
  range_left.publish( &left_msg );
  range_right.publish( &right_msg );

  lidar_pub.publish( &lidar);


I get an error that reads:

Arduino: 1.8.5 (Linux), TD: 1.41, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz (overclock), Faster, US English"

TFmini: In function 'void setup()':
 error: cannot convert 'int*' to 'std_msgs::Int16MultiArray::_data_type* {aka short int*}' in assignment = (int *)malloc(sizeof(int));
cannot convert 'int*' to 'std_msgs::Int16MultiArray::_data_type* {aka short int*}' in assignment

any help would be much appreciated!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-04-03 17:34:31 -0500

Mark Rose gravatar image

The problem is that "int" and "short int" are different data types, so pointers to those data are also different types. It appears that on the Teensy an "int" is 32 bits, while you're trying to create a message of type Int16MultiArray.

This should work: = (std_msgs::Int16MultiArray::_data_type*) malloc(2 * sizeof(std_msgs::Int16MultiArray::_data_type));
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-03-16 17:26:50 -0500

Seen: 346 times

Last updated: Apr 03 '18