Computer Science 101: Lab #1

There will be no code to submit for this lab, just a PDF of the writeup of your answers to the questions highlighted in red. After naming your PDF document appropriately (mine would be lab1_levy.pdf), email it to me as an attachment.

Part 1: Trying out your Scribbler 2 robot

Read over pages 4 – 7 of the Scribbler 2 (S2) Robot Startup Guide. Then try some of the demos on pages 8 – 22.

Question 1.1: Why do you think there are eight demos? How many demos could there be with two light sensors? With four? In general, how many demos can there be with N light sensors?

Question 1.2: Write down the little four-character code on the white label on the front of your robot’s Fluke board. Now do the same for the codes on the Fluke boards being used by the other students in the class. What is the largest digit in the codes, and what is the last character you find (alphabetically)? Write down all the numbers in order, followed by the letters, filling in any gaps. How many characters (letters and numbers) are there total? Type the list you just created into Google. What does the answer to this question have to do with the answer to the previous question? Why do computers use this many digits (characters) to represent numbers, whereas human beings use ten? What does this have to do with the term digit?

Part 2: Mac OS X Under the Hood

Our robots are going to interact with our Mac computers in an interesting way. Before we connectour Macs to our robots, do the following:

  1. Click on any open area in the background of your Mac desktop so that the Finder menu appears.
  2. Click on the Go menu and select Computer. Make a note of the folders that you see inside the Hard Drive.
  3. Click on the Go menu again, but this time select Utilities. Then double-click on Terminal.app. This will open a terminal windowinto which you can type commands to the Mac’s operating system.
  4. In the terminal window, type (or better yet, copy-and-paste)   ls /     (letter el, letter ess, space, forward-slash, return).
  5. Question 2.1. How does the result of this command compare with what you saw in the Hard Drive? Is there some spelling convention being followed (capitalization, length of name)? Google on the name of some of the three-letter items along with the keyword directory; e.g., google on bin directory or dev directory. What is the common pattern in the hits you get?
  6. In the terminal window, type (copy-and-paste)   ls /dev/tty.*   and make a note of what you see.

Part 3: Connecting the Mac to the Fluke via Bluetooth

We will do this together. Once you’ve made the Bluetooth connection to your Fluke board, repeat the final step (ls /dev/tty.*) from the previous section, and compare the new results with what you noted down.

Question 2.2 How do the results of the two listing differ? How does the new listing relate to the connection that we just made?

Part 4: Programming the Scribbler 2 with Calico / Python

Python is the language that we will learn and use in this course, and Calico is an Integrated Development Environment (IDE) for Python; i.e., an app that allows us to create, edit, and run programs in Python. Go to page 8 of the textbook and follow the directions in the section labeled 1. Start Calico. The textbook assumes you are using a Windows computer, so there will be some details that you will have to change for the Mac:

  • Instead of typing initialize("comX"), we will type initialize("/dev/tty.X"), where X is whatever we named our Bluetooth connection to the Fluke in the setup phase. For example, I typed initialize("/dev/tty.Fluke2-0407-Fluke2") for my robot.
  • It’s difficult to get a gamepad working with Calico on the Mac, so instead of the gamepad() command, we’ll use the joystick()command, which gives us a virtual joystick for controlling the Scribbler.

Pro tip #1: Once you’ve typed something into the Calico shell (command area), you should use the up-arrow and down-arrow keys in Calico to retrieve it. Likewise, when you are given something to type, don’t actually type it yourself; just copy it from the instructions and paste it into the area where you’re supposed to type it. I’ll be happy to show you how to do this if you’re not sure. But please don’t let me see you re-entering commands the long way.1

Pro tip #2: You probably already know that when you run into a serious problem on your computer, the fastest way to get back to work is often to reboot (restart) it. The same goes for working with your robot using Calico: if you keep getting errors (complaints from Calico in red text), it’s probably easiest just to quit Calico, re-launch it, and up-arrow to repeat the commands you wanted.

Our one-command-at-a-time interaction with our robot is obviously too limited to be of much use. In next week’s lab we will learn how to define sequences of commands to do more interesting things. In the meantime, you can string together commands in a sequence by separating them with commas; e.g., forward(1,1), beep(1,440), backward(1,1). See if you can come up with an interesting program (sequences of commands), to make your robot do a little dance or other clever activity. You may find the Myro Command Referencehelpful. Once you’re satisfied with what your robot is doing, give a demo to me so you can receive full credit on this lab.

1to paraphase Truman Capote: that’s not programming; that’s typing.