CS 372: Artificial Intelligence
Robot Building Lab
Session 2

Resource Kit
Outfitting A Robot Laboratory
Sample Syllabus for an AI Course
Robot Laboratory Handout
Session 1
Session 3



Find a MAC and extract the following items from your kit:

  1. The Handy Board.
  2. The battery charging unit.
  3. The RJ11 cable.
  4. The MAC-DIN 8 cable.
  5. The power adapter cable.
  6. The Interactive C floppy disk.

Next, we will connect the Handy Board to the MAC, and power it up!

  1. Put your MAC to sleep (if it is already awake!),
  2. Connect the battery charging unit to the serial port of the MAC using the MAC-DIN 8 cable.
  3. Make sure the "Charge Rate" switch on the charging unit is selected for "Normal Charge" (as opposed to "Zap Charge").
  4. Connect the Handy Board to the battery charging unit using the RJ11 cable.
  5. Connect the power cable to the battery charging unit and the other end of the cable into a wall outlet.
  6. Turn the Handy Board ON (the power switch is located near the RJ11 connector).

The Handy Board requires two software components: A 6811 runtime library, and the Interactive C application program. Both are provided on the Interactive C floppy disk. The 6811 runtime routines are like a small operating system for the Handy Board. They are normally pre-loaded on the Handy Board and reside there permanently. When you turn the Handy Board ON, if the display on the Handy Board shows the following:



Interactive-C
V 2.81 9/28/93


then we know that the 6811 runtime libraries are already pre-loaded. If you do not see the above display, you will have to download these libraries from your floppy. Here is what you will have to do:

Find the application labeled Init board R2 7.2 Modem on your Interactive C floppy. Double click the application and you will get the following screen on your MAC:

Turn OFF the power switch on the Handy Board. Turn it ON again while pressing the STOP button. This puts the Handy Board into bootstrap download mode. I.e. when you press the RETURN key on the MAC, the downloader will place the 6811 runtime system on the Handy Board. The downloader screen will show the following:

At this point, turn the Handy Board OFF and turn it back ON. You will now see the Interactive C message:


Interactive-C
V 2.81 9/28/93


Also, notice in the bottom right corner of the Handy Board screen, there is a blinking heart. A blinking heart indicates a healthy Handy Board. You may now exit the downloader application. Most likely you will not need to use it again. In case the contents of the Handy Board memory do get corrupted, you can follow the above steps to reload the 6811 runtime system.

Interactive C

We are now ready to look at the second piece of software. One that will be used for programming agents controlled by the Handy Board. Find the Interactive C application on the floppy disk. It is named IC R2 2.852 modem. Double click on the application and you will see the following screen on your MAC:

In the above window, as a result of launching the application, the software first tries to make contact with the Handy Board. if the Handy Board is turned ON, it will synchronize with it. It will also load additional program libraries before giving the prompt (>C).

At the prompt, you can enter any valid Interactive C (IC, from now on) statement. The application will translate the statement into code (pcode) that can then be executed by the Handy Board. The results of the execution will be returned on the MAC screen, or displayed on the Handy Board display, depending on the command issued. For example, try entering the following IC statement:


C>printf("I am alive!\n");


The string in the printf message will be displayed on the Handy Board display. Try typing the expression:



C>2 + 2;


This statement will be compiled and then executed on the Handy Board and the result of the evaluation will be returned on the MAC screen. Both of these are shown below:

Interactive C is a little-sister version of C. Additionally, it comes with several useful, Handy Board specific, libraries containing procedures and functions that provide access to various Handy Board features. Over the next few sessions, we will spend most of our time familiarizing ourselves with these. For now, read the first 9 sections (pages 1 to 28) of the Interactive C manual.

Building An Embedded Agent

In Chapter 2 of Russell & Norvig's text you learned that an agent is anything that can perceive its environment and act upon it. This requires the agent to have some sensors for perception and some effectors for acting. In this lab, we will create mobile agents that are capable of moving about in their environments. From your last lab, you should now have a wheeled LEGO assembly (chassis) capable of carrying the Handy Board (the LEGO Bug, for instance). This assembly is powered by two motors. Today, we will connect these motors to the mounted Handy Board so that we can build agent programs that exhibit simple motion behaviors. You may assume, for this lab, that the environment of the agent will be a big flat surface without any obstacles. Let us start by connecting the motors.

Place the Handy Board on the chassis. Connect the two motor cables to the motors (if not done already). Plug the pin ends of the two motor cables onto two motor ports of the Handy Board. Jack up the chassis so that the wheels are off the ground. Let us first see how to run the motors through a C statement.

The motor ports are numbered 0 through 3. The Handy Board's library contains procedures for controlling the motors. The command:


motor(int m, int p)


turns motor m on at speed p. There are typically seven speeds available ranging in values from -100 to 100. Negative numbers indicate a backward rotation and positive for forward motion. A value of 0 will turn the motor off.

Issue some motor commands to both the motors. Make sure that the motors go forward when you give them positive speeds. if the polarities are switched they will go in the opposite direction. Switch the pin connections and make sure the motors are configured properly.


Writing Procedures

In this section, we will learn to write short procedures and programs that control the behavior of mobile agents. Here is a simple program:



int LeftMotor = 3; /* Left motor is connected to port 3 */
int RightMotor = 0; /* Right motor is connected to port 0 */

void goForward(long Time) {
motor(LeftMotor, 100);
motor(RightMotor, 100);
msleep(Time);
alloff();
}


Before you enter this program, go to the Interactive C disk, open the IC-Libraries folder and in it, create a new folder (say Agents). Open SimpleText, and enter the above program. Save it in a file (say moves.c). Next, launch the IC application. Turn the Handy Board ON, and at the IC prompt enter the command:


C>load Agents:moves.c


Your program will be loaded, compiled, and downloaded into the Handy Board's memory. After this has been done successfully, you can issue a command to the agent as follows:


C>goForward(500);


Observe the actions. You can also write a main procedure as follows:



void main(void) {
goForward(500);
}

A simple program that you can add to the moves.c file. Next load the file again. After the file is loaded, you may disconnect the RJ11 cable from the Handy Board, turn the Handy Board OFF, place the agent on a flat surface, and then turn the board ON. As soon as the board is turned ON, the main procedure is executed.


Exercises

Using two motors, you can program the agent to go forward or backward in a straight line, or turn going in the forward or backward directions. Write some IC procedures to make your agent go forward, backward, turn while going forward, and turn while going backward, etc. Here are some exercises to work on:



Resource Kit
Outfitting A Robot Laboratory
Sample Syllabus for an AI Course
Robot Laboratory Handout
Session 1
Session 3 ÿ