For a teacher with a class? The classroom edition has the full plan, slides and standards.

Homeschooling PDF

Family edition

Tunnel Boring Lab: A Boulder in the Way, Events

Ages 14-16 ยท about 45 minutes, in one sitting

In Tunnel Boring Lab your child programs a tunnel boring machine. In this level a boulder hides in the clay ahead, and the program has to notice it the moment it is hit.

What you need

Before you start: try it once yourself

Open mytekdev.com/try/tunnelboringlab?lesson=a-boulder-in-the-way-events&ref=fam-tunnelboringlab-4. A short guide opens over Level 10, A boulder. The street is drawn cut open along the tunnel's line like a diagram: the buildings and the road on top, then topsoil, sand, clay and granite. The machine is under the street, boring from the launch shaft on the left. The box at the top says what the level wants and what is happening; the guidance screen is the round dial.

  1. The starter. Push 50 on every side, 3 turns a minute, a stroke and a ring 20 times; the level ends at 12 rings. The boulder is in the clay a little below the line, about 12 m from the shaft, and first touches the cutterhead partway through stroke 7.
  2. The rule. On the stone, more than 2 turns a minute, or more than 160 kN on each cutter, chips the cutters after 30 seconds. At a push of 50 each cutter is pressed with 135 kN in clay, so the push is safe and the turns are the problem.
  3. The event. Blocks: when a boulder is hit, turn the cutterhead at 2 turns a minute. Python shows it as def on_boulder(): with tbm.spin(2) inside, and tbm.on("boulder", on_boulder). It runs the moment the cutterhead touches the stone, in the middle of the stroke, then the main program carries on where it was.
  4. Speed. A drive is many hours of the machine's own time. Speed up, twice, runs it at 6 times faster, 22 minutes of the drive a second, so most runs take under a minute. Play always puts the machine back in the shaft and runs the program as it is now.
  5. Numbers to expect. The starter at 3: chipped in stroke 7. 2.5 the whole way: chipped. 2 the whole way: passes, 17.8 hours. An if before each stroke that turns at 2 if the ground at the face is "boulder": chipped. The event alone: 15.8 hours. The event, and an if in the repeat that turns back to 3 when the ground is not "boulder": 14.9 hours. The event with the push at 70: chipped, 258 kN a cutter.
The if for speeding back up uses ground at the face (Guidance), a compare block set to not equal, and a text block with boulder in it. Build it once before you start so you can show it on the board.

The ideas, in plain words

Most of a program runs in order, top to bottom. An event-driven program also says what to do when something happens, and the system calls that code the moment it does, wherever the main program is. Web pages work this way (a click handler), and so do games and phones. The other way to find out is polling: check again and again at set times. Polling is simple, but it only sees what is true when it looks.

Here the main program checks between strokes, and a stroke takes about 40 minutes of the drive's time. The boulder arrives partway through one, so a check before the stroke sees clay, and the next check is far too late. The handler runs on the hit itself.

Boulders are a real hazard for soft-ground machines. Disc cutters are built to roll on rock, but a sudden hard stone in soft clay hits them with a shock. Real operators watch the torque for the same jump and slow the cutterhead and lighten the push until the stone is through.

Do it together

  1. Open mytekdev.com/try/tunnelboringlab?lesson=a-boulder-in-the-way-events&ref=fam-tunnelboringlab-4 together and press play, then Speed up twice.

    You'll know it worked when: The cutters chip on the boulder in stroke 7.

  2. Open Blocks. From Events drag out when a boulder is hit, and put turn the cutterhead at 2 turns a minute under it. Go back to Simulator and press play.

    If you get stuck: If it still chips, check the turn block is under the when block, not inside the repeat.

    You'll know it worked when: Green: 12 rings in 15.8 hours.

  3. Take the when block away, change the 3 in the first turn block to 2, and press play.

    You'll know it worked when: It passes too, in 17.8 hours: two hours slower.

  4. Open the Python tab with the event put back, and find def on_boulder and tbm.on.

    You'll know it worked when: The function is the handler; tbm.on tells the machine to call it when a boulder is hit.

Talk about it

Ask these while you work together. A child who has understood it can answer them without help:

The fourth question is the one that matters. A child who says "the boulder came in the middle of the stroke, after the check" understands timing. A child who says "the if was wrong" has not seen that the if was right when it ran.

For younger and older kids

Younger: For a younger child, stop after the first green result and talk about alarms: a smoke alarm is an event.

Older: For an older child, add an if inside the repeat that turns back to 3 when the ground is not "boulder", and find out how many hours it saves.

Keep going

Bring it into other subjects

For your records

Ready to copy into an hour log, a portfolio or a transcript.

LessonTunnel Boring Lab: A Boulder in the Way, Events
SubjectsComputer science, Engineering
Time45 minutes
What we didWrote an event handler for a simulated tunnel boring machine that reacts the moment it hits a boulder, and compared it with checking between steps on the same drive.
Skills practicedEvents; Timing in programs; Comparing programs

Tunnel Boring Lab: A Boulder in the Way, Events

Activity sheet (optional)

Name: ______________________________ Date: ______________

Open the app: scan the QR code, or go to mytekdev.com/try/tunnelboringlab?lesson=a-boulder-in-the-way-events

Essential question: How can a program react to something the moment it happens?

Warm-up: Does your phone check for messages, or get told? Which is better, and why? ________________________

  1. Vocabulary. Event, event handler, polling, torque, boulder, test case: write each in your own words.
  2. The starter. At 3 turns a minute the cutters ____ in stroke ____ .
  3. My table. Program / hours or what went wrong. 2 the whole way: ____. A check before each stroke: ____. The event: ____. The event and back to 3: ____.
  4. The Python. The two lines that make the event: ______________________________

1. Which program would you run on a real drive, and why?

2. Why did the check before each stroke come too late?

Quick check

Name: ______________________________

1. In tbm.on("boulder", on_boulder), the handler is: (A) "boulder" (B) on_boulder (C) tbm

2. Checking the ground before each stroke is an example of: (A) an event (B) polling (C) a handler

3. A friend says an event is no better than an if, since both check for the boulder. Use what you learned today to answer them.

Answers

QuestionAnswerWhy
1BThe function the machine calls when the event happens.
2BIt checks at set times and sees only what is true when it looks.
3Open answerThe if only checks before the stroke, and the stone arrives in the middle of it, so the cutters chip. The event runs the moment the boulder is hit.

If your state or umbrella school asks, this lesson covers CSTA 2017 3A-AP-16, NGSS HS-ETS1-4.