Ask Your Question
1

Length of the ranges array in a LaserScan msg

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

sykatch gravatar image

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

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 -0600

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 imagesykatch ( 2017-10-07 04:19:47 -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: 2017-10-07 02:57:05 -0600

Seen: 1,050 times

Last updated: Oct 07 '17