Turkey Trot: Gobbler Hill

A virtual CodeBot on a line-following course in front of a fan of orange and brown turkey feathers, with the words Turkey Trot: Gobbler Hill.
Free Mission Lesson Plan

Turkey Trot

Students race a virtual CodeBot turkey up a two-ramp hill. Tune a finished program on Race Day, or build the whole thing from scratch.

⏰ 30-90 min 🎯 Grades 6-12 💻 CodeSpace 🤖 Virtual CodeBot 🐍 Python
View Lesson Outline
A virtual CodeBot on a line-following course in front of a fan of orange and brown turkey feathers, with the words Turkey Trot: Gobbler Hill.
📋

Overview

Turkey Trot is a fun Python project for the Thanksgiving season. Students race a virtual CodeBot "turkey" up a two-ramp hill in CodeSpace. No robots are needed, because everything runs on the Sim CodeBot in the Sandbox.

You choose how far to take it (Slide 5). On the Race Day path (about 30 minutes, no coding experience needed), students load the finished program, predict what will happen, and tune SPEED and TURN for the fastest reliable time. On the Build It path (about two class periods), students write the whole program step by step and fix planned bugs using real sensor data. Build It is for students who already know if / else, loops, and functions. Not sure? Choose Race Day.

🎯 Mission Goal: Students will tune a virtual CodeBot turkey to race up a hill as fast as possible. On the Build It path, they also program it to follow a line, count hills, and stop at a timed finish line.

🎬

Project Video

🎯

Learning Targets

Both paths

  • I can read a program and predict what a change will do.
  • I can test and tune a program using data from several runs.

Build It path also

  • I can define and call a function that uses a list and a for loop.
  • I can use a while loop with if / elif / else to make a robot steer.
  • I can collect sensor data and use it to choose a threshold.
  • I can use the accelerometer to detect when a robot is climbing.
  • I can use a counter variable to tell a real event from a brief bump.
  • I can time an event with ticks_ms().
💡

Key Concepts

  • Build It has planned bugs in Step 3 (steering), Step 5 (the turkey falls off the summit), and Step 7 (the hill counter). Let students see each problem and guess why before you show the fix.
  • ls.check() returns a tuple of five True/False values, one for each line sensor. A threshold decides how dark a reading must be to count as the line.
  • The accelerometer senses tilt. Saving the flat reading at the start means students never need to know the raw numbers.
  • The loop runs about 100 times per second, so a counter variable that counts loops can tell a real hill from a brief bump.
  • Keep SPEED + TURN at 100 or less. A motor value over 100 stops the program with an error.
✅

Assessment Opportunities

  • Race Day students predict what a bigger SPEED will do before they run, then compare with their results.
  • Collect the Race Log, where students record three runs for each SPEED and TURN setting they test.
  • Build It students run their program and show the turkey following the line up both ramps and stopping at the finish.
  • Use the Think about it questions after each part as a quick check. Build It students should be able to explain the planned bugs and how they fixed them.
☑️

Success Criteria

  • Read the finished program and predict what a bigger SPEED will do (Race Day)
  • Tune SPEED and TURN, running each setting 3 times, and record the results on the Race Log (both paths)
  • Steer with the line sensors and a threshold that ignores the gray stripes (Build It, Steps 2 to 5)
  • Use the accelerometer to count each hill once (Build It, Steps 6 to 8)
  • Time the race with ticks_ms() and stop at the finish line (Build It, Step 9)
📁

Digital Resources

🧰

Classroom Materials

  • ▸Computer with Chrome or Edge (Chromebooks work)
  • ▸Optional: printed Turkey Trot Race Log for Race Day
🚀

Extensions & Cross-Curricular

ExtensionDNF detector: stop and print DNF if no sensor sees the line for 1.5 seconds. Hint: save ticks_ms() when the line disappears.
ExtensionSmarter turns: right now, if the turkey loses the line it drives straight. Change the else to drive straight only when the middle sensor sees the line, and keep turning otherwise.
ExtensionSplit times: print the time when each hill is climbed.
ExtensionVictory song: change the notes in gobble(), or write a separate finish song.
ExtensionSlowest finisher: find the lowest SPEED that still makes it up the hill.
ExtensionSmoother steering: use all 5 sensors to steer a little or a lot depending on where the line is (proportional control). The Line Follower mission in Python with Robots teaches this.
MathGraph SPEED against race time for the whole class. Where does the curve level off? Where do runs start to fail?
ScienceThe accelerometer measures the pull of gravity. Discuss why the reading changes when CodeBot tilts, and why a faster robot has a harder time turning (momentum).
Social StudiesThe first Turkey Trot was run by the YMCA in Buffalo, New York, in 1896. Have students hunt for the name of the first winner. The YMCA credits Henry A. Allison.
Lang ArtsStudents write a short race report or a how-to guide for tuning a robot.
📐

