Project+104

Project #104 - Keep on Going (Loops & Sensors)

media type="custom" key="8219422"


 * The NXT will back up and turn when it hits a wall. **

Objectives:

When you complete this lesson, you should understand the following:

How to implement a while loop. How to test a Sensor’s Value in the conditional part of a while statement. How to make an infinite loop. How to structure “Nested” loops.

Procedures:

Please review the following videos before you begin the task:

Touch vs. Timing Configuring Sensors The While Loop Putting it Together

This project will introduce you to the touch sensor. When the sensor is "touched" it will send out a "1", otherwise it sends out a "0". You will continually read the sensor using a "while" loop. You will have the robot go forward until the sensor is touched. The robot will then backup and turn 90 degrees and continue going until the sensor is touched. The robot will continue doing this forever (or until the battery runs down). This will require a second while loop that has its parameter always set to true. A loop inside of a loop is called "Nested" looping. I feel a need to work in a lame bird joke but I will contain myself. Good Luck!

<span style="font-family: 'Comic Sans MS',cursive; font-size: 16px; line-height: 19px;">The code below is an example of how to write a loop that will keep your robot going in circles :)

<span style="color: #002bff; display: block; font-family: 'Arial Black',Gadget,sans-serif; font-size: 16px; line-height: 23px; text-align: left;">while (true) <span style="color: #002bff; display: block; font-family: 'Arial Black',Gadget,sans-serif; font-size: 16px; line-height: 23px; text-align: left;">{ <span style="color: #002bff; display: block; font-family: 'Arial Black',Gadget,sans-serif; font-size: 16px; line-height: 23px; text-align: left;">motor[motorB]=0; <span style="color: #002bff; display: block; font-family: 'Arial Black',Gadget,sans-serif; font-size: 16px; line-height: 23px; text-align: left;">motor[motorC]=50; <span style="color: #002bff; display: block; font-family: 'Arial Black',Gadget,sans-serif; font-size: 16px; line-height: 23px; text-align: left;">}

<span style="color: #0000ff; font-family: 'Comic Sans MS',cursive; font-size: 20px; margin: 0px; padding: 0px;">Enrichment: <span style="font-family: 'Comic Sans MS',cursive; font-size: 16px; margin: 0px; padding: 0px;">When you have mastered the touch sensor, then I chanllenge you to try using the **ultra sonic sensor.** This sensor makes your robot appear to have eyes. Watch the video called **Sonic Sojourn** and then implement this project using the ultra sonic sensor. The robot should back up when it is within 15 cm of the table railing.

<span style="color: #0000ff; font-family: 'Comic Sans MS',cursive; font-size: 20px;">Evaluation: <span style="font-family: 'Comic Sans MS',cursive; font-size: 16px;">You can evaluate your work using the following three-point rubric:

<span style="font-family: 'Comic Sans MS',cursive; font-size: 16px;">**Three points**: You were able to work successfully together and demonstrated proficient understanding of how to attach and configure a touch sensor. You were able to complete an adequate solution to the problem using **nested** looping. The behavior of the robot successfully completed the Loops and Sensors project.

<span style="font-family: 'Comic Sans MS',cursive; font-size: 16px;">**Two points:** You were able to work together and discuss the problems that they encountered. You attempted to implement looping into their program and demonstrated some understanding of the concept. The behavior of the robot partially completed the Loops and Sensors project.

<span style="font-family: 'Comic Sans MS',cursive; font-size: 16px;">**One point:** You worked poorly together and minimal understanding was demonstrated as to how to implement a loop into a program or configure a touch sensor. The robot behavior demonstrated very little of the correct solution.

** Good Luck and Have ﻿FUN! **