Smart Home League

Step-by-step Lesson Booklet — U19 (Secondary)
4 LESSONS

Install & run

The Smart Home League folder you received contains two sub-folders: Windows and Mac.

Windows

  1. Open the Windows folder and double-click Smart Home League.exe.
  2. If Windows shows a security prompt the first time, choose More infoRun anyway.
  3. The game window opens by itself — that is all.

Mac

  1. Open the Mac folder and double-click Smart Home League (Mac).command.
  2. If macOS refuses: right-click the file → Open → Open (needed only once).
  3. If macOS offers to install its command-line tools (python3), click Install, then double-click again.

Inside the app: the language switches from the ☰ menu; the base code, the helpers and Match mode sit on each league's front page, and the full rulebook opens from the Rules button.

📍 The Route helper (U19) — tap points, receive code

  1. Open Route helper from the league's front page — a real top-down photo of the house opens.
  2. First pick in the settings whether your robot is red or blue — that robot's starting point appears on the photo with a START badge.
  3. Click the map to drop route points (or use draw mode to sketch a free path that becomes points by itself).
  4. The helper computes the in-between doorway points for you — goto only drives straight lines.
  5. Every point carries a battery chip: 🔋 the estimated charge on arrival and 🏠 the cost of the trip home to the charger — and a red ⚠ if the current settings cannot reach it.
  6. The ⚙ settings box: loop or single pass; battery guard on/off; the "below N% go charge" threshold; and whether to stay on the pad "to N%" or "for N seconds".
  7. The generated code is built on two functions: follow_route() for the route and go_charge() for the charging trip — called at the bottom of the file; you may rename them. If the pad is taken, the robot waits in line politely.
  8. Finish with Copy, ⬇ Download .py, or ▶ — with ▶ the match starts by itself.

The robot's sensors at a glance

The ultrasonic distance sensors (US): front looks straight ahead, frontleft front-left, frontright front-right — the orange arc is the touch bumper

Before you start

The golden rule: the robot program runs 10 times a second, top to bottom; whatever you put in wheelleft / wheelright holds until the next run. Every lesson is a complete runnable program — run it in the in-app Tutorial or paste it into the match editor.

Lesson 1 — The battery: match fuel

In U19 every wheel turn burns charge: battery starts at 100 and falls about 1.7% a second at full throttle — 100% is only ~60 seconds of driving. This code just drives; you watch the gauge.
wheelleft = 25
wheelright = 25

if front < 55:          # just dodge the walls
    wheelleft = 18
    wheelright = -18
elif frontleft < 45:
    wheelleft = 25
    wheelright = 8
elif frontright < 45:
    wheelleft = 8
    wheelright = 25
You should see: Watch the panel: battery falls step by step. At this rate a 3-minute match means at least two charging trips. Next lesson: the station itself.

Lesson 2 — The charging station and goto

The station has a fixed home, given to your code as dockx and docky (cm). goto(x, y) turns, drives and stops there by itself; atgoal turns 1 on arrival. On the pad, charge refills at +25% a second. Careful: goto does not dodge sofas or dogs — watch the bumper!
if state == 0:          # once, at the start
    state = 1
    goto(dockx, docky)  # -> head to the station

if bumper == 1:         # goto does not dodge obstacles
    stopgoto()
    backward(1)
    state = 0           # try again

if atgoal == 1:         # arrived: stand and drink
    wheelleft = 0
    wheelright = 0
You should see: the robot turns toward the station, drives the straight line and parks on the pad — and in the panel, battery starts climbing. After bumps it sets off again.

Lesson 3 — The budget rule

When do we head home? The trip costs roughly home / 25 percent of charge (home = the distance to the dock in cm). The champion adds a fat margin of 22: needed = home / 25 + 22 — it covers the slow rug, detours and bumps. The moment battery dips below needed, leave.
home = distto(dockx, docky)
needed = home / 25 + 22

wheelleft = 25
wheelright = 25

if state == 1:           # on the way home
    if atgoal == 1:
        wheelleft = 0    # stay on the pad and fill up
        wheelright = 0
        if battery > 95:
            state = 0    # full -> back to work
elif battery < needed:   # time to go!
    state = 1
    goto(dockx, docky)
elif front < 55:
    wheelleft = 18
    wheelright = -18
You should see: Let it run: every time battery dips below needed it heads home by itself, drinks to 95% and returns — the real match cycle. Change the 22 margin to 5 and see how dangerous life gets!

Lesson 4 — The state machine

A dependable program means the robot always knows what it is in the MIDDLE of. We write that with state: 0 cleaning, 1 heading home, 2 on the pad. Each state does only its own job and hands over only on explicit conditions — this is the skeleton of the full U19 champion.
home = distto(dockx, docky)

if state == 2:           # state 2: drinking
    wheelleft = 0
    wheelright = 0
    if battery > 95:
        state = 0

elif state == 1:         # state 1: heading home
    if bumper == 1:
        stopgoto()
        backward(1)
        goto(dockx, docky)
    elif home < 25:      # arrived
        stopgoto()
        state = 2

else:                    # state 0: cleaning
    wheelleft = 25
    wheelright = 25
    if battery < home / 25 + 22:
        state = 1
        goto(dockx, docky)
    elif front < 55:
        wheelleft = 18
        wheelright = -18
You should see: The same cycle as lesson 3, but now "one state, one block" — read it: each block does exactly one job. Now open the full U19 champion from the robots menu: the same machine, plus the bin mission and a smarter escape.