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

Length of the ranges array in a LaserScan msg

asked 2017-10-07 02:57:05 -0500

sykatch gravatar image

updated 2017-10-07 02:57:33 -0500

Hi,

I'm having this programming problem: I'm cycling through the ranges array in LaserScan messages and accessing its values. I'm using just this simple for cycle:

for (int i = 0; i < sizeof(scan->ranges)/sizeof(scan->ranges[0]); i++)

But the expression for getting the array length returns the value of 6, although the scan contains many more values (seen them through rostopic echo). What am I doing wrong? Isn't this the normal way of obtaining the length of an array in C++?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2017-10-07 03:04:49 -0500

gvdhoorn gravatar image

Isn't this the normal way of obtaining the length of an array in C++?

No. What you show is one approach that you could use in C.

I'm cycling through the ranges array in LaserScan messages [..]

Note that unbounded arrays in ROS msgs are mapped onto std::vector in C++.

If you want to use an old style for-loop, you can use std::vector::size(). Otherwise an iterator is a bit more "C++-y".


Refer to wiki/msg for more information on how ROS msg IDL is mapped onto C++ types.

edit flag offensive delete link more

Comments

Oh, it's a vector. I thought it's a normal array. Thanks, now I get it.

sykatch gravatar image sykatch  ( 2017-10-07 04:19:47 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-10-07 02:57:05 -0500

Seen: 2,262 times

Last updated: Oct 07 '17