Mission 6-2: Line Follower - PwR MS
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.
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
Extensions & Cross-Curricular
check_lines() and ls.check() using different shades of gray and surfaces. Create a table from the data, then make a graph.
π€
Vocabulary
βΎ
int in Python; can be positive or negative.
π
New Python Code
βΎ
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)
π
Standards
βΎ
CSTA Standards β Grades 6β8
- Decide what materials you want to use for presenting the lesson. The slides can be projected on a large screen.
- Be familiar with the mission log assignment and the questions they will answer. Prepare the assignment to give through your LMS.
- Have the Test Surfaces paper available for each student or programming pair. They will also want a small black paper to act as a line. This can be a piece of black electrical tape on a piece of white paper.
- Students will need paths for their 'bot to follow. You can make paths on your floor, or use white posterboard with black electrical tape for the line. You will want a variety of paths so the students can test their code.
- If you have a word wall, or another form of vocabulary presentation, prepare the new terms.
- The examples given in the slides are more inline with variables and examples from Mission 5.
- The code used in the slides is similar to CodeTrek, but a little different. It keeps consistent variables and sections of code. All goals will be met.
- Slides go into a lot more detail about tuples, giving more examples.
- Students will need lines for their 'bots to follow. You can get white posterboard from Dollar Tree and black electrical tape. Give the posterboard and tape to the students to make their own paths. You want a variety of paths for testing.
Lesson Outline
The warm-up questions review lists and using bools to turn on/off LEDs. Students can share their answers, or compare with each other.
- Question: Complete the tables for lists and LEDs.
The Chrome browser works best, but other browsers also support CodeSpace. Each student will complete a Mission Log. Students could work in pairs through the lesson, or they can work individually.
check_lines().ls.check() is introduced. It will replace the check_lines() function moving forward.ls.check() in the Console Panel to see the results. Students will do this two different ways: ls.check(0) and ls.check(). They record the results in their mission log. Students will use the Test Surfaces document and a small black piece of paper. The second part of the activity is to start a new file called "LineFollow". The code on the slide is basically the same as CodeTrek. Test the program with the 'bot on the white rectangle and use the small black piece of paper. The LEDs should turn on when the black paper is underneath the line sensors.ποΈ Optional: Mission 6 Obj 4-6 Kahoot! Review. A review Kahoot! is available for these three objectives.
The post-mission reflection asks students to review the new ls.check() function. This question is a good one for small group or whole class discussion.
You can use an extension or cross-curricular activity as post-mission activity.
End by collecting the Mission 6 Lesson 2 Log.