1
FREE VIRTUAL CODEBOT MISSION
Turkey Trot: Gobbler Hill
Code your virtual CodeBot to race up a hill
2
THANKSGIVING
What's a Turkey Trot?
3
DID YOU KNOW?
The first Turkey Trot was in 1896
On Thanksgiving Day, the YMCA in Buffalo, New York, held a race of about 5 miles on dirt roads. It still runs every year, and it is older than the Boston Marathon.
1896
First race in Buffalo
6
Runners started
4
Runners finished
FUN FACT HUNT (OPTIONAL)
Who won the very first Turkey Trot? See if you can find out!
4
THE MISSION
For this project you will:
5
CHOOSE YOUR PATH
Two ways to race
Race Day path
Build It path
Your teacher will tell you which path to take. Everyone starts with Getting Started.
6
GETTING STARTED
Log in and open the Sandbox
7
GETTING STARTED
Choose the virtual CodeBot
8
GETTING STARTED
Choose the race course
9
GETTING STARTED
Start your program
10
GETTING STARTED
Three buttons you will use a lot
Run
The green button above the code.
Console
The button at the bottom right. Your program's messages show up here.
RESET
Puts your turkey back at the start line. Press it before every run!
11
RACE DAY PATH
Race Day path: load the finished program
12
TURKEY TROT
Part 1: Follow the line
Get your turkey up the hill.
13
PART 1
Step 1: Warm up with a gobble
14
PART 1
Step 1: Warm up with a gobble
Your code could look like this:
New and changed lines are highlighted.
A list holds several values in square brackets. The for loop takes the notes one at a time.
15
PART 1
Step 1: Test your code
TEST YOUR CODE
16
PART 1
Step 2: Trot forward
17
PART 1
Step 2: Trot forward
Add the highlighted lines:
New and changed lines are highlighted. The numbers on the left are line numbers.
18
PART 1
Step 2: Test your code
TEST YOUR CODE
19
PART 1
Step 3: Meet the line sensors
Front of CodeBot
the line
0
False
1
False
2
True
3
False
4
False
left
right
vals = (False, False, True, False, False)
20
PART 1
Step 3: Steer to stay on the line
Try it first: write this yourself before you look at the next slide!
21
PART 1
Step 3: Steer to stay on the line
Your code could look like this:
New and changed lines are highlighted. The numbers on the left are line numbers.
Also add:
Line 5: TURN = 15
Delete or change these lines:
motors.run(LEFT, SPEED)
motors.run(RIGHT, SPEED)
sleep(3)
motors.enable(False)
22
PART 1
Step 3: Test your code
TEST YOUR CODE (WATCH CLOSELY!)
23
PART 1
Step 4: Be a sensor detective
24
PART 1
Step 4: Be a sensor detective
Your sensor test could look like this:
New and changed lines are highlighted.
25
PART 1
Step 4: Read the data
TEST YOUR CODE
26
PART 1
Step 5: Use a threshold
27
PART 1
Step 5: Use a threshold
Add the highlighted lines:
New and changed lines are highlighted. The numbers on the left are line numbers.
Delete or change these lines:
vals = ls.check()
28
PART 1
Step 5: Test your code
TEST YOUR CODE (WATCH CLOSELY!)
29
PART 1
Part 1: Think about it
You can stop here, or continue to Part 2 to give your turkey a finish line.
30
TURKEY TROT
Part 2: Find the finish line
Teach your turkey to know when it reaches the top.
31
PART 2
Step 6: Feel the hill
32
PART 2
Step 6: Feel the hill
Add the highlighted lines:
New and changed lines are highlighted. The numbers on the left are line numbers.
Why isn't flat zero? CodeBot's nose points slightly down, even on flat ground. So gravity pulls a little along y, and flat reads about 5660.
33
PART 2
Step 6: Test your code
TEST YOUR CODE
34
PART 2
Step 7: Count the hills
35
PART 2
Step 7: Count the hills
Add the highlighted lines:
New and changed lines are highlighted. The numbers on the left are line numbers.
Also add:
Line 17: hills = 0
Delete or change these lines:
print("Flat ground:", flat)
# Feel the hill
36
PART 2
Step 7: Test your code
TEST YOUR CODE (WATCH CLOSELY!)
37
PART 2
Step 8: Count each hill only once
Try it first: write this yourself before you look at the next slide!
38
PART 2
Step 8: Count each hill only once
Your code could look like this:
New and changed lines are highlighted.
Also add:
Line 18: climb = 0
Delete or change these lines:
hills = hills + 1
print("Hill", hills, "climbed!")
39
PART 2
Step 8: Test your code
TEST YOUR CODE
40
PART 2
Step 9: The finish line
41
PART 2
Step 9: The finish line
Add the highlighted lines:
New and changed lines are highlighted.
Also add:
Line 2: from time import sleep, ticks_ms, ticks_diff
Line 22: start = ticks_ms()
Delete or change these lines:
from time import sleep
42
PART 2
Step 9: Test your code
TEST YOUR CODE
43
PART 2
Part 2: Think about it
You can stop here, or continue to Part 3 for Race Day.
44
TURKEY TROT
Part 3: Race Day!
How fast can your turkey trot?
45
PART 3
Tune your turkey
46
PART 3
Race challenges
Bronze
Finish the race.
Silver
Under 18 seconds.
Gold
Under 15 seconds.
Legend
Can you beat 14 seconds?
Add your best time, SPEED, and TURN to the class leaderboard!
47
PART 3
Think about it
48
WRAP-UP
What's inside your racer
49
TURKEY TROT
Extensions
Add even more to your Turkey Trot.
50
EXTENSIONS
Extensions
51
Nice job, turkey trotter!
Your turkey trotted all the way to the top of Gobbler Hill.
Happy Thanksgiving from Firia Labs!