Exercise 1. Experiment with Sensors and Motors

Total Page:16

File Type:pdf, Size:1020Kb

Exercise 1. Experiment with Sensors and Motors

Exercises

Exercise 1. Experiment with sensors and motors

Do this with your partner. Examine your NXT kit and identify the parts. Check them off as you find them:

____The CPU (brick) ____Motors (3) ____Light sensor ____Touch (bump) sensors (2) ____Ultrasonic sensor ____Sound sensor ____Connector cables

Test the various motors and sensors. Start at page 4 of the “Mindstorms Education 9797” manual and connect the sensors as shown. (Only connect one motor, and connect that to the B motor port.) Because we are using the rechargeable battery pack and since that is already in place, ignore page 5.

Pages 6 and 7 lead through the sensor testing exercise.

1. Press the center orange button, called ENTER, once. 2. To turn off the brick, press the dark grey rectangular button underneath, which is called the ESCAPE button, once. 3. The menu on the LCD says Turn Off? Press the ENTER button once to turn off. 4. Turn on the brick again. 5. Press the RIGHT button twice. That is the light-gray triangular button to the right of ENTER. 6. Now you see View on the screen. Press ENTER to select that. 7. We will experiment with the sound sensor first. Press ENTER to select the sound test. 8. Since the sound sensor is connected to port 2, press the RIGHT button once until you see Port 2 on the LCD. 9. Press ENTER. 10. Now the LCD has a percentage on it, which is the intensity of the sound incoming. Try shouting at the sound sensor, which is a very simple microphone. 11. When done with this test, press ESCAPE. 12. Press the RIGHT arrow to do the other tests. 13. One test that is interesting is Rotation. Select the Motor degrees menu option that shows as a gear with a tiny D to the right. 14. Press the RIGHT button once to tell it Port B because that is where your motor is plugged in. 15. Gently turn the orange wheel on the motor and observe the numbers. What happens when you go backwards? What happens when you complete more than 1 revolution? 16. When done, turn the brick off.

1 Exercise 2. Write algorithms

2a. Here is a an “algorithm” that you might often find on shampoo bottles. Discuss any problems with it.

Lather. Rinse. Repeat.

2b. Imagine that you want to visit an old friend in Denver. She gave you written directions to her house and you are now in your car on the outskirts of the city, having successfully made it as far as I-25. Write a general algorithm that captures the thinking and processing that has to occur when anybody uses directions to find something. Write down a skeleton of your algorithm.

2 2c. Go back to your directions-following algorithm and identify anyplace you used the four basic control structures:

sequence -- do the next step

decision -- depending on a condition that you assess, go to one of several sequences

loop -- repeat the sequence of steps

subalgorithm -- use a subsequence as if it were an elementary step

3 Exercise 3. Walk a Maze with the help of NXT’s Ultrasonic sensor

Do this with your partner or a small group of 3 or 4. This activity will give you a taste of the limitations a robot faces when attempting to negotiate obstacles. In your group, one individual will be the resident “robot.” He or she will have the task of navigating a maze with his/her eyes closed. The only aid will be an NXT configured to act as a sonar range finder. (If you are the robot and need to open your eyes for any reason, please feel free to do for your safety. If you are not the robot, please make sure the “robot” doesn’t bump into anything and get hurt. Thank you.)

3a. From within your group select one person to enter the maze. This person will close their eyes and attempt to successfully navigate the maze with only the aid of the sonar range finder. Observe them as they attempt to exit the maze. Think about the answers to the following questions:  What strategies do they employ?  How do they decide in which direction to turn?  Are they just randomly moving around, or does there appear to be some method involved?

3b. Select another member from your group. This time, instead of relying on human intuition, develop an algorithm for the maze walker to follow. Write this algorithm down on a piece of paper. What will they do when they start to come close to a wall – turn left? Right? Stop? Pretend you are programming a robot which will follow your algorithm exactly as you write it.

3c. Now have your maze walker enter the maze and attempt to navigate it (closing their eyes once again) by following the steps in your algorithm. Assist the maze walker by calling out the appropriate action as defined in your algorithm. Do they successfully exit the maze? If not, what problems do they run into?

4 Exercise 4. Get started with the NXT-G programming system

Do these with your partner.

4a. Getting started with “Hello World” program.

1. Start NXT-G on your computer after booting it up. 2. Plug in your USB cable to both the computer and the robot. 3. Check on the status of the robot using the NXT button. 4. Write a simple program that prints out “Hello World” on the brick. 5. Download and run the program.

4b. Turn on motors program.

1. Create a program that turns on the connected motor. 2. After 20 seconds, turn off the motor. 3. Turn the connected motor on in reverse. 4. After 10 seconds turn it off.

