CS81 Lab1: Scribbler Robot

Due by noon next Friday

In this lab you will use a real robot in the physical world. You will directly program the robot to do specific tasks, such as finding its way out of a maze. This lab my be done alone or with a partner of your choice.

Git started

We will be using git as a repository for your code for the class. If this is your first time using git, you may want to read a little more about git and its commands. Go through the following steps to setup your directory for this lab.

  1. First you need to run setup81 to create a git repository for the lab.

    If you want to work alone do:

    setup81 labs/01 none
    If you want to work with a partner, then one of you needs to run the following while the other one waits until it finishes.
    setup81 labs/01 partnerUsername
    Once the script finishes, the other partner should run it on their account.

  2. For the next step only one partner should copy over the starting point code.
    cd ~/cs81/labs/01
    cp -r ~meeden/public/cs81/labs/01/* ./
    This will copy over two files called draw.py and escape.py.

  3. Whether you are working alone or with a partner, you should now add all of the files to your git repo, commit, and push them as shown below.
    git add *
    git commit -m "lab1 start"
    git push

  4. If you are working with a partner, your partner can now pull the changes in.
    cd ~/cs81/labs/01
    git pull

Scribbler robot and the Fluke

The Scribbler robot base has the following capabilities:

The robot has an attachment called the Fluke which provides additional capabilities:

Try to locate all of the sensors on the Scribbler and the Fluke.

Connecting to the Scribbler robot

In order to use your robot you'll need to do the following:

  1. Turn on the robot. Notice what number robot you are using.
  2. Type the following where NUM is replaced with the number of your robot.
    >>> from myro import *
    >>> init("/dev/rfcommNUM")

The init command attempts to establish a bluetooth connection between the computer you are logged into and your particular robot. You may need to repeat this command several times before a successful connection is made. You can press the UpArrow key to re-enter previous commands within the Python interpreter.

If you are unable to connect, then check for the following problems:

After a successful connection you will see a message like this (the name may be different) and your robot will emit a series of beeps:

You are using fluke firmware 2.9.1
You are using scribbler firmware 1.0.2
Hello, I'm Scribby!

The Scribbler robot uses 6 AA batteries, and only works well when it has enough power. The first command you should run each time you begin using the robot is to check its current battery level:

>>> getBattery()
If the battery level is below 6.2, replace the batteries. Put the old batteries into the small green battery recycling bin.

Controlling the Scribbler robot interactively

The Scribbler is controlled through a python library called Myro. Read through the Myro reference manual trying the commands interactively in the python interpreter as you go. Not all of the commands will work as described.

For example, the speak command turns a string into spoken words that will be output through the computer's speakers, not from the robot. Some computers do not have speakers so you will not hear anything. Some computers do have speakers, but the volume control is set very low.

Focus your attention on the commands that move the robot and read the sensors.

Escaping from a maze

After you've tried all of the Myro commands interactively in python, explore the obstacle detection sensors available to you in more detail. You'll need these sensors in order to program the robot to escape from a maze. There are IR sensors on both the scribbler and the fluke. Which ones work more reliably to detect obstacles? Feel free to grab an extra wooden block and bring it back to your desk to more easily test the robot. Read about the setIRPower command in the Myro reference manual. You may need to tweak the power setting of the Fluke's IR sensors in order to get reasonable values for obstacle detection.

Edit the program escape.py in your current lab directory. Using Myro commands, write a program that will cause the robot to find its way out of a maze like the one that is set up at the front of the lab. You have a number of options of how to accomplish this:

Once your robot can successfully escape, move on to the next section. Remember to use git to add, commit, and push the file you have changed.

git add escape.py
git commit -m "put some message here"
git push

Drawing with the Scribbler

One of the challenging aspects of using physical robots in the real world is that their movements are not always reliable. We will test the reliability of the Scribbler by drawing geometric figures.

Get a big piece of white paper. Insert a pen into the Scribbler's pen port and put it on top of the paper. As the Scribbler moves it will draw a line.

  1. Issue a command to make the robot move forward at full speed for one second. Stop the robot. Then issue a command to move backward at full speed for 1 second. Pick up the robot and look at the pen marks. Does the robot traverse the same trajectory? Does it travel the same distance in both directions? Measure the length of the line drawn by the robot when moving for one second. In the file draw.py in your current lab directory, write a function called travel(distance) to make the robot travel the given distance. You may use inches or centimeters as your units. Test the robot a few times to see how accurate the line is.

  2. Study the turning behavior of your robot. Based on your observations write a function called degreeTurn(degrees) that will make the robot turn the specified degrees.

  3. Using the functions travel and degreeTurn write a function called square(size) to draw a square. Save the paper for a good square drawn by your robot.

  4. Using the same functions write a function called star(size) to draw a five-point star as shown below. Save the paper for a good star drawn by your robot.

  5. Suppose you would like to create a vacuuming robot. The robot is given the dimensions of a rectangular area and must travel through the entire area as efficiently as possible. Write a function called vacuum(length, width) that uses your travel and degreeTurn functions to traverse the entire area. You can test your program by using the white paper (which is 4ft wide) with a pen in the Scribbler to see how well the robot covers the area. Save the paper for a good vacuuming path executed by your robot.

Once you have gotten some good drawings made by your robot, use git to add, commit, and push the file you have changed.

git add draw.py
git commit -m "put some message here"
git push


When you are completely done, be sure that you have pushed all of your changes to the repo. Use the status command as shown below, to verify this. If there are uncommitted changes, be sure to do another add, commit, and push cycle.

git status
Also write your name(s) on the saved drawings made by your robot, and turn them into me.