The worksheetDownload the PDF
Answers

F9.8 Embedded systems: inside BugBot

Logic and computer systems · GCSE · OCR J277 1.1.3, AQA 8525 3.4.5, Edexcel 1CP2 3.1.3 · about 15 min

BugBotLab

What this lesson is about

What makes a system embedded, the robot's three boards, and the sense-decide-act loop.

Questions 5 marks in all

  1. [1 mark]What is an embedded system?

    1. AA computer built into a larger device to control it
    2. BA computer connected to the internet
    3. CA program stored in ROM
    4. DA laptop used in a factory
    Answer: A. A washing machine controller is a classic example.
  2. [1 mark]Which is an embedded system?

    1. AThe controller in a microwave oven
    2. BA desktop PC
    3. CA laptop
    4. DA web server
    Answer: A. The others are general-purpose computers.
  3. [1 mark]Which is typical of an embedded system?

    1. AIt does one dedicated job with limited memory
    2. BIt runs many different apps chosen by the user
    3. CIt has a large screen and keyboard
    4. DIt needs the most powerful processor available
    Answer: A. Small, cheap, low power, and dedicated.
  4. [1 mark]Put the steps of the control loop in order.

    Number the lines 1 to 3 to put them in the right order.

    1. Decide: work out what to do
    2. Act: set the outputs
    3. Sense: read the inputs
    Answer:
    Sense: read the inputs
    Decide: work out what to do
    Act: set the outputs

    Then repeat, forever.

  5. [1 mark]What does this program print?

    gap = 15
    if gap < 20:
        action = "stop"
    else:
        action = "drive"
    print(action)
    Answer:
    stop

    15 is under 20, so the decision is stop.

The task: a sense-decide-act loop

There is a wall ahead. Write a sense-decide-act loop that drives the robot forward slowly. Each time round: sense the distance; decide; act. While the gap is 20 cm or more, keep driving with a green LED. When it is under 20 cm, stop, turn the LED red, play a tone, and end the loop. Do not hit the wall.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

The hint students can ask for: Start the robot moving, then loop: read the gap, decide, act. While there is room, keep the LED green. When the gap is too small, stop, turn the LED red, sound the tone and leave the loop.

A solution

from bugbot import *
connect()
drive(30, 0)
while True:
    gap = distance()
    if gap < 20:
        stop()
        led(255, 0, 0)
        tone(880, 0.3)
        break
    else:
        led(0, 255, 0)
    wait(0.05)

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.