Sending arrays (LaserScan msg) in rosserial
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)
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).this is most likely the problem:
middle[7]
is a singlefloat
, not an array. The error msg tells you that the field expects an array (or really afloat*
).Ok, so removing the [7] from the line:
to:
seemed to fix the compiling issue. However, while rosserial does publish the message type. The intensities array shows as empty (shows [] in ros).
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.
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 betweenrosserial
androscpp
.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