0
$\begingroup$

Rosanswers logo

Hello All,

I am getting the following error when compiling my rosserial_arduino code for sampling and sending a LaserScan msg.

This code works just fine in a standard ros c++ node. Does this member not exist? Am I not accessing it correctly? Thanks!

Compilation Error:

error: request for member ‘resize’ in ‘scan_msg.sensor_msgs::LaserScan::ranges’, which is of non-class type ‘float’*

Code in Question:

unsigned int node_count = 10;

scan_msg.ranges.resize(node_count);


Originally posted by Kent Williams on ROS Answers with karma: 91 on 2014-07-31

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

It appears that using rosserial_arduino, the ranges are not represented by a std::vector (as in roscpp) but by a float* (saving space on a embedded system, probably mainly by not pulling in std::vector). A float pointer naturally does not provide any of the member functions a std::vector does.


Originally posted by Stefan Kohlbrecher with karma: 24361 on 2014-08-01

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Kent Williams on 2014-08-01:
Thanks for the response Stefan!

So if the vector is of type float*, should I be declaring and initializing my ranges variable like so:

float *ranges = new float[num_readings];

and then assigning the ranges to the msg type like so:

scan_msg.ranges = ranges;

This seems to be restricting the ros serial python node from connecting.... so something is off.

Comment by Stefan Kohlbrecher on 2014-08-01:
Memory is pretty restricted on Arduino, it could be that you exceed the processor´s memory if you allocate a too large array. See also http://wiki.ros.org/rosserial/Overview/Limitations for an explanation how things work.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.