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

Revision history [back]

We need to see more of your code to know what's really going on here. But there's a few things I can spot straight away.

Also, i keep getting the index 540, which is my first value as the minimum value : Your loop starts at 541 but your initial closest value at index 540. So if this is invalid i.e. zero, or closer than any other values in the range you're testing then the if statement will never be true. This explains why index 540 comes up so often.

You're also not handling the possibility there are no valid depth samples in the range 540 - 1080, this would also result in an index of 540 being reported.

A note on coding style : you're using the variable minIndex to represent two different things at different points in your code, this is very bad practice. I recommend using a separate variable called closestIndex instead, setting this to an initial impossible value like -1 would allow you to detect when there are no valid samples.

You should use the range_min and range_max values from the laser scan message to check a sample is valid, not simply check it's greater than zero. This may work for some sensors and drivers but will not work in all systems.

I'll second @Delb using ROS_INFO with some extra information so you know what the numbers being printed out mean would be really helpful.

Hope this helps.