Standards

▾

CSTA Standards - Grades 6-8

2-CS-02 2-CS-03 2-DA-08 2-AP-11 2-AP-12 2-AP-17

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-12 3A-AP-13 3A-AP-16

CSTA Standards - Grades 11-12

3B-AP-10 3B-AP-21 3B-AP-22

These standards describe the full Build It path. The Race Day path mainly covers testing and refining a program with data from several runs (2-AP-17, 2-DA-08).

📝
Preparing for the Lesson
  • Decide which path your students take (Slide 5). Not sure? Choose Race Day.
  • Download the slides and code files. Run turkey_trot_part2.txt once yourself (about 22 seconds at SPEED 40).
  • Race Day: share turkey_trot_part2.txt with students (a link, your LMS, or a pasted doc). Slide 11 says your teacher will share it.
  • Check that student computers can open make.firialabs.com (Chrome or Edge; Chromebooks work).
  • Students log in (New File and Save As stay gray until they do) and keep just one CodeSpace tab open. A free CodeSpace account works. No license needed.
  • Optional: print or share the Turkey Trot Race Log for Part 3.

🧑‍🏫
Teacher Notes
  • The instructions for this project are not in the interactive textbook in CodeSpace. The slides are the student directions.
  • Build It: students write every line of code themselves. The code images on the slides have line numbers and highlight the new lines, so students can see exactly what to add and where it goes. When lines must be deleted or changed, the slide lists them in a red box.
  • Race Day: students paste the finished program and only change numbers. SPEED is on line 4 and TURN is on line 5 of turkey_trot_part2.txt. Slide 11 tells students to find them near the top of the file.
  • The bugs in Step 3, Step 5, and Step 7 are planned. Let students see the problem and talk about why it happens before moving on. Debugging is the main skill in this project.
  • The Step 3 bug does not look the same every run. Some runs zigzag and leave the ramp early, and others go well and only fail at the left turn at the top. Have students run it three or four times (RESET each time) before moving on to Step 4.
  • Some steps say "Try it first." Give students a few minutes to write the code before you show the next slide.
  • Almost all errors are typing mistakes. Check spelling, capital letters, colons, and especially indenting. The editor copies the indent of the line above but does not add one after a colon. Students press Tab to indent and Shift+Tab to move back.
  • Stop before you edit. While a program is running, the editor and the File menu ignore typing and clicks, with no message. The square Stop button ends the run. This matters most in Step 3 and Step 5 (the loop never ends on its own), and on Race Day when a turkey crashes and the program keeps running.
  • Students must press RESET before every run, and wait about 2 seconds before clicking Run. If a run looks strange, RESET and run again.
  • Set the camera to Chase (the camera menu at the bottom of the 3D view). Otherwise the camera stays put and the turkey can drive out of the picture.
  • Keep the CodeSpace tab on screen during a race. Hidden tabs make the simulation run in slow motion. The race time stays accurate because it uses CodeBot's own clock.
  • This project works individually or with pair programming.
🗺️

Lesson Outline

This outline gives one way to present the lesson. The Race Day path fits in one class period: Warm-up, Choose a Path, Getting Started, Load the Finished Program, then Part 3 Race Day. The Build It path takes about two periods. On Day 1, do the warm-up, Getting Started, and Part 1. If students run long, stop after Step 3 or Step 4 and finish Part 1 on Day 2. On Day 2, review, then do Part 2 and Part 3 Race Day. The wrap-up fits only if the class is moving quickly.

🗣️Warm-up

Slides 1-4: Ask whether anyone has run or watched a Turkey Trot. The history slide includes an optional fun fact hunt for early finishers. The answer is in Extensions & Cross-Curricular above. Slide 2 also mentions that line-following robots are real (robotics competitions, warehouses).

🧭Choose a Path (Slide 5)

Tell students which path they are on. Race Day (no coding experience needed): load the finished program, read it, and tune it. Build It (the challenge): write the whole program step by step. Slide 5 says Build It is for students who already know if / else, loops, and functions. If you are not sure, choose Race Day. Everyone does Getting Started first.

💻Getting Started (Slides 6-10)

