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

Sending arrays (LaserScan msg) in rosserial

asked 2018-12-05 07:30:05 -0500

Edie00773 gravatar image

updated 2018-12-05 08:34:16 -0500

gvdhoorn gravatar image

Hi, I'm trying to send data from a temperature sensor using the intensities array within a LaserScan message (this will then be manipulated within ROS further. using laserScan does make sense later down the road).

The sensor gives out an array of 64 numbers, I extract the ones I want and put them into another array, this array is then assigned to the intensities field of the message.

However, when I try to compile the code I get the error:

exit status 1
cannot convert 'float' to 'sensor_msgs::LaserScan::_intensities_type* {aka float*}' in assignment

Code:

#include <ros.h>
#include <ros/time.h>
#include <sensor_msgs/LaserScan.h>

#include <Wire.h>
#include <Adafruit_AMG88xx.h>

//***ROS requrments***//
ros::NodeHandle  nh;

sensor_msgs::LaserScan Temp_distance;
ros::Publisher pub_dis("AMG833", &Temp_distance);

const float angle = 60;
float minimum_angle = 0 - (((angle * 71) / 4068) / 2);
float max_angle = (((angle * 71) / 4068) / 2);
float inc = (((angle * 71) / 4068)/8);

char frameid[] = "/AMG833id";


//***AMG8833 requrments***//
Adafruit_AMG88xx amg;
float pixels[AMG88xx_PIXEL_ARRAY_SIZE];
float middle[7];


void setup()
{
  //***ROS requrments***//
  nh.initNode();
  nh.advertise(pub_dis);

  //***AMG8833 requrments***//
  delay(100); //sensor boot
}

void loop()
{
  //read all the pixels
  amg.readPixels(pixels);


 for (int i = 0; i <=7; i++)
 {
  int pixelval = 32-i;
  middle[i] = pixels[pixelval];
 }


  Temp_distance.angle_min = minimum_angle;
  Temp_distance.angle_max = max_angle;
  Temp_distance.intensities = middle[7];
  Temp_distance.header.frame_id = frameid;
  Temp_distance.header.stamp = nh.now();
  Temp_distance.angle_increment = inc;
  Temp_distance.scan_time = 0.1;

  pub_dis.publish( &Temp_distance );
  nh.spinOnce();
  delay(1000);
}

Sorry if i've got the formatting of the post wrong, (feel free to fix if necessary mods)

edit retag flag offensive close merge delete

Comments

1

Sorry if i've got the formatting of the post wrong, (feel free to fix if necessary mods)

I've fixed it this time for you. Next question will be closed if you don't format it properly.

Use the Preformatted Text button for that (the one with 101010 on it).

gvdhoorn gravatar image gvdhoorn  ( 2018-12-05 08:34:56 -0500 )edit
Temp_distance.intensities = middle[7];

this is most likely the problem: middle[7] is a single float, not an array. The error msg tells you that the field expects an array (or really a float*).

gvdhoorn gravatar image gvdhoorn  ( 2018-12-05 08:36:29 -0500 )edit

Ok, so removing the [7] from the line:

Temp_distance.intensities = middle[7];

to:

Temp_distance.intensities = middle;

seemed to fix the compiling issue. However, while rosserial does publish the message type. The intensities array shows as empty (shows [] in ros).

Edie00773 gravatar image Edie00773  ( 2018-12-05 09:01:20 -0500 )edit

And, I'm sorry, I'm afraid I am not familiar with float* as a variable type, how is it different from float? And I couldn't find any reference page to it, is there a way to convert a float to a float*? As the sensor gives out an array as a float array of 64 characters, and this cannot be changed.

Edie00773 gravatar image Edie00773  ( 2018-12-05 09:05:18 -0500 )edit

I would suggest to take a look at the rosserial/Overview/Limitations page. It discusses the limitations of rosserial and how to deal with them. Lists and arrays work differently between rosserial and roscpp.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-05 09:25:44 -0500 )edit

Thanks, I have looked at it, but I msut admit, I don't understand the example given, and don't know how to apply it in this case. The array test example in arduino, as far as I can tell does not publish an array, only subscribes to one

Edie00773 gravatar image Edie00773  ( 2018-12-05 09:53:29 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-12-05 09:22:19 -0500

updated 2018-12-05 10:17:27 -0500

I will say that using the laser_scan message for something that is not a laser scan is not a good idea. This is breaking the semantics of the message type completely. There is almost certainly a better way of doing this even if you need to make your own custom message type.

However the problem you're having at the moment is cause because you're not manipulating arrays correctly. The type of the laser_scan.intensities variable is a pointer to a float so to set it to point to your middle array you should remove the lvalue so it decomposes to a pointer.

Temp_distance.intensities = middle;

Hope this helps

UPDATE:

I've just checked the documentation for rosserial regarding arrays and you need to add an extra parameter describing the length of an array when working in rosserial. So in your case you'll need to add an extra value as shown below:

Temp_distance.intensities = middle;
Temp_disrance.intensities_length = 7;
edit flag offensive delete link more

Comments

You're right about the OP not populating the intensities field correctly, but this is a rosserial context: arrays and lists in ROS IDL are mapped to malloced arrays there, not to std::vector.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-05 09:24:09 -0500 )edit

You're right. Fixed

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-12-05 09:25:24 -0500 )edit

While changing to your suggestion did allow the code to compile, as mentioned above in the comments, the field when in ros is empty. The messsage displays as (shorted for post length):

intensities: []

This data will be combined with a laser scanner distance measurments as a stop-gap for Rviz

Edie00773 gravatar image Edie00773  ( 2018-12-05 09:43:44 -0500 )edit

I've updated my answer with the solution to this for you now.

Regarding the message type, a PointCloud2 with a custom point type would be the correct way to go about this and could be visualised in RVIZ without any problems.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-12-05 10:18:44 -0500 )edit

Thank you, I was missing the intensities_length message, it now prints. (although it need to be Temp_distance.intensities_length = 8; as the array starts at 0) For some reason it prints every value as -511.75, I don't know why yet. But I suspect thats a different issue.

Thanks all for the help!

Edie00773 gravatar image Edie00773  ( 2018-12-05 10:39:23 -0500 )edit

And thank you, I will likely use PointCloud2 as the enxt logical step then, as most of the work for laser scan is already done and they should be largely the same issues getting both to work

Edie00773 gravatar image Edie00773  ( 2018-12-05 10:42:14 -0500 )edit

I'm glad you got this working. Although I believe the array is still 7 elements long regardless of starting at index 0.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-12-05 10:44:29 -0500 )edit

What makes you say that? When I echoed the message within ros and the array onl had 7 elements until I increased the value to 8. Or are you saying the array i add only had 7 elements? Thanks Edward

Edie00773 gravatar image Edie00773  ( 2018-12-05 11:01:43 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-12-05 07:30:05 -0500

Seen: 992 times

Last updated: Dec 05 '18