Instruction Guide: Repeating Behaviors

In this lesson students explore the use of the loops in NXT-G, including infinite loops, counter controlled loops and sensor controlled loops. Students may have already used infinite loops for earlier challenges (e.g. Flashlight Follower) and perhaps even some controlled loops. The video lesson will, however, walk through these concepts in a logical progression and fill in some gaps in understanding that students may have.

Have students work through the "Repeating Behaviors" lesson on the "Behaviors" page in "NXT Video Trainer 2.0"

Students should be able to answer all the review questions at the end of each step and end up with a solid command of each parameter in the Loop block configuration panel.

As students progress through, have them document their milestones in the Repeating Behaviors Task Assignment Sheet.

This Task Assignment has two teacher sign-offs, here's what to look for in each:

Sensor Controlled Loop

  • This sign-off was added to ensure that students grasp a key limitation of working with loops. In Step 7, students write a program with an ultrasonic sensor controlled loop which stops running laps when it sees an obstacle after a turn. This makes sense to most students since the loop is being controlled by the ultrasonic sensor. However, when the obstacle is placed down the straight-away, or before the turn, the tribot fails to stop. This is unexpected for most students, since they programmed the loop to stop upon "seeing" the obstacle. Key points to check for:

     

    • Ensure the student's tribot does indeed stop for the obstacle after the turn

       

      • Have students explain this behavior through their program
    • Demonstrate that the tribot fails to stop for obstacles down the straight-away or before the turn

       

      • Ask students to explain this
      • The video lesson demonstrates this, but does not directly answer "why" (this is covered in the next unit "Obstacle Detection").
      • It may be helpful to use the animation in Step 8
      • Ensure the students understand that the loop control is only checked at the time the end of the loop is reached
      • So, if time-consuming activities (like move for "x" rotations, or turn "y" degrees) are built inside the loop, the loop control can checked too infrequently and ignore significant events.

         

        • The solution to this problem is the subject of sub-unit 8.1 "Obstacle Detection"

Automated Sentry Challenge

This page contains a copy of this challenge from "NXT Video Trainer 2.0."

  • This challenge has many possible solutions:

     

    • Dead Reckoning:

       

      • Determine Move Block durations for the complete rectangle and loop twice
      • Determine the Move Block durations for the "L" shaped half-rectangle and loop four times
    • Sensor Control:

       

      • If a solid fence and/or building is used, the ultrasound sensor could be used to determine extent of movement, and then loop as required

         

        • 8 times for a segment
        • 4 times for an "L"
        • 2 times for a rectangle
      • If a black line is placed on the ground at each corner, the light sensor could be used to determine extent of movement, and then loop as required
  • Challenge students to write as robust (immune to changes in setup) and efficient (fewest number of blocks) a program as possible.

     

      • Start with their flow char/pseudocodet to get an overall view of the program
      • Use the NXT-G program to show how each block was implemented