The answersDownload the PDF
Worksheet

10.4 Trails and tight spots

Competing · Robot club · about 15 min

BugBotLab
NameClassDate

What this lesson is about

A mat that fills up: seeing trails, turning early, keeping to the outside, and turning without stopping.

Questions 6 marks in all

  1. [1 mark]In Light Cycles you want a moment to think. What happens if you stop?

    1. AYou lose: sitting still is not allowed
    2. BNothing, the trails pause too
    3. CYour trail disappears
    4. DThe other robots stop as well
  2. [1 mark]Which line turns a corner without stopping?

    1. Adrive(35, 0, 80)
    2. Bstop() then turn_right(40, angle=90)
    3. Cturn_right(40)
    4. Dbackward(30) then turn_left(40)
  3. [1 mark]Which of these keep you alive longer in Light Cycles?

    Tick every answer that is true.

    1. ATurn early, when a trail is about 30 cm away
    2. BKeep to the outside of the mat
    3. CHead for the middle, where there is most space at the start
    4. DWait until a trail is 15 cm away before turning
    5. ENever stand still
  4. [1 mark]What does this program print?

    import math
    trail = [(0, 30), (10, 30), (20, 30)]
    x, y = 8, 12
    closest = min(math.hypot(px - x, py - y) for px, py in trail)
    print(round(closest, 1))
  5. [1 mark]What does this program print?

    found = None
    print("line ahead?", bool(found))
    found = [200, 5]
    print("line ahead?", bool(found))
  6. [1 mark]Does info()['trails'] include your own trail?

    1. AYes, and touching your own trail puts you out too
    2. BNo, only the other robots' trails
    3. COnly the last 10 cm of it
    4. DOnly in team games

The task: thread the gap

Two trails lie across the mat, each with a gap at one end, and the gaps are at opposite ends. Drive from the start to the green zone at the top without touching a trail. In this task the trails are low walls, 6 cm high, so the depth sensor sees them and the line detector does not.

from bugbot import *
connect()

while position()[1] < 85:
    forward(45)
    wait(0.1)

stop()

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

QR code
Do it on the robot
www.bugbotlab.com/learn/10-4-trails-and-tight-spots/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Use distance() or scan() to spot the trail ahead and steer for the gap rather than driving a fixed path.
  2. Do it again with drive() only, never stopping.
  3. Count how many times you changed direction. Fewer is usually faster.