4c. Loops and sensors.

1. Construct a loop. 2. Every time the bump sensor is pressed, it plays a sound. 3. Download and get to run.

4d. Enter a complex program.

1. Follow along in entering the ultrasonic distance display.

5 Exercise 5. Build the basic roverbot

Do this with your partner.

Follow the instructions in the “Mindstorms Education 9797” booklet. On p. 2, you see the end-result, except we will not build the arm at the left;

Start on p. 8 and progress through each page in step. Ask for help if you get stuck. Compare parts in your kit against the booklet’s pictures. They are almost exact in size and color.

When you reach p. 23, enter the simple on-brick program that is indicated to test the brick. (Don’t worry about the little person on p. 23.)

Continue building on p. 24. You can skip the test program on p. 27, 31, 35, 39 and 45. Stop building when you’ve completed p. 44.

6 Exercise 6. Program the Roverbot (Part 1)

Enter and download the programs as the presenter displays and discusses them.

6a. A program to show how to count bump sensor touches and display. Program: Concept_Vars.rbt

6b. A program that gets input from the ultrasonic sensor and goes backward if it senses an obstacle. Program: Concept_Decision.rbt

6c. A program that spins in a circle until it detects a loud and then it stops, plays a sound file, goes forward, and then stops and starts over. It does this 3 times. Program: Concept_Loop.rbt

6d. Download Concept_Subalgorithm.rbt (already on your computer’s desktop), run it and listen to explanation of MyBlocks (which are NXT-G’s subalgorithms) and threads. Also study how pseudo-code matches the visual program. Program: Concept_Subalgorithm.rbt

7 Exercise 7. Program the Roverbot (Part 2)

Do these with your partner using the NXT roverbot you built and your computer.

7a. Write an NXT-G program incorporating a for loop. The algorithm is:

Go Forward for 2 seconds. Stop. Say “Goodbye” four times (using a loop, not four separate sound blocks!) End program.

7b. Create a MyBlock (subAlgorithm) out of the “Goodbye” loop created in Part a. To do this, follow these steps:

1. Select the Goodbye loop and its content. 2. From the menu select Edit ---> Make A New My Block 3. Name this MyBlock GoodbyeX4. You can also write a short description if you wish. 4. Click Next 5. Drag an icon from the palette onto the white box at the top of the Icon Builder screen. You can resize the icon by clicking and dragging one of the black boxes which are at the four corners of the icon border. 6. Click Finish

You will now see the MyBlock GoodbyeX4 where your loop used to be. Also if you select the Custom Palette (a blue equals sign found towards the bottom of the left hand side of the NXT-G window) and hover your mouse over the My Blocks button, you will find your new My Block in the list. You can now drag this My Block into any program you create in the future, and it will act just like the loop you created.

7c. Create a program that uses the above MyBlock. Your program should turn on the motors so the bot goes forward for 3 seconds. Then it should stop, turn around (by turning on one motor forward and the other backwards), stop, and invoke the GoodbyeX4 block.

8 Exercise 8. Write NXT-G programs for the competition challenge

Do this with your partner using the NXT roverbot you built and your computer.

The competition challenge is where you can write a fairly non-trivial NXT-G program for your robot and you can do it however you like. We will not have an official “contest” but you can imagine that this is a programming contest with robots that your students would participate in. Tomorrow, you will have a chance to show what you have accomplished to everyone else, if you like, and to reflect on problems or triumphs you encountered.

There are three challenges in order of difficulty:

1. Drag racer -- your roverbot has to start at a black line and go as fast as it can to the second black line and stop. The idea is that the bot stops between the second and third lines. It can’t overshoot the third line after it stops.

2. Maze ‘scaper -- your roverbot has to get out of our wooden maze in 4 minutes.

3. Sumo wrestler -- your roverbot has to stay inside the round ring but push outside the ring your opponent bot. For you to win, the opponent must be entirely outside the ring. However, you cannot competely leave the ring in order to be considered the winner.

8a. Because a little bit of planning can cut short a lot of unproductive tinkering, sketch out the algorithms you could use for each of the above. You could do all three at once, or simply write the drag racer first, then get it to work. Next plan the ‘scaper and then get it to run and so on. Keep in mind that your pseudo- code fit the NXT with its sensors and motors and dimensions, not a real person who might be attempting to escape a maze or wrestle! Don’t worry too much about which NXT-G function blocks you’ll need.

8b. Actually write the NXT-G program and download. For the SUMO wrestler, we will provide a non-competitive roverbot that will merely try to stay in the ring if it is pushed out.

9

Recommended publications