Application Example
Application: distance measurement on a robot
First, let us return to the robot example that you already know from lectures and lab sessions. An autonomously driving robot needs collision detection so that it does not drive into obstacles. This task is solved, among other things, by distance sensors. A distance sensor outputs a number that indicates the distance to the nearest obstacle in the sensor’s “line of sight”. An important event occurs, for example, when the robot is about to drive into a wall.
If an obstacle is too close to the robot, it should stop immediately. For this collision detection we use an additional distance sensor for the close range.
In addition, the robot should measure the distance to objects in the direction of travel at regular time intervals. The measurement results feed into an algorithm for determining the direction of travel. For this distance measurement we use a long-range distance sensor.
At the same time, the robot also has other things to do than take care of collision detection or the optimal direction of travel. It observes its surroundings via a camera, sends image data to a smartphone, for example, or it vacuums dust or mows the lawn. How do we ensure that all tasks are carried out at the right time? We define some tasks as the “main program”, which are processed one after the other. These include vacuuming or mowing the lawn. Other tasks are treated as events and solved accordingly with interrupts.
If distance measurements are to be carried out regularly at fixed times, we trigger the measurement with a timer interrupt. In the lecture we work out how timer interrupts are programmed. Please revise the chapter “Timer” (which does not exist, because this is only a trial lecture) before the next lecture. In the lecture you will program a timer interrupt yourself.
As soon as an object is too close, we need an interrupt that stops the robot immediately. It must not finish mowing the lawn first; it must brake immediately. Here an interrupt is required to interrupt the main task immediately. In the lecture I will present how such an interrupt is programmed.