The code for this section is located in navigation_bot_09 part of an archive. Note that archive includes some additional folders, like maps and worlds, that are used by all projects and therefore are located outside of them. Note also that we use ROS2 Galactic now.
This is the first of two articles. Here, we are going to make our waypoints following robot (implemented earlier) to run infinitely, over and over the same set of waypoints. A good example is a security robot running circles around the object it is supposed to guard.
As our robots's batteries discharge, it has to abandon its post and to go to a charging station.
Note that this task has more than one solution. Here we are going to "simply"
place all the logic in the script derived from the waypoint follower that
we created earlier. However, in a "real" robotic app, you probably should use
behaviour trees instead.
Also, you might want to send another robot to continue patrolling as the
first one went for charging.
The project can get even more complex, if you want to resolve conflicts
like few robots arriving simultaneously at the same charging station.
So please consider this example as a very basic one.
The idea behind this example is:
1. We use the waypoint_follower.py from the previous article.
2. As the robot completes navigating over waypoints, it returns to the
first waypoint and the cycle repeats.
3. We have a variable that holds the battery charge. Initially, it is
100%, but it is losing 1% per second. We publish the battery charge using
ROS2 BatteryState Message.
4. In our code, we define the treshold (20%), as the battery goes below it,
the robot should go to a charging station.
5. As the robot arrives to a charging station, it waits for a charge to restore.
6. Finally, robot goes to the next waypoint and the waypoint following resumes.