💻 Students log in, open the Sandbox, choose Sim CodeBot, and switch the environment from Sumo Garden to Line-follow 101. Three things trip people up:

  • Log in first. New File and Save As stay grayed out until students log in (Slides 6 and 9 say so). A free CodeSpace account works. No license needed.
  • Sandbox first. Choosing Sim CodeBot fails with "Cannot Change Target Device" until the student clicks the Sandbox icon on the right side bar, near the bottom (Slides 6 and 7). The same icon leaves the Sandbox, so click it once.
  • Sumo Garden and the camera. The most common setup mistake is staying in Sumo Garden. Choose Line-follow 101. Slide 8 also tells students to set the camera to Chase so it follows the turkey.

Slide 9 explains that Build It students add to this one program in every step, and Race Day students paste one finished program into it. On Slide 10, point out the Run, console, and RESET buttons.

Teaching tip: Slide 10 does not show the square Stop button yet, so show students that one yourself. Slides 11 and 45 remind students to click it after a crash.
🏁Race Day Path - Load the Finished Program (Slide 11)

Students open turkey_trot_part2.txt (you share it), copy all of it, and paste it into their TurkeyTrot file. They find SPEED and TURN, predict what a bigger SPEED will do, find the line that prints FINISH!, then press RESET and Run. The slide then sends them to Part 3 on Slide 44.

Predictions to listen for: a bigger SPEED should finish sooner, but the turkey may lose the line or crash. The FINISH! line prints a message with the race time in seconds, about 22 at SPEED 40. If a turkey crashes, students must click Stop before they can change SPEED or TURN.

💻Build It, Part 1 - Follow the Line (Slides 12-29)

💻 Slides 13-15, Step 1: Students gobble. They use imports, a function, a list, and a for loop. If there is no sound, check that the computer's sound is on and that spkr.off() is not indented inside the loop. Slide 13 reminds students: Tab indents, Shift+Tab moves back.

💻 Slides 16-18, Step 2: Students add a SPEED constant and drive forward for 3 seconds. The prediction question sets up Step 3.

💻 Slides 19-22, Step 3 (planned bug): Slide 19 explains that ls.check() returns a tuple of five True/False values, one per sensor. Slide 20 describes the steering as a bang-bang controller: CodeBot bangs back and forth between left and right turns. Give students time to write the if / elif / else themselves ("Try it first"). When they run it, the turkey often zigzags and runs off the course, but not on every run, so have them try three or four times. The loop never ends, so students click Stop before they edit. Ask: do the sensor lights only light up on the black line?

💻 Slides 23-25, Step 4: Students save TurkeyTrot, start a new file, and run a short sensor test. In our test the black line read 4095, plain white about 286, and the gray stripes about 1200 to 2700. Have a few students share their numbers. Ask what single number separates the stripes from the line. If the console looks empty, scroll down. It does not always jump to the newest line.

💻 Slides 26-28, Step 5: Students add THRESHOLD = 3000 and use ls.check(THRESHOLD). The turkey now follows the line up both ramps, then stops at the summit wall, or tumbles off, because it does not know the race is over.

Teaching tip: Slide 29 has the Part 1 Think about it questions. This is a stopping point. Students should save TurkeyTrot, and turkey_trot_part1.txt matches the program at this point.
  • Why did the steering fail? The default setting counts fairly dark readings as the line, and the stripes are dark enough, so the outside sensors kept "seeing" the line and steered the wrong way.
  • How does the threshold fix it? The data showed the stripes stay below about 2700 while the line reads 4095, so any threshold in between, like 3000, separates them.
  • Why does the turkey fall off the summit? Nothing in the program tells it the race is over. It keeps driving after the line ends at the top.
💻Build It, Part 2 - Find the Finish Line (Slides 30-43)

💻 Slides 31-33, Step 6: accel.read() returns a tuple of three numbers (x, y, z), and accel.read()[1] picks out y, the direction CodeBot's nose points. On flat ground it reads about 5660, about 1300 on the first ramp, and about -600 on the steeper second ramp. Slide 32 explains why flat is not zero: CodeBot's nose points slightly down. Saving flat at the start means students do not need to know these numbers. The user LEDs show when CodeBot is climbing.

💻 Slides 34-36, Step 7 (planned bug): Ask for predictions first. The loop runs about 100 times per second, so it adds 1 every time through the loop while climbing. In our test it printed over 190 hills before the turkey fell off the summit.

