The worksheetDownload the PDF
Answers

0.1 Your first program

Python quick start · Robot club · about 10 min

BugBotLab

What this lesson is about

The two lines at the top, drive, wait, stop, print, and the rule that stops the robot on its own.

Questions 7 marks in all

  1. [1 mark]What does connect() do?

    1. AGets you the robot, ready to take commands
    2. BBrings in the robot's commands
    3. CStarts the robot driving
    4. DPrints a line under the program
    Answer: A. from bugbot import * brings in the commands, and connect() gets you the robot itself. You need both lines at the top.
  2. [1 mark]What does forward(50) do on its own?

    1. AStarts the robot at half speed and goes straight on to the next line
    2. BDrives 50 cm and then stops
    3. CDrives for 50 seconds
    4. DWaits until the robot has finished moving
    Answer: A. forward(50) only starts the robot going. It does not wait, which is why you need wait() to let it drive for a while.
  3. [1 mark]This program has no stop(). What does the robot do?

    from bugbot import *
    connect()
    
    forward(60)
    wait(1.5)
    1. ADrives for about 1.5 seconds, then stops by itself once the program stops sending it commands
    2. BDrives for ever until you close the page
    3. CNever moves, because there is no stop()
    4. DStops straight away, because the program is too short
    Answer: A. The real robot stops on its own if it hears nothing from your program for half a second, and the simulator stops it the moment the program ends. Either way a crashed program cannot drive it into a wall.
  4. [1 mark]Put these lines in order to drive forward for two seconds, stop, and then say so.

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

    1. connect()
    2. wait(2)
    3. from bugbot import *
    4. forward(50)
    5. print("done")
    6. stop()
    Answer:
    from bugbot import *
    connect()
    forward(50)
    wait(2)
    stop()
    print("done")

    The two setup lines always come first. Then start driving, let time pass, switch the motors off, and only then print that you have finished.

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

    print("drove for", 2, "seconds")
    Answer:
    drove for 2 seconds

    Commas in print() put a single space between each thing, whether it is text or a number.

  6. [1 mark]Which of these make BugBot move across the mat?

    Tick every answer that is true.

    1. Aforward(60)
    2. Bright(60)
    3. Cled("green")
    4. Dbackward(60)
    5. Eprint(position())
    Answer: A, B, D. forward, backward and right drive the robot. led only changes the light, and print only writes a line.
  7. [1 mark]You drive forward for 1 second and back for 1 second. Why does position() not say exactly (0, 0)?

    1. ADriving by time is never exact, and the robot leans a little as it goes
    2. BThere is a mistake in the program
    3. Cposition() counts from the middle of the mat
    4. Dbackward() always goes twice as far
    Answer: A. Timing a drive can never be exact, and the vibrating feet push a little unevenly. Module 2 shows how the sensors fix that.

The task: cross the line

Drive from the start into the green zone and stop inside it, using forward, wait and stop. If it stops short, wait longer or drive faster.

from bugbot import *
connect()

forward(50)
wait(1)
stop()

The hint students can ask for: The green zone starts 40 cm ahead. Drive long enough, or fast enough, to get there, then stop inside it.

A solution

from bugbot import *
connect()
forward(60)
wait(4)
stop()

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