/scan messages not making sense


I am currently trying to get the turtlebot to follow the wall to it’s right and the readings I am getting from /scan do not make sense. They don’t seem to change as expected when approaching a wall. I tested this by just having the subscriber print out the readings and using the teleop program to control the turtle bot. Here is my code
def callback(msg): # detect if there is a wall in front, turn left to maintain wall following forward = 360 right = 0 left = 719 print("right: ", msg.ranges[right]) print("forward: ", msg.ranges[forward]) print("left: ", msg.ranges[left])
I am using the same ranges index as the prior exercises, so I am not sure what is wrong. Thanks

Hello @erbrauch,

Thanks for reaching out and welcome to our forum! Are you doing a course?
If so, which course, unit and exercise are you on?
Also it seems your code is wrongly indented or not indented for some reason. You can try to select the entire code block with your mouse and hit the icon with the angle brackets and a slash from the text formatting options.
Finally in order to better understand your question, could you please explain in more detail what you mean by:

They don’t seem to change as expected when approaching a wall.

What values are you getting, and what values are you expecting?
This will help me to understand the problem and explain better without having to make too much assumptions.

Looking forward to your reply.


Hi! Thanks for getting back to me. The code indenting was from copying the code into the message. I have attached a screenshot that will hopefully be a little more clear. Basically what is happening is that as the robot is approaching the wall on it’s right side, the values for ‘ranges’ don’t decrease. I initially thought it was the algorithm, but then when I just printed the values and controlled the turtlebot via the teleop program it didn’t make sense. perhaps I’m using the wrong indices or syntax? The logic could very well be incorrect, but the readings are definitely still an issue. Some comments might not be exactly where they should be. My apologies!

I’m also in the Ros in 5 days (python) course

Here is the robot position with the output

I managed to figure it out. Turns out an index of approx. 180 works, I would suggest specifying this in the spec/hints so others don’t struggle with this

1 Like

Hi @erbrauch, I’m glad you got that solved.

I made a note of your feedback so that we can improve the course on the next revision.

To get the number of laser scan rays in a laser scan message you can temporarily add a print statement like this one:


Once you have the total number of rays in the message you can calculate the correct indices to use.



Hello @erbrauch,

the rosject for the course project has been updated to include information abut how to interpret the LaserScan message.

Thanks for your feedback,


1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.