Mission 6-2 Lesson Plan | Python with Robots MS
Mission 6-2 Lesson Plan
Line Follower Lesson 2: ls.check() and Logical Operators
Students will create a line follower that uses two sensors for turning and three sensors for moving forward.
⏰ 40-45 min
🎯 Grades 6-8
💻 CodeSpace
🤖 CodeBot
🐍 Python
📋
Overview
Mission 6-2 builds on the line-following code from Lesson 1. Students replace the check_lines() function with the faster botcore function ls.check(), learn about tuples, and use logical operators to build a more reliable line follower. By the end of the lesson, students have a working two-sensor turning / three-sensor forward-moving program.
🎯 Mission Goal: Students will create a line follower that uses two sensors for turning and three sensors for moving forward.
🎯
Learning Targets
-
I can call the
ls.check()function to use the ADC hardware channel scanning feature. - I can use an item in a tuple as a condition.
- I can use logic operators to increase the reliability of the 'bot.
💡
Key Concepts
- The line follower 'bot will need to continuously check for the presence of a line beneath all five sensors.
- A list and a tuple are similar, but different. A list is mutable, or can change, and a tuple is immutable, or cannot be modified.
- Pre-coded functions from the botcore library can use the ADC hardware, making your program even faster!
✅
Assessment Opportunities
- Mission 6 Lesson 2 Log (digital)
- Submit completed program LineFollow (through Obj. 6)
- Mission 6 Obj. 4-6 Review Kahoot!
☑️
Success Criteria
-
Call the
ls.check()pre-coded function -
Use an item from the
valstuple as a condition - Turn if an outside sensor detects a line
- Use the logical operator "or" to check multiple conditions
- Move forward if a line is detected
📁
Digital Resources
📚
Classroom Materials
- ▸CodeBot
- ▸USB cable
- ▸4 AA batteries
- ▸A track for the 'bot to follow - white poster board with a black line made from electrical tape works great
🌎
Real-World Applications
🤖Self-driving cars, autonomous flying drones, and other computing systems that navigate on their own share basic principles with CodeBot. Whether writing code for a vehicle with a high-powered vision processing system or for CodeBot's low-power sensors, you will face many of the same challenges to stay on the path. Robots that zip through warehouse distribution centers often follow lines as they pick up and pack items ordered online.
🚀
Extensions & Cross-Curricular
ExtensionAdd code for pressing BTN-1 to stop the program.
ExtensionAdd a sound when the 'bot turns left, another when it turns right, and a different sound (or silence) when no line is detected.
ScienceLook up the schematics for the CodeBot. Find the ADC and study the electronics chart to learn more about analog-to-digital conversion.
MathCompare line sensor readings for
check_lines() and ls.check() using different shades of gray and surfaces. Create a table from the data, then make a graph.
Lang ArtsSupports language arts through reading instructions, guided notes, and reflection writing.
🔤
Vocabulary
▾
Review
int - A value that is an integer; designated by
int in Python; can be positive or negative.
float - A value that is a decimal, also known as a floating point; can be positive or negative.
New
Tuple - Read-only form of list.
Immutable - Unable to be changed.
Logical operators - And, or, and not - operators that allow for multiple conditions in a comparison. Logical operators handle combinations of Boolean results.
Or - Allows for multiple conditions where only one must be true for the entire comparison to be true.
🐍
New Python Code
▾
vals = ls.check(thresh, is_reflective)Botcore line sensor function - faster than
check_lines(). thresh is the threshold for detecting a line. Pass False for a black line, True for a white line. Returns a tuple of bools. Example: vals = ls.check(2000, False)
ls.check(0)Returns the line sensor readings when entered directly in the Console Panel.
elif vals[1] or vals[2] or vals[3]:Uses the logical operator "or" for multiple conditions. If any one condit