
Sat Jul 21 10:23:51 CDT 2001

What is this stuff?

These files represent the working code from one of my robots.  It is
by no means a finished robot (if there actually is such a thing).  If
your interests include amateur robotics, I hope these examples using
the excellent GNU gcc cross-compiler generating code on an i386
GNU/Linux system for a 68hc11 target are interesting.  The best
distribution I have found of this cross-compiler is from Stephane
Carrez (www.gnu-m68hc11.org).  This code assumes that distribution.
If you build your own compiler or select a different distribution, you
may have some adjustments to make.

Who might be interested in it?

The code is written entirely in c (even interrupt routines) to make it
more accessible to software types unaccustomed to a runtime
environment that provides no ready-built OS services.  It shows
examples of interrupt routines, accessing absolute memory addresses,
responding to external events, a PD speed controller and pwm motor
control.  The main program is an arbitration loop based loosely on the
ideas of subsumption architecture.

How can I use it?

You can view this as an example of how these things might be done in
c.  Most commercial compilers I have used have similar functionality
even if not identical syntax.  If you are not using Linux or some
other version of UNIX, you may still be able to get a distribution of
gcc for your environment and it may work, but I have no personal
experience of this.

One of the advantages of free software, of course, is that if you
happen to become interested in this code, all the tools and even the
OS are free for grabs on the net.  

Will it work on my robot as is?

Yes, if your controller is setup exactly like mine (MIT 6.270 board).
In the likely event that is not the case, you will need to check the
various services to see which are applicable to your controller.  Some
should work on any 68hc11 (sysclock.c, analog4.c, buffered_io.c);
others are specific to the MIT 6.270 card (analog32.c, ir_detect.c).
The bot.h file has most of the #defines that map specific I/O ports.
In the examples/config directory I have added a subdirectory for
m68hc11-6270; the memory.x file there is a memory map for the 6270
card (where the ram is), and the make.def contains loader instructions
for this card (setting a value for _io_ports).  The speed controller
is generic, but you will absolutely need to tweak the P and D
constants.  The pwm controller is a bit arcane in order to conserve
TOC outputs (some are dedicated on the 6.270 interfering with more
obvious choices).

Where is the documentation?

You are reading the primary documentation file, but there is also a
file named mtr_tab.txt which has tips about building a custom
mtr_tab.h file.  The code is commented to provide explanations of what
is taking place (even if you don't program in c).  The overall
strategy is to use interrupt service routines to update globally
accessible data structures.  The bot is controlled by the main program
(bot.c) which invokes behaviors based on the contents of those data
structures.  A stable sampling rate is provided by the interrupt
routines, and the main program loops as fast as possible in the
remaining time (ie time not used by interrupt services).

Why didn't you use a more modern language like java or c++?

Because I have more confidence in my ability to control the assembly
produced by the compiler using c. If you have never looked at the
assembly language output produced by a compiler, this may strike you
as an odd approach to choosing a computer language.  For work on an 8
bit processor clocked at 2 mhz with a whopping 32k of ram, some
conservation of resources is in order.

Why didn't you write this in assembly language then?

I did actually, but moved it to c for portability when I found a good,
free c compiler for 68hc11.  Unfortunately, I can still write tighter
68hc11 assembly language than I can convince gcc to write (this says
as much about my skill with gcc as it does my skill with 68hc11
assembly).  Still, gcc can write pretty good 68hc11, and c is vastly
easier to modify and understand when you come back to revisit and
refine the code later.

Why are you giving code away?

First, this is an attempt to contribute to the admirable work of GNU
community in providing a powerful development environment for the
68hc11 which is free.  Second, because I have chosen a free
development environment, I am free to share my work with others; they
can do likewise, and we will all end up with cooler robots as a
result.  The 68hc11 is an excellent choice for a robot controller due
to the timer input/output compare facilities and eight channel A/D
converter.  Several 68hc11 boards are available at reasonable prices,
ranging from simple kits to assembled units complete with motor driver
chips.  When supported by the GNU tool chain, a powerful, inexpensive
development platform results.  I hope this code increases the
attractiveness of this useful combination for robot enthusiasts
everywhere.