💻 Slides 37-39, Step 8: The Step 7 bug becomes the fix. The climb variable counts loops while CodeBot is tilted. When CodeBot levels out, a climb longer than 50 loops (about half a second) counts as a hill, and climb resets to 0. This also ignores the jolt when the motors start, which at SPEED 60 and up tilts CodeBot for a split second and would otherwise count as a hill. Students move the counting lines inside the else:. Watch for indenting errors here.

💻 Slides 40-42, Step 9: Students import ticks_ms and ticks_diff, save start after the motors turn on, and stop when hills == 2. At SPEED 40 the finish time is about 22 seconds. The time comes from the simulator's clock, so it is the same on fast and slow computers.

Teaching tip: Slide 43 has the Part 2 Think about it questions. This is a stopping point, and turkey_trot_part2.txt is the finished program.
  • How does the program know it reached the summit? The accelerometer senses tilt. Climbing tips the nose up and the reading drops. After the second climb levels out, the program knows it is on the summit.
  • Why did the counter reach hundreds, and how was it fixed? The loop runs about 100 times per second, so every pass while tilted added 1. Now climb counts the loops, and the hill is counted once, when CodeBot levels out, and only if the climb lasted more than 50 loops.
  • Why must start be saved only once? It must be saved once, when the race begins. Inside the loop it would reset every time, and the time would always be close to zero.
🏁Part 3 - Race Day (Slides 44-47, Both Paths)

Students change one setting at a time, press RESET, and run each setting 3 times, recording results on the Race Log. Remind them to keep SPEED + TURN at 100 or less. A motor value over 100 stops the program with an error. If a turkey crashes, students click Stop before they change a number.

About the challenges (Slide 46). Bronze is finishing, Silver is under 18 seconds, Gold is under 15, and Legend is beating 14. Gold and Legend are within reach just by raising SPEED. If you want them to reward careful tuning, make the targets tougher (for example, under 12 seconds).

💻 Slide 47 has the Race Day Think about it questions. Sample answers:

  • What happened when SPEED got too high, and why? Too fast and the turkey cannot turn quickly enough to stay on the line, or it goes off the ramp. Also, at high speed it moves farther between sensor checks.
  • Did the same settings always give the same time? No. The simulation varies a little from run to run, especially at high speeds. Good testing means running each setting several times.
  • What would you change to make your turkey even faster? Answers vary: a higher SPEED with the right TURN, or smoother steering that uses all 5 sensors.
🚀Extensions (Slides 49-50)

Hints are on the slide. Full solutions are not given, so students can apply what they learned. See Extensions & Cross-Curricular above for the full list. Slide 51 is the closing slide.

🧑‍🤝‍🧑Wrap-Up (Slide 48)

Slide 48, "What's inside your racer," lists what the program uses: line sensors and a threshold, a bang-bang controller, the accelerometer, counters, and CodeBot's clock. Race Day students read all of these in the code even though they did not write them, so ask them to find each one in the program. Post the leaderboard. Ask: which settings were fast and reliable? Build It students: what was the hardest bug to find, and how did you find it?

🔧
Troubleshooting
  • Choosing Sim CodeBot says "Cannot Change Target Device": click the Sandbox icon on the right side bar, near the bottom, first. Clicking it again leaves the Sandbox.
  • "You are already running the CodeSpace Simulation Environment in another window or tab": close every other CodeSpace tab or window on this computer, then reload. CodeSpace runs in one tab at a time.
  • Nothing happens when Run is clicked: check that the bottom left says Sim CodeBot is connected. If not, choose Sim CodeBot again. Right after RESET, wait about 2 seconds, then click Run.
  • Typing does nothing, or New File and Save As are grayed out: log in (New File and Save As stay gray without it). If a program is still running, click the square Stop button. The editor and File menu are locked while it runs.
  • The turkey drives out of the picture: open the camera menu at the bottom of the 3D view and choose Chase.
  • The turkey is in the wrong place or a run looks strange: press RESET, then Run again. RESET is needed before every run.
  • The course looks different, or nothing works: the environment is probably still Sumo Garden. Choose Line-follow 101.
  • A red error appears: usually a typo. Check spelling, capital letters, a missing colon, or indenting. Tab indents and Shift+Tab moves back. Compare with the code image line by line.
  • Error after changing SPEED or TURN: SPEED + TURN is over 100. Motor values must be between -100 and 100.
  • The race looks like slow motion: the tab was hidden or the computer is busy. Keep the tab on screen. The time is still accurate.
  • Nothing prints: open the console with the button at the very bottom right, then scroll down to the newest lines.
💬

Share Your Results

Join the conversation in the Firia Labs Code Collective to share how your students did!

Back to blog