|
|
An Overview 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 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
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:
|