VR - Mission 13: Going the Distance!
Going the Distance!
Students use wheel encoders to calculate distance and speed, then write functions to drive CodeBot an exact distance, turn a precise angle, and maintain a set speed.
Overview
In this mission, students get to know CodeBot's wheel encoders: discs with slots that let an IR beam pulse through as the wheel turns. Students count those pulses to calculate distance and speed, then put the math to work, writing a drive() function that moves CodeBot an exact distance, a rotate() function that turns it a precise angle, a speed function with "cruise control" to hold a steady pace, and finally an arc() function that reads both encoders at once to drive a curve at a given speed.
π― Mission Goal: Students will use wheel encoders to make CodeBot move exact distances and angles.
Learning Targets
- I can get to know the wheel encoders.
- I can calculate speed in cm/sec.
- I can create a function to move CodeBot an exact distance using the wheel encoders.
- I can write a function to rotate CodeBot using the wheel encoders.
- I can write a function that calculates the speed of the 'bot from wheel encoder data.
- I can write a function that enables the 'bot to maintain a speed.
- I can write a function that reads both wheel encoders and uses the data to move in an arc at a given speed.
Key Concepts
- Each wheel encoder consists of a disc with slots that allow IR light to pass through. Counting the light-dark and dark-light intervals tracks distance exactly.
- Knowing the distance lets the 'bot move precisely a given distance at a given speed.
- The encoders can also be used to calculate a turning angle.
- Using lists for the data helps manage the information for both wheels.
- The time library has built-in functions that can be used to track time.
- Data from the wheel encoders can be used to maintain a given speed.
Assessment Opportunities
- Quiz after Objective 3
- Quiz after Objective 6
- Quiz after Objective 10
- Code Tracing Chart as a debugging tool
- Use the Debugger to track variables and lists
- Give students code snippets from an objective and have them explain what it does
- Give extra practice with math calculations for distance
-
Submit the
encoder_check.pyprogram -
Submit the
enc_drive.pyprogram -
Submit final
enc_speed.pyprogram - Mission 13 Review Kahoot!
Success Criteria
- Write code to create a bar chart visualization for wheel encoder data.
-
Define a
drive()function to move CodeBot an exact distance, based on the counts of the wheel encoder. -
Define a
rotate()function that turns the 'bot a specified angle, based on wheel encoder data. - Calculate the speed of CodeBot and display the data in a bar chart visualization.
- Write "cruise control" code to maintain a set speed over any terrain.
-
Define an
arc()function to drive the 'bot around a free throw ring.
Digital Resources
- βΈLevel-1 Mission 13 Assignment
- βΈLevel-1 Mission 13 Assignment Answers
- βΈLevel-1 Mission 13 Review Questions
- βΈCode Tracing Chart
- βΈLevel-1 Mission 13 Review Kahoot!
- βΈMission 13 Obj 2
- βΈMission 13 Obj 4
- βΈMission 13 Obj 5
- βΈMission 13 Obj 6
- βΈMission 13 Obj 8
- βΈMission 13 Obj 10
- βΈMission 13 Final Code Solution
Classroom Materials
- βΈComputer or Chromebook with internet access
Real-World Applications
Extensions & Cross-Curricular
π€
Vocabulary
βΎ
π
New Python Code
βΎ
!= is the "not equals" comparison operator.
// operator).
π
Standards
βΎ
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
Certiport IT Specialist: Python Standards
PCEP: Certified Entry-Level Python Programmer
- This mission is math-heavy: wheel circumference, counts-per-revolution, and distance/angle/speed calculations. Review integer division and consider working a few example problems on paper before starting.
- Encoder behavior varies 'bot to 'bot and track to track, so the distance, angle, and speed values in CodeTrek are starting points. Expect some trial and error to hit the goals, especially for Objectives 8, 11, and 12.
- Preview the objective walkthrough videos (Obj 2, 4, 5, 6, 8, and 10) so you can point students to the right one when they get stuck.
-
Plan checkpoints for the three program submissions:
encoder_check.py,enc_drive.py, and the finalenc_speed.py.
- For Objective 8, the number given in CodeTrek for the distance is a starting point. It will need to be changed to meet the goal.
-
For Objective 11, remember to change the arguments for
drive_speed(). The values given in CodeTrek will not meet the goal. -
For Objective 12, the global designation is only needed in the
init_drive_state()function. Lists are global and can be updated anywhere. The function needs the global designation because the lists originate there and cannot be local. - You may need to adjust values to meet the goal. Slower speeds work better.
- There is a lot of information given in this lesson. Take your time with each objective and review the concepts frequently.
- There is a lot of math in this lesson. Review important concepts as needed, and maybe even do some practice problems on paper.
Lesson Outline
Ask students how a car's odometer or speedometer "knows" how far or how fast it's traveled without measuring the road directly. Introduce wheel encoders as the sensor that makes this possible, and connect it to the mission: CodeBot has to use its own wheel encoders to go the exact distance, and at the exact speed, it's told.
- Read raw encoder values, use a Boolean threshold to detect a slot, and build a bar chart visualization of the encoder counts.
- Reference Mission 13 Obj 2 as needed.
-
Have students submit their
encoder_check.pyprogram as an early check that the encoders are working. - Administer the Quiz after Objective 3.
- Calculate the wheel circumference, convert counts to distance (and distance to counts), and calculate speed in cm/sec.
- Reference Mission 13 Obj 4, Obj 5, and Obj 6 as needed.
- Administer the Quiz after Objective 6.
-
Define a
drive()function that moves CodeBot an exact distance, based on wheel encoder counts. - Reference Mission 13 Obj 8 as needed.
-
Define a
rotate()function that turns CodeBot a specified angle, using wheel encoder data and a positive/negative direction. - Reference Mission 13 Obj 10 as needed.
-
Have students submit their
enc_drive.pyprogram, combiningdrive()androtate(). - Administer the Quiz after Objective 10.
- Write a "cruise control" function using a feedback loop to maintain a set speed over any terrain.
-
Define an
arc()function that reads both wheel encoders and uses the data to drive the 'bot around a free throw ring at a given speed. -
Have students submit their final
enc_speed.pyprogram.
drive_speed() - the CodeTrek values won't meet the goal as given. For Objective 12, the global designation is only needed inside init_drive_state(), since that's where the lists originate. Slower speeds tend to work better.
Close with the Level-1 Mission 13 Review Kahoot! to reinforce wheel encoder distance, angle, and speed calculations before moving on to the Unit 5 Remix & Assessment.