The answersDownload the PDF
Worksheet

F6.7 Project: the fail-safe controller

Robust programs · GCSE · about 25 min

BugBotLab
NameClassDate

What this lesson is about

A command program that authenticates, validates every command, and is tested against a plan.

Questions 4 marks in all

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

    def parse(command):
        parts = command.strip().lower().split()
        if len(parts) != 2 or parts[0] not in ["forward", "back"]:
            return None
        if not parts[1].isdigit() or not 1 <= int(parts[1]) <= 50:
            return None
        return (parts[0], int(parts[1]))
    
    print(parse("Forward 20"), parse("forward 60"), parse(""))
  2. [1 mark]Why put all the command checks in one function, parse?

    1. AEvery command goes through the same checks, and they can be tested on their own
    2. BFunctions run faster
    3. CPython requires validation in a function
    4. DIt avoids using a loop
  3. [1 mark]In the controller's test plan, an empty command is which kind of test data?

    1. AErroneous
    2. BNormal
    3. CBoundary
    4. DValid
  4. [1 mark]Which comes first in the controller, and why?

    1. AAuthentication, so no commands are accepted from someone who is not allowed
    2. BValidation, so the password is sensible
    3. CTesting, so the robot is safe
    4. DThe main loop

The task: the fail-safe controller

Build the controller from the brief with operators = {"ada": "robot42"}. Print access denied for a wrong login, welcome <name> for a right one, invalid command for every command it refuses, and bye on quit. The task types: ada and oops, then ada and robot42, then the commands forward 20, fly 10, right 500, an empty line, right 15, beep and quit.

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

operators = {"ada": "robot42"}
MOVES = ["forward", "back", "left", "right"]

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/f6-7-project-fail-safe-controller/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Refuse a forward command that would take the robot closer than 10 cm to a wall, using distance().
  2. Keep a log of every command in a list, with whether it was obeyed, and print it at quit.
  3. Log out automatically after five invalid commands in a row, and ask for the login again.