Imagine being tasked with exploring a vast underground cave system where no human has ever been before. Narrow passages, uneven ceilings, jagged rocks and sudden drops make it far too dangerous for people to enter. Instead, scientists use autonomous drones to safely explore these hidden environments, mapping caves and collecting valuable data without putting anyone at risk.
In this activity, you’ll investigate the Python code used to control a cave exploration drone. Rather than being controlled by a pilot, the drone uses three infra-red distance sensors to detect obstacles in front of it. One sensor points diagonally upwards, one points straight ahead, and one points diagonally downwards. As the drone flies through the cave, these sensors constantly monitor the shape of the ceiling and the ground.

The Python program processes the information from the three sensors many times every second. If one of the sensors detects that the drone is getting too close to the cave walls, the program decides whether the drone should climb, descend or continue flying straight ahead. By repeatedly reading the sensors and adjusting its movement, the drone can navigate safely through the cave while avoiding collisions.
Here is the flowchart for the algorithm to control the drone:

As you work through the code, you will discover how programming, sensors and decision-making algorithms combine to create an autonomous system capable of reacting to its environment in real time. See if you can understand how the drone makes its decisions, then experiment with the code to improve its navigation or add your own ideas!






