24
Aug

# [Exploring ROS using a 2 Wheeled Robot] #7: Wall Follower Algorithm

Hello! Welcome to the video #7
of the series exploring ROS with a two-wheeled robot
my name is Marko Hooda and for this video we’re gonna have wall following
algorithm using the same robot we have worked in the previous videos so this
video is going to be a quite different we are going to use ROSDS as usual if you don’t have an account yet you can create one and use ROSDS for free just following
the link at the description of this video after having our account you can
open a project in ROSDS if you have the project already created following the
previous tutorials you can just open your project from the last video and
another option is just to clone the repositories which are also in the
description of this video okay so this time I’m gonna I’m gonna have email in
the right side of my desktop here the simulation running so you can see the
robot performing the task let me change the position of the robot because you
have been seen already there robot following this wall here so let’s change
to the another one let’s put the robot more or less right here okay great
and now let’s take a look on the algorithm okay so you have created
before the go to point algorithm script obstacle avoidance and reading laser and
this time you have to create to have the same code as I do here in my workspace
only this file here follow_wall.py script okay so let me put a little
bigger okay great so as you can see we are just importing the rust by library
which is the most important of course because we are working with Python and
ROS we are also working with lasers or laser scan and publish to the to the
top key which makes the robot move comment velocity which is twist message
okay so let’s take a look here what we have so i’m declare
a global variable here called pub underscore which is our publisher in our
main function let’s minimize the functions here just make confusion we
don’t have to see all of them yet I have also defined the regions of the
laser we have seen already this variable here regem the right region of the robot
front right front front left and the left side of the robot here is the same
thing okay I am defining here I state variable for the robot because and also
I stake state dictionary because we’re gonna have three states basically here
okay so if the robot cannot see any wall we have the first state which is final
wall if the robot has seen a wall it’s the full behavior is should turn to the
left side so we’re gonna keep the wall in our right side and finally after
having the Wow in our right side in the right side of the robot we are gonna
follow the wall okay which is the main task here so let’s take a look in our
main function we are using the publisher here define it at the beginning of the
script initializing our node the name it doesn’t matter so you can change it and
put the name you prefer I am using defining the publisher to the common
velocity and reading the laser of the same torque we have been reading the
previous videos I’m defining a rate here of 20 Hertz for me it’s enough to make
the robot work like this as you can see and inside our loop we are defining a
message and depending on the state we are getting the message values from a
function so for the state number zero we have fine wall for the state number one
we have turned left and the West State number two we have the main task which
is follow the wall okay finally we are publishing the message should come on
velocity and put an old shoe slip to the next time we have to perform the same
tasks so let’s take a look here in the in the
clbk_laser so we are just feeling the region’s variable so we’re using the
global variable here regions on this underscore and we are calling this
function take action which is a function the function this function is just
reading the values from the laser and we are changing this state of the algorithm
okay so we have this function here change state which is basically just
working with the global variables state and state dictionary and if the state is
different than the previous one we change the name of the variable and also
print the the the name of this state we are gonna be okay
so well follow the number of the state and the description of the state of the
robot okay so after taking an action based on the on the reading of the laser
we are using the front region front left and front right and I have changed it
here from the obstacle avoidance algorithm the distance so I put in a
variable here because I don’t want to change it in a lot of places every time
I put here one meter and a half and I have used
variable here okay so I am working with all the possibilities H possibilities of
three variables combination okay and finally after changing this state we
have here our loop which is taking the number of the state we have and
assigning to a function the the task to give the robots velocity okay so in the
case of the robot don’t see any obstacle in front of it we have to find a wall so
basically to find a wall we are just going forward and also turning to the
right side okay so let’s take a look here I’m gonna have the terminal so you
can see the state is changing all the time let’s put a
robot in a position which we cannot see an obstacle actually the laser can
detect the obstacle but we are not using it because the distance from of the
robot to the obstacle is less than a meter and a half ok so let’s see in this
case here the robot cannot see the obstacle so it’s strange final wall and
it’s going forward and turn to the right side and it has just found a wall and
then ok we are doing we are in a going around the obstacle so we cannot see
just one state working so let’s try to put robot or less right here ok so the
robot now is trying to find a wall it has just found a wall and now it’s
following the wall ok and also we have to consider the another state which is
turn left so which is gonna happen when when the robot founds the obstacle and
it’s right in front of the robot so the robot strange find a wall ok and it has
just found the wall here the obstacle when it’s turning to the left side
because you want to keep the wall in the right side of the robot ok this is just
a standard that I have adopt for my my algorithm if you want if you prefer you
can define that your robot will follow a wall and keep it in its left side ok it
doesn’t matter so finally it should return a leftover rhythm I am just
defining and putting an angular velocity here around the z-axis ok so here it’s
positive which is the opposite of the final algorithm which is where the
robots turning to the right side ok and finally, the follow wall algorithm which
is basically go straight ahead ok so there is no mystery here
if the robot has the wall in its right side just goes through the head and we
know that there is something in the right side because we’re using the laser
and it’s data okay so basically that’s it
I hope you enjoy it it’s also important to pay attention to these values here
because if you are working with a different robot okay I have to tell you
that I have done at these fellows fine for my robot and my application so I may
have some problems if I try to use the same algorithm but not just the same
algorithm but the same values here that I that have worked for my robot if I try
to use in a different robot of course if I try to use in a bigger robot I have to
change also the distance that I am detecting the wall because otherwise
we’re gonna just go with the robot in question robot into the wall okay so you
have to pay attention to these variables here okay they were tuning it for this
robot and this scenario okay it’s very important to have it in mind so
basically that’s it I hope you enjoy don’t forget if you like this kind of
video and if you want to keep following this video series we are publishing a
new video every week and for our channel we publish a new video every day so
don’t forget to subscribe and press the bell should be notified every time we
publish something you see you

• Robert Bandit says:

Hi,
What are the differences if this project is carried out with a 4 wheeled vehicle that moves with the ackermann model instead of a two-wheeled vehicle? Are you going to do it for a vehicle that moves with this ackermann model in the next project?

• R. Z. says:

Hello, I am following this series and think it is very well made, thank you!
I would really love to test this algorithms in a real robot, but I am missing a PID controller to control the robots heading. Without closed loop steering to adjust power to motors a real robot would probably never reach its goal or even drive straight. Could you please consider to include this on your project? Thanks a lot again for this great tutorial series!!

• Pito Salas says:

I was going to ask also, what @R.Z. asked below. In my experimentation with a real robot with a lidar the information that I get is very noisy. The robot thinks that it sees a wall on the left and then the right and then the left again in three consecutive scans. The robot jumps around in a very ugly way. Have you tested your code with a real robot?