DOC PREVIEW
Princeton COS 116 - Laboratory 2

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 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 9 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 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

COS 116 The Computational UniverseLaboratory 2: Introduction to PseudocodeDue: Beginning of lecture Tuesday, February 19, 2008.Today you’ll meet Scribbler, the robot we’ll be using in several labs this term. Scribbleris a very capable little machine. It has two independently driven wheels, three statuslights, and a small speaker. It can detect light sources, obstacles in its path, and linesprinted on the “road.” Best of all, the Scribbler can easily be programmed to perform amultitude 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 graspsome important concepts about computation without having to understand a completeprogramming language.In this lab you will learn the building blocks of pseudocode by analyzing and testing aseries of pseudocode files. Then, in two short experiments, you’ll use the robot and theprovided pseudocode to explore the robot’s capabilities. You won’t be writing anypseudocode this week-- that will be the focus of the next week’s lab.At each lab laptop, you should find:• The Scribbler, with 6 AA batteries• A black serial cable• A gray serial-to-USB adapterWe will provide these additional supplies for this lab:• Flashlight• Ruler• Cardstock paper• Tape• Permanent marker• Printout: 1-inch path linePlease return unused materials at the end of the session.Scribbler Software InstallationCOS 116 – Lab 22The course staff has created a simple interface for the Scribbler robot, called the ScribblerControl Program (SCP). SCP was written by a Princeton computer science undergrad.You’ll need to install SCP on the Friend 007 laptops before you can begin this lab. Toinstall SCP, visit http://www.cs.princeton.edu/courses/archive/spring08/cos116/instruct.phpand follow the instructions. If you are installing your Scribbler on your personalcomputer, you’ll find the relevant instructions there as well.General Test ProcedureIn this lab you will test the robot with several pseudocode files. Keep detailed notesabout 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. In the Help menu, selectSample Programs. Select a test file from the list.2. Examine this pseudocode. Write in your notes what you think it will makethe 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 gray serial-to-USB adapter.Attach the adapter to the USB port (on the right) on the Friend 007 laptop.b) Switch the robot on.c) Download the pseudocode to the robot.In the Tools menu, click Download to Robot (equivalently, press F5).• Note: If the program asks for a “COM port”, select “COM 4”.d) Unplug the cable from the robot.e) Place the robot where it will have enough room to run the test. (For sometests, 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 additionalinstructions.h) If the robot is still moving when you are finished with your observations,press the button once more to stop it.COS 116 – Lab 23i) To conserve the batteries, you should turn off the robot if you’re notgoing to use it for a few minutes.4. Did the robot’s behavior differ from what you predicted? If so, figure outwhy and write about it in your notes.Part 1: Basic Motion, Lights, and Sounds1. Test the robot with the file “01 Forward, Back”1 Move Forward for 1s2 Pause 0.5s3 Move Back for 1s4 ENDRemember, you should use the testing procedure described on the previouspage for all the tests in this week’s lab.2. Test the file “02 Spin Left, Spin Right”1 Spin Left for 1s2 Pause 0.5s3 Spin Right for 1s4 END3. Test the file “03 Turn Left, Turn Right”1 Turn Left for 1s2 Pause 0.5s3 Spin Left for 0.7s4 Pause 0.5s5 Turn Right for 1s6 ENDIn your notes, explain the difference between spinning and turning. Hint:Carefully observe the motion of the robot’s wheels while performing a spinand a turn.4. Test the file “04 LEDs”1 LED: ON, OFF, OFF2 Pause 1s3 LED: ON, ON, OFFCOS 116 – Lab 244 Pause 1s5 LED: ON, ON, ON6 Pause 1s7 LED: OFF, OFF, OFF8 ENDNotice that, unlike the motor commands, the LED (“Light Emitting Diode”)commands have a lasting effect on the state of the LEDs.5. Test the file “05 Sound – Scale”1 Play Sound for 0.5s at Frequency 262Hz2 Play Sound for 0.5s at Frequency 294Hz3 Play Sound for 0.5s at Frequency 330Hz4 Play Sound for 0.5s at Frequency 349Hz5 Play Sound for 0.5s at Frequency 392Hz6 Play Sound for 0.5s at Frequency 440Hz7 Play Sound for 0.5s at Frequency 494Hz8 Play Sound for 0.5s at Frequency 523Hz9 ENDPart 2: Sensors and Branches1. Test the file “06 If, Light”1 If <Light from any 1 side> Then2 {3 Play Sound for 1s at Frequency 440Hz4 }5 Else6 {7 LED: ON, ON, ON8 }9 ENDFirst try starting the robot with your hand covering its light sensors, then trystarting it while holding a flashlight close to the sensors. What happens afteryou stop shining light on the sensors? Remember, pseudocode commands areperformed in sequence.2. Test the file “07 If, Obstacle”1 If <Obstacle on Either Side> Then2 {COS 116 – Lab 253 Play Sound for 1s at Frequency 440Hz4 }5 Else6 {7 LED: ON, ON, ON8 }9 ENDFirst start the robot where there is nothing in front of it for several feet. Thenhold your hand about three inches ahead of the robot and try again. Whathappens after you move your hand away?3. Test the file “08 If Not”1 If Not <No Obstacle> Then2 {3 Play Sound for 1s at Frequency 440Hz4 }5 Else6 {7 LED: ON, ON, ON8 }9 ENDCompare this test to the previous one. Are they logically equivalent? Is thereany difference in the robot’s behavior? Can you think of another way toexpress line 1 in the pseudocode from step 1 above?Part 3: Loops1. Test the file “09 Do For n Times”1 Do for 3 Times2 {3 Play Sound for 0.25s at Frequency 392Hz4 }5 Play Sound for 1.5s at Frequency 330Hz6 END2. Test the file “10 Do While”1 Do While <No Obstacle>2 {3 Move Forward for 0.2sCOS 116 – Lab 264 }5 Play Sound for 1s at Frequency 440HzBefore you start the robot, place it at least three feet


View Full Document

Princeton COS 116 - Laboratory 2

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
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 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 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?