Lab 08 - Turtle Robots


Lorna Mitchell

Pre-Lab

  • Pseudo-code One approach to coding is to start your sketch by writing comments. In comments, describe what you're trying to accomplish, and then write more comments: a new comment for each step you'll use to accomplish it.

    After you've written the comments, add the code to accomplish each step after the comment about that step.

    It helps to organize your pseudo-code in program blocks and with appropriate indentation to show the structure of what you're doing. See this example of indented pseudo-code as comments.

    This approach to coding works with any programming language that has a way of mixing comments with code! (That should be all of them....)

For this week's Pre-lab,

Try the pseudo-code approach to write a first approach to the Follower program in part 1 of the Lab (below). It can be a standalone program, or it can be a menu item that you add to Robot Test Menu sketch that you hopefully got working on Monday.

Take a look at the Chicken description. You don't need to write anything yet. But start thinking about how you might make that work.

Lab 08 - Turtle Robots


  1. Follower

    Write a program to look only straight ahead and move forward or backward to maintain a constant distance from an object in front of the robot.

    You should have written a first draft of your program for the Pre-lab. Try that out and get it working. Then make some improvements to make the bot move more smoothly.

    Copy your working, well-commented code into your Note

    Also include two short paragraphs: one explaining what the code is supposed to do and a second describing how the robot actually behaved. (don't just say "it followed", describe its movements in some detail so a reader might be able to distinguish yours from someone else's robot)

  2. Chicken

    Write a program to scan the rangefinder left, right, and center and move around avoiding all obstacles. There are many approaches to doing this.

      Don't try to write the whole sketch out at once. Instead, break it down and take on one part of the task at a time.

      For example: You might start by just writing some pseudocode and some code to move the range finder to three different positions. Try to get the next part of the task working on its own. Then write and test another part by itself. Then start putting the parts together. Don't code more than about 10-20 lines before testing what you've written in some way.

    Finally, when you have your whole, working, well-commented sketch finished, put it into your report.

    Also include two short paragraphs: one explaining what the code is supposed to do and a second describing how the robot actually behaved. (don't just say "it followed", describe its movements in some detail so a reader might be able to distinguish yours from someone else's robot)

  3. Convenience Features

    Here are some things you may want to add along the way:

    • Motor speed adjust Have a menu item to adjust the speed of the motors.
    • Save to EEPROM You spend time adjusting the motor speeds and other parameters. Then you turn off the robot and the next time you start it up, you have to enter them again.

      The Arduino board has a built-in EEPROM chip: non-volatile memory which acts like a miniature hard drive. Google something like Arduino EEPROM library to find out how to use it. You'll need to include the EEPROM library which is a standard Arduino library. Your program can have a way to save parameters you care about, and then read them in again when you startup() your sketch again the next time you turn things on.

    • Adjust other parameters If you have a minimum distance to an object, let that be adjusted from a menu item.
    • Power monitor Have a way to check the voltage of both batteries (the 9V and the 4xAA group) using the analog read function. The 9V battery voltage is available on the Arduino board as the connection called "Vin". You'll need to make a voltage divider to bring each of these down to the range that can be safely measured by the analog inputs.
  4. Other Ideas

    If you need more inspiration here are some other possibilities.

    • Lights Have the robot react to its environment with lights as well as movement.
    • Noise Have the robot react to its environment with sound (beeps of various types).
    • Randomness Make the program somewhat unpredictable while still avoiding obstacles.
    • Speech We have a few speech chips to add another level of silliness.

Try to get the basic Chicken scanner avoider working in some way. Then try to add one convenience feature from 3 and one idea from 4. You may substitute your own ideas if you check with your instructor. Demonstrate your program with all its great features for your instructor.