Ask Your Question
0

LaserScan msg ranges.resize() - Arduino

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

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

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);

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

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

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

Comments

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 imageKent Williams ( 2014-08-01 14:49:06 -0600 )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 http://wiki.ros.org/rosserial/Overview/Limitations for an explanation how things work.

Stefan Kohlbrecher gravatar imageStefan Kohlbrecher ( 2014-08-01 17:18:39 -0600 )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

Stats

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

Seen: 789 times

Last updated: Aug 01 '14