Albert Menu:        

 buttblue.jpg (750 bytes) Albert Project Home
The Albert Project Homepage.
 buttblue.jpg (750 bytes) Project Log
Follow Albert's progress.
 buttblue.jpg (750 bytes) Long Term Goals
Read the long term project goals.
 buttblue.jpg (750 bytes) Short Term Goals
Read the short term project goals.
 buttblue.jpg (750 bytes) Gallery
Enjoy pictures of Albert, taken during development.
 buttblue.jpg (750 bytes) Albert's Five Ears
Read this report about Albert's sonar sensors.
 buttblue.jpg (750 bytes) Albert Programming
Read this report about Albert's low level and high level code.
 buttblue.jpg (750 bytes) Speak, Albert, Speak
Read this report about Albert's text-to-speech ability.
 buttblue.jpg (750 bytes) Mood-Based Behaviors
Read this report about Albert's "Mood Matrix".

Programming Albert
Last Updated:  6/21/99

Disclaimer:
This report contains links to my source code, algorithms and programming ideas and concepts.  You are welcome to use anything you find here provided your application is non-commercial, and so long as you do NOT use my code as an example of the correct way to do things.  I've never had any training in proper programming techniques or practices, and don't always write well structured code, or do things in the best or most efficient way. 

Important Files

Albert's Functions and Subroutines
Last updated: 6/21/99

Albert's 'C' source code
Last updated: 6/10/99

Visual Basic source code 
Last updated: 6/17/99

GuywthBot.jpg (6364 bytes)

An Overview
Albert's programs run on two different processors, and use four different computer languages.  He has an onboard 68HC11 processor that interfaces with his motors and sensors.  It is programmed in FORTH, Assembly, and 'C'.  A serial cable connects the HC11 to my P200 laptop, which I use for high level processing and other functions.   It is running Visual Basic (version 5.0), and that's the language I will use for most of Albert's programming.

Albert's 68HC11 Program
Albert's C program accepts input from the serial port (either keyboard commands, or strings from my VB program).  It then handles Albert's PWM (Pulse Width Modulation) motor functions, or it reads a sensor and sends back a serial message with the results.

The commands that can be sent to Albert, and the data that can be received, look like this:

"!S1" - Read sonar #1 and send back a distance reading
"!S2" - Same for sonar #2
"!S3" - Sonar for sonar #3
"!S4" - Same for sonar #4
"!S5" - Same for Sonar #5
"!SC" - Read the compass and send back Albert's current heading
"!SP" - Read the photoresistor (light meter) and send back reading
"!S<" - Read the left encoder and send back count
"!S>" - Read the right encoder and send back count
"!ST" - Read the left and right touch sensors and send back value

"!MLFXX" - Send a Motor command to the Left motor, Forward, at XX% of full power
"!MRFXX" - Same as above, but for right motor
"!MLBXX" - Send a Motor command to the Left motor, Backward, at XX% of full power
"!MRBXX" - Same as above, but for right motor
"!MXX10" -  Turns off PWM, causing motors to stop

The HC11 code sits in a tight loop reading the encoders and waiting for an exclamation point.  When it sees one, it then begins to look for either "S" for Sensor commands, or "M" for Motor commands.  If it's a Sensor command, I know there will only be one more character to follow.  Motor commands have four more characters.  (That's why I look for a speed of "10" to turn off PWM.  Albert won't move until his motors reach about 18% power anyway.)

Future Upgrades:  I need to rewrite Albert's encoder routines and utilize interrupts.  The way they are currently implemented, I could be missing "ticks" while I'm in a separate timing loop (such as when Albert is timing sonar pings).

Programming Albert in Visual Basic
All of Albert's high level navigation routines and behaviors will be programmed in VB.  As of this writing I'm just now starting to add simple functions to make my code easier to understand and more readable.  For instance, I used to have to type in the following commands to make Albert announce that he is facing North:

MSComm1.Output = "!SC"
Do
     DoEvents
Loop Until MSComm1.InBufferCount >= 1
Compass = Val(MSComm1.Input)
If Compass = 13 then DirectSS1.TextData CHARSET_TEXT, 1, "I am facing North!"

It didn't take me long to realize that functions would make my life a whole lot easier.  I put the code above into a function called Compass() (and the text-to-speech command into a function called Say()).  So I can now do the same thing as above by typing the following command:

    If Compass() = 13 then Say("I am facing North")
    Or even simpler (using the direction() function): 
    Say("I am facing " & Direction())