Mission 5-4: Fence Patrol - PwR MS

 

Mission 5-4 Lesson Plan

Fence Patrol Lesson 4: Stay in the Lines

Students write functions to move CodeBot and use line sensor data to keep it inside a boundary.

⏰ 30-45 min 🎯 Grades 6-8 💻 CodeSpace 🥇 CodeBot 🐍 Python
View Lesson Outline
📋

Overview

In this final lesson of Mission 5, students bring everything together to create a working Fence Patrol program. They write functions to move CodeBot forward and backward, then use line sensor data to call those functions and keep the 'bot inside a boundary. Students test with a rectangular boundary and can explore other shapes as time allows.

🎯 Mission Goal: Students will create a program that reads line sensors and uses that data to move CodeBot within a boundary. 

🎯

Learning Targets


  • I can define a function that moves the 'bot.

  • I can call a function that moves the 'bot at the appropriate time and place.

  • I can program the 'bot to stay inside a boundary.
💡

Key Concepts


  • Autonomous robots use sensor data to make decisions and take action in their environment.

  • Functions can be written for 'bot movement as well as reading sensors - movement functions do not return a value.

  • Algorithms can be developed as a plan first, then translated into code step by step.

Assessment Opportunities

☑️

Success Criteria

  • Define and call a function that moves the 'bot forward
  • Define and call a function that moves the 'bot backward and then turns
  • Program the 'bot to move inside a boundary line
🧰

Classroom Materials

  • CodeBot
  • USB cable
  • 4 AA batteries per CodeBot
  • White posterboard with black electrical tape boundary (rectangle to start - try other shapes too!)
🌍

Real-World Applications

🏭Automatic Guided Vehicles (AGVs) use similar code to navigate warehouse distribution centers and get packages to customers.
🌎Robots explore underground mines, clean up environmental waste, and discover shipwrecks - places too dangerous for humans.
🚗Self-driving vehicles use sensor data and boundary detection to stay in lanes on roads.
🚀

Extensions & Cross-Curricular

ExtensionBlink an LED while waiting for the BTN-0 press, or play a tone when line_count is incremented.
ExtensionAdd BTN-1 to stop the program. Or use random numbers for speed, sleep time, or beep pitch.
ExtensionProgram BTN-0 to test for a black line on a white surface and BTN-1 for a white line on a dark surface.
Physical ScienceRun experiments with different speeds and thresholds. Collect data, create a chart or graph, make predictions, and test them.
ArtAttach a pen or marker to the 'bot and have it draw a graphic on paper as it stays within the lines.
Lang ArtsHave students write a poem about programming, functions and abstraction, or robots. Supports reading instructions, guided notes, and reflection writing.
🔤

Vocabulary

Algorithm - (Review) A list of step-by-step instructions the computer can follow to complete a task.
🐍

New Python Code

def go_forward():
  motors.run(LEFT, 45)
  motors.run(RIGHT, 45)
Define a movement function. Creates a reusable function that moves CodeBot forward.
else:
  go_forward()
Call a movement function. Calls go_forward() when the 'bot is not detecting a line.
📐

Standards

CSTA Standards - Grades 6-8

2-AP-10 2-AP-11 2-AP-12 2-AP-13 2-AP-14 2-AP-16 2-AP-17 2-AP-19
📝
Preparing for the Lesson

  • 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 students will answer. There are a couple of tables to fill out. Prepare the assignment to give through your LMS.

  • Have posterboard with boundaries ready for students to use for testing. Make sure you have charged batteries for the CodeBots.

  • If you have a word wall, or another form of vocabulary presentation, prepare the new terms.

🧑‍🏫
Teacher Notes

  • The slides replace the instructions in CodeSpace. Code will be similar to CodeTrek but slightly different - all goals will be met.

  • This lesson isn't very long. Depending on testing and debugging time, students can use extra time for extensions or cross-curricular activities.

  • The simplest boundary is a rectangle on posterboard with black electrical tape (both available at the dollar store). After initial testing, try different shapes and even a white line on a dark surface.

  • The Mission 5 Kahoot! reviews all Mission 5 objectives - not just Objective 9.
🗺️

Lesson Outline

💡Lesson Tips and Tricks
Teaching tip: You can use a variety of discussion strategies to get the most engagement from your students. For example, you can have students write their answers before asking anyone for an answer. You can use one of many think-pair-share methods. You can have students write their answer and share with someone, and then have other students share answers they heard from their peers. You can randomly select students to answer.
🗣️Warm-up / Hook

Slide 2 - Students can write in their log first and then share, or discuss first and then write. These questions review movement and turning code. Students can reference Mission 3 NavSquare or Mission 4 Animatronics if they need a refresher.

  • Question: What code will move the 'bot forward?
  • Question: What code will move the 'bot backward?
  • Question: What code will turn the 'bot?
💻Mission 5 Lesson 4 Activities

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.

Teaching tip: Mission Introduction - slides 3-5. This mission is divided into four lessons. The fourth lesson focuses only on the final goal.
Teaching tip: Objective 9 - slides 6-10. This objective reviews moving forward, backward, and turning. Students can reference previous code. Slide 7 shows the algorithm for the Fence Patrol project. You can optionally have students develop the algorithm first before revealing the four steps.
Teaching tip: Objective 9 Part 1 Activity - slides 11-12. Students open their LineSense project and add a go_forward() function near the top with the other functions.
Teaching tip: Objective 9 Part 2 Activity - slides 13-16. Students add a backup-and-turn function. Consider having students develop it on their own before showing slide 15. Students should test this function before moving on (slide 16).
Teaching tip: Objective 9 Part 3 Activity - slides 17-20. Students complete the objective by calling both functions, then test and adjust speed or sleep time as needed. Try a basic rectangle first, then other boundary shapes. Students should have a working program to turn in by the end.

🗝️ Optional: Mission 5 Kahoot! Review. The review Kahoot! covers all Mission 5 objectives.

🧑‍🤝‍🧑Post-Mission Reflection

The post-mission reflection asks students to think about functions and how they are useful in programming. This is a good topic for class discussion.

You can use an extension or cross-curricular activity as a post-mission activity.

End by collecting the Mission 5 Lesson 4 Log.