Rosject Follow Wall Project

Hello. Ive been really struggling with the first part of the rosject. The robot does move and turn but it moves sticking too close to the right wall as it assumes the wall is too far away and does not move away.

If I could get some help understanding how to manoeuvre the robot it would be really appreciated because there is little assistance with this project that I can find.

Hi @khulood1027 ,

I will provide you some tips (not exactly the solution).

  1. It is a good practice to not load the the subscriber callback functions with robot control logic. So remove the robot movement logic from the scan callback and put it inside while not ros.is_shutdown() loop.
  2. You can use a PID control logic or any other adaptive control logic to control your robot’s turning. Otherwise your robot will move far away from wall or too close to the wall.
  3. Work on robot speed control. Don’t move the robot too fast. Also you can’t exceed speed limits - linear - max speed 0.19 m/s, angular - max speed 0.49 rad/s. This is specified in the rosject notes.

That’s all for now.


Thank you for the tips! I shall attempt to use them to fix my code
I did not know that there was a max speed, where are the rosject notes located exactly?


Hi @khulood1027 ,

You can find them at the very bottom of the rosject (ipython) notebook instructions.


When you open the rosject, the notebook should open automatically. If you close it for any reason, you can open it again by pressing the notebook icon at the bottom right group of icons.

Hello again.
I was trying to fix my code when i noticed that my laser values are quite strange.
All angles showed values of 1, but slowly decreased/ went to inf when the robot was stationary.

Am I collecting the laser values incorrectly?

Hi @khulood1027 ,

Your laser indexes for right and left are wrong. The robot uses a 360 degree laser.
Use rostopic echo /scan -n1 to get the scan message details and use that info to understand the indexes.


1 Like

I have the same problem. I have noticed that the laser of the right and left give me same values all the times, so if the laser at right measure 0.2 , the laser at the left give me almost same value though the robot close to the wall in one side and far away from the other side. Any comments here. I believe that task do not require that much of control complexity if the lasers at both side works fine. Waiting for tips

1 Like

We’re looking into this and will get back as soon as possible.

I used the following scan_test file and it gave be a length of 720. Is the laser actually 360 degrees? Using rostopic echo /scan -n1 did not help me understand the laser values either.
I believe I have sorted the movement mechanics of the robot, but the laser readings are still giving me issues.
Any assistance with figuring out the laser readings for right and left would be appreciated

[The file that gave me a reading of 720 below:]

#! /usr/bin/env python3

import rospy
from sensor_msgs.msg import LaserScan

def callback(msg):
sub = rospy.Subscriber(‘/scan’, LaserScan, callback)

Hi @khulood1027 ,

Please refer to this post for further clarity: Incorrect Robot Scan Values in ROS Basics Course - Wall Follower Robot / TurtleBot3

The scan degrees for the robot start with 0 on the back.
0 degrees / 0 ray index = back
90 degrees / 180 ray index = right
180 degrees / 360 ray index = front
270 degrees / 540 ray index = left
360 degrees / 719 ray index = back (again)

I hope this clarifies your doubts.


1 Like

Thank you!
This seems to have fixed my laser readings issue.

I had a final question about the format of the code. You mentioned earlier that robot control logic should not be placed into the subscriber callback function.

I have rewritten my code and placed it in a seperate function which is then called by the loop, however it only runs once and does not continue executing, nor move the robot.

What would be the correct format for the code in order to continuously publish into the publisher and read from the subscriber?

def follow_wall():
contains robot control logic and publishing to the publisher

while not rospy.is_shutdown():