Ask Your Question

LaserScan msg ranges.resize() - Arduino

asked 2014-07-31 21:31:41 -0500

updated 2014-08-01 00:20:02 -0500

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;


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-08-01 01:13:58 -0500

It appears that using rosserial_arduino, the ranges are not represented by a std::vector<float> (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.

edit flag offensive delete link more


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.

Kent Williams gravatar image Kent Williams  ( 2014-08-01 14:49:06 -0500 )edit

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 for an explanation how things work.

Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2014-08-01 17:18:39 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2014-07-31 21:31:41 -0500

Seen: 949 times

Last updated: Aug 01 '14