Haunted Code Chronicles - Mission 4: The Hallway

Mission 4 Lesson Plan

The Hallway

Students will use line sensor readings to follow a dark line on the floor to reach a doorway.

⏰ 45-90 minutes 🎯 Grades 5-12+ πŸ’» CodeSpace πŸ€– CodeBot 🐍 Python
View Lesson Outline
πŸ“‹

Overview

Mission 4 is a short, focused mission in the dark hallway. Students read a single line sensor and print its value to the console, then pick a threshold and use it in an if statement to stop the 'bot on a stain. From there they read all five sensors at once, work with the tuple that comes back, and build a bang bang controller that follows a dark trail all the way to the door.

🎯 Mission Goal: Students will use line sensor readings to follow a dark line on the floor to reach a doorway.

🎯

Learning Targets

  • I can read the line sensors and return their values.
  • I can print a value to the console.
  • I can use a line sensor reading in a condition to control CodeBot.
πŸ’‘

Key Concepts

  • CodeBot has five line sensors. Each one returns a reading of light reflectivity.
  • All five sensors can be read at the same time and compared to a threshold. A tuple of five Booleans is returned.
  • A tuple is a read-only version of a list. You can use the values but not change them.
βœ…

Assessment Opportunities

  • Complete the Mission 4 Activity Guide.
  • Complete and turn in program HallwayStains after Objective 4.
  • Record the score for the mission, found in the class dashboard.
  • Write a paragraph about their coding experience and what they learned.
β˜‘οΈ

Success Criteria

  • Read a single line sensor and print the value to the Console
  • Determine a threshold value for line sensor readings
  • Use a line sensor reading and threshold in an if statement
  • Read all five line sensors at the same time and return a tuple of five Booleans
  • Use the algorithm for a bang bang controller to guide CodeBot along a dark line to the door
🧰

Classroom Materials

  • β–ΈLaptop/computer with Chrome browser
πŸ”€

Vocabulary

β–Ύ
Line Sensors - Photo reflective sensors that can detect how much light is reflected by the surface the 'bot is on.
Tuple - A list that doesn't change its size. For example: (False, False, True, False, False).
Index - A number, starting with 0, used to access a value in a tuple or list.
Constant - A variable that doesn't change its value during program execution; usually defined in ALL CAPS.
🐍

New Python Code

β–Ύ
val = ls.read(2)Read line sensor #2
print(val)Print the line sensor reading on the console
ls.check(threshold)Check all five line sensors and return a tuple of five Boolean values
if middle:An if statement that uses a Boolean value, returned by the line sensor reading, to select the branch of code.
elif vals[4]:An additional branch for an if statement. The condition for the elif (short for else if) is evaluated, and if true, the code is executed.
πŸ“

Standards

β–Ύ

CSTA Standards - Grades 3-5

1B-CS-02 1B-CS-03 1B-DA-07 1B-AP-09 1B-AP-10 1B-AP-15

CSTA Standards - Grades 6-8

2-CS-02 2-CS-03 2-DA-08 2-AP-10 2-AP-12 2-AP-13

CSTA Standards - Grades 9-10

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

CSTA Standards - Grades 11-12

3B-CS-02 3B-DA-06 3B-AP-10 3B-AP-16
πŸ“
Preparing for the Lesson
  • Go through the Mission in advance, if you can. This is a fairly short mission.

πŸ§‘β€πŸ«
Teacher Notes
  • The mission has two activity guides. They use the same questions, but the alternative guide (alt) gives added support with the questions. Use the one that best fits the needs of your students.
  • Students will do all their coding in one program. The code from the first three objectives will be deleted and replaced with code copied from the instructions for Objective 4. If students want to keep their code from Objectives 1-3, they need to either start a new file for Objective 4 or do a "Save As".
  • Subtle changes are made in their code during Objectives 1-3. Students need to pay attention to CodeTrek to avoid syntax and typing errors.
πŸ—ΊοΈ

Lesson Outline

πŸ§‘β€πŸ€β€πŸ§‘Warm-up

The warm-up has two questions. Have students share their answers as a class discussion or think-pair-share. Objective 1 gives a quick lesson on line sensors. Look it over to see if you need to do any additional front-loading or if the instructions are enough for your students to continue.

Go over the mission introduction to help them understand what will be expected during this mission.

πŸ’»Mission 4 Objectives
Objective #1: This objective gives a short lesson about line sensors. The code is given in CodeTrek, with only one # TODO:. Students should open the Console and observe the readings. The goal should be met with one try. If for some reason the goal isn't met and the 'bot goes past the red stain, just have the student do a reset and run again.
Objective #2: Students will select a value halfway between the floor reading and the spot reading to be the threshold. Then they use the threshold in an if statement to stop the 'bot when it reaches the spot. They just need to follow CodeTrek. A suggestion for the threshold is 3300, but it can be any number that is basically in between their readings.
Objective #3: This objective uses the term tuple. Students only need to know it is a read-only version of a list. If you (or the students) want to know more, click on the tool and add it to your toolbox. CodeTrek guides students in modifying their code. There are subtle changes that students might miss. They need to check each line of code from the current program to what is in CodeTrek. Every time the scene is reset, CodeBot will move its position slightly.
Objective #4: Students are given code for this challenge. They can click on the icon next to the code in the Objective Panel to copy the code, and then paste it in the text editor. The copied code includes imports, so all their previous code can be deleted and replaced with the new code. If students want to keep their previous code, they should do a "File β†’ Save As...". After they copy the code, they still need to follow CodeTrek.
  • Beginning students do not need to read the hints. The copied code and CodeTrek, with slight modifications, will complete the challenge.
  • There are two different configurations for the hallway stain. One scene uses the door on the left, and the other uses the door on the right. Both configurations have a short path and a long path, and the same code should work on both scenes.
  • Students will do a lot of trial and error, which means resetting the scene multiple times. Sometimes the 'bot will be positioned in front of the longer trail. Students can try the longer trail, or do another reset to position the 'bot in front of the shorter trail.
  • The easiest modification to make is to try a slower speed. Experiment with the speed until you find one that keeps the 'bot on the trail.
  • Students who want to try the challenges can read the hints and add more elif statements for more precise turning, and also try the longer trail.
πŸ§‘β€πŸ€β€πŸ§‘Reflection

The reflection questions can be written, shared as a class discussion, or handled through a think-pair-share activity. This is an opportunity to promote a growth mindset.