DOC PREVIEW
Princeton COS 116 - Laboratory 2: Introduction to Pseudocode

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

COS 116 The Computational Universe Laboratory 2: Introduction to Pseudocode Today you’ll meet Scribbler, the robot we’ll be using in several labs this term. Scribbler is a very capable little machine. It has two independently driven wheels, three status lights, and a small speaker. It can detect light sources, obstacles in its path, and lines on printed on the “road.” Best of all, the Scribbler can easily be programmed to perform a multitude of tasks. For this class, we’ve created a way to control the Scribbler using simple “pseudocode” instructions. These statements resemble English commands, and they’ll help you grasp some important concepts about computation without having to understand a complete programming language. In this lab you will learn the building blocks of pseudocode by analyzing and testing a series of pseudocode files. Then, in two short experiments, you’ll use the robot and provided pseudocode to explore the robot’s capabilities. This week you won’t be writing any pseudocode, but that will be the focus of the next lab. Your TA will issue you the following items: x The Scribbler (in box, together with a black serial cable) x 6 AA batteries x A blue USB-Serial adapter and software CD These are yours to keep and experiment with until the end of the semester. Please take good care of them! We’ll send email with instructions for installing the Scribbler software on your PC. We will provide these additional supplies for this lab: x Flashlight x Ruler x Construction paper x Tape Please pick them up at the beginning of the session.COS 116 – Lab 2 2 General Test Procedure In this lab you will test the robot with several pseudocode files. Keep detailed notes about each test and hand in them when you finish. Follow this procedure for each test: 1. Use Scribbler Control Panel to open the test file. 2. Examine this pseudocode. Write in your notes what you think it will make the robot do. 3. Load the file on to the robot and observe the robot’s behavior. a) Attach your robot to the computer. Use the black cable to attach the robot to the blue USB adapter (don’t tighten the thumb screws), then plug the USB adapter into the computer. b) Switch the robot on. c) Download the pseudocode to the robot. In the Tools menu, click Download to Robot. d) Unplug the cable from the robot. e) Place the robot where it will have enough room to run the test. (For some tests, you will need to use the floor.) f) Press the robot’s button twice (rapidly) to start it. g) Observe the robot’s behavior. Some tests will provide additional instructions. h) If the robot is still moving when you are finished with your observations, press the button once more to stop it. i) To conserve the batteries, you should turn off the robot if you’re not going to use it for a few minutes. 4. Did the robot’s behavior differ from what you predicted? If so, figure out why and write about it in your notes.COS 116 – Lab 2 3 Part 1: Basic Motion, Lights, and Sounds 1. Test the robot with the file “01 Forward, Back” 1 Move Forward for 1s 2 Pause 0.5s 3 Move Back for 1s 4 END Remember, you should use the testing procedure described on the previous page for all the tests in this week’s lab. 2. Test the file “02 Spin Left, Spin Right” 1 Spin Left for 1s 2 Pause 0.5s 3 Spin Right for 1s 4 END 3. Test the file “03 Turn Left, Turn Right” 1 Turn Left for 1s 2 Pause 0.5s 3 Spin Left for 0.7s 4 Pause 0.5s 5 Turn Right for 1s 6 END In your notes, explain the difference between spinning and turning. Hint: Carefully observe the motion of the robot’s wheels while performing a spin and a turn. 4. Test the file “04 LEDs” 1 LED: ON, OFF, OFF 2 Pause 1s 3 LED: ON, ON, OFF 4 Pause 1s 5 LED: ON, ON, ON 6 Pause 1s 7 LED: OFF, OFF, OFF 8 END Notice that, unlike the motor commands, the LED (“Light Emitting Diode”) commands have a lasting effect on the state of the LEDs.COS 116 – Lab 2 4 5. Test the file “05 Sound – Scale” 1 Play Sound for 0.5s at Frequency 262Hz 2 Play Sound for 0.5s at Frequency 294Hz 3 Play Sound for 0.5s at Frequency 330Hz 4 Play Sound for 0.5s at Frequency 349Hz 5 Play Sound for 0.5s at Frequency 392Hz 6 Play Sound for 0.5s at Frequency 440Hz 7 Play Sound for 0.5s at Frequency 494Hz 8 Play Sound for 0.5s at Frequency 523Hz 9 END Part 2: Sensors and Branches 1. Test the file “06 If, Light” 1 If <Light from any 1 side> Then 2 { 3 Play Sound for 1s at Frequency 440Hz 4 } 5 Else 6 { 7 LED: ON, ON, ON 8 } 9 END First try starting the robot with your hand covering its light sensors, then try starting it while holding a flashlight close to the sensors. What happens after you stop shining light on the sensors? Remember, pseudocode commands are performed in sequence. 2. Test the file “07 If, Obstacle” 1 If <Obstacle on Either Side> Then 2 { 3 Play Sound for 1s at Frequency 440Hz 4 } 5 Else 6 { 7 LED: ON, ON, ON 8 } 9 ENDCOS 116 – Lab 2 5 First start the robot where there is nothing in front of it for several feet. Then hold your hand about three inches ahead of the robot and try again. What happens after you move your hand away? 3. Test the file “08 If Not” 1 If Not <No Obstacle> Then 2 { 3 Play Sound for 1s at Frequency 440Hz 4 } 5 Else 6 { 7 LED: ON, ON, ON 8 } 9 END Compare this test to the previous one. Are they logically equivalent? Is there any difference in the robot’s behavior? Can you think of another way to express line 1 in the pseudocode from step 1 above? Part 3: Loops 1. Test the file “09 Do For n Times” 1 Do for 3 Times 2 { 3 Play Sound for 0.25s at Frequency 392Hz 4 } 5 Play Sound for 1.5s at Frequency 330Hz 6 END 2. Test the file “10 Do While” 1 Do While <No Obstacle> 2 { 3 Move Forward for 0.2s 4 } 5 Play Sound for 1s at Frequency 440Hz Before you start the robot, place it at least three feet away from an obstacle (your bag, the wall, etc.). Allow the robot to move forward until it encounters the obstacle. When do you hear the sound?COS 116 – Lab 2 6 3. Test the file “11 Do Forever” 1 Do forever 2 { 3 If <Obstacle on Either Side> Then 4 { 5 Play Sound for 1s at Frequency 440Hz 6 } 7 Else 8 { 9 Move Forward for 0.2s 10 } 11 } 12 END


View Full Document

Princeton COS 116 - Laboratory 2: Introduction to Pseudocode

Documents in this Course
Lecture 5

Lecture 5

15 pages

lecture 7

lecture 7

22 pages

Lecture

Lecture

32 pages

Lecture

Lecture

16 pages

Midterm

Midterm

2 pages

Lecture

Lecture

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

24 pages

Lecture

Lecture

22 pages

Lecture

Lecture

28 pages

Lecture

Lecture

21 pages

Lecture

Lecture

50 pages

Lecture

Lecture

19 pages

Lecture

Lecture

28 pages

Lecture

Lecture

32 pages

Lecture

Lecture

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

19 pages

Lecture

Lecture

22 pages

Lecture

Lecture

21 pages

Logic

Logic

20 pages

Lab 7

Lab 7

9 pages

Lecture

Lecture

25 pages

Lecture 2

Lecture 2

25 pages

lecture 8

lecture 8

19 pages

Midterm

Midterm

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

29 pages

Lecture

Lecture

40 pages

Lecture 3

Lecture 3

37 pages

lecture 3

lecture 3

23 pages

lecture 3

lecture 3

20 pages

Lecture

Lecture

21 pages

Lecture

Lecture

24 pages

Lecture

Lecture

19 pages

Load more
Download Laboratory 2: Introduction to Pseudocode
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Laboratory 2: Introduction to Pseudocode and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Laboratory 2: Introduction to Pseudocode 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?