Earlier (when working with Nav2 module) I have introduced the Path Follower. Please refer to the corresponding chapter (or to links section below) for theory. The idea is very simple: the algorithm finds a point on a path that is ahead of a robot and moves towards it. As it gets closer, a new point is selected and so on. This algorithm is also called Pure Pursuite Path Follower
Of course, some additional euristics are required, for example, it there is a sharp turn ahead, we need to reduce the speed and look for a point that is closer to a robot.
In this section we will create a fully functional Path Follower for our 2.5d world. It will rely on localization data from our Kalman filter that performs sensor fusion, and it will send commands to our robot, so it follows the path.
Note that, while being a must for any robotic library, Path Follower is not a universal solution. Let me show an exagerated (by playing with parameters) result of "path following":
What happened? Our path follower is only as good as localization data is: if the robot's position and orientation info "jumps", the robot will move in the wrong direction. Then it will correct itself, which can produce rather signifficant deviations from a path.
So what do we do? If you run the example, you will notice that the robot leaves the road, sometimes on the very steep areas, which is not safe. Also, if we let it drive like that, the road police might have some questions...
This is why we use "global" and "local" algorithms in robotics. I will use "local" algorithm to fix the problem in future, for now just keep in mind that we should do what humans usually do: create an accurate local map (say, within the visible range) and move there, using global localization data for high level guidance only. A good example would be using odometer, as - without slippage - it gives us an accurate positioning. But as it does slip, we will probably use some other navigation technics. A human would probably say something like "this tree is in the right direction, so I am going there and then look at a compass again". Robot can do the same.
Once again, the Path Following algorithm will still be used, but the robot will use additional local navigational tricks to improve its positioning.