Figure 5 shows where everything
I used two speeds of PWM for
this project: slow and fast. I think I
could have gone a little faster
though. That will be a modification
for the next round of hacks on this
guy! I used the CCS PCM compiler
to write the code in C for the spider
robot. Since these PIC processors
don’t have PWM timers, I faked it in
the ISR routine by just counting. It
worked fine. Listing 1 shows how I
created my PWM with a simple
counter interrupt. I only had four
bits of resolution, but really, if we
don’t use feedback, how many
speeds does a robot use? In my
case, typically three: off, slow, and
In Figure 5, you can see how
tight the fit of everything is.
Nothing a little tape and hot glue
gun can’t handle, though.
I like my robots to look
interesting, but this time, the look was accidental. Take a
look at Figure 6. What a face! This robot initially scared my
three year old. She did eventually get used to it, though.
Rather than print the source program for this robot,
I’ve made it available on the Servo Magazine website as
bugf84.zip in the article downloads. The full source is there
and it implements only three behaviors: wander, avoid, and
edge. I’m a “Brooksian” behavioral programmer, so if you
are interested in what
Rodney Brooks called
programming, this robot
code is a gentle
To recap, this robot
is a hacked toy made
fully autonomous. It will
wander around and
avoid colliding (mostly)
with objects in its path.
It will avoid walking off
the edge of a table,
within reason. Within
what reason, you ask?
The Sharp IR detector’s
beam will bounce right
off of a highly polished
surface and the robot
will act like it sees the
edge of the table all of
the time. The same
thing will happen if it is
walking on a dark fluffy
Figure 4. Looking down on the Sharp IR sensor.
cliff. I found a nice device built by Sharp, and as usual, it
has a huge, complex incomprehensible part number. I used
a Sharp GP2Y0D810Z0F digital distance sensor that I found
at www.pololu.com. This model has a 10 cm detection
range. Perfect for my little walker. See Figure 4 for what it
The controller, IRPD, and Sharp sensor were pretty
tough to shoe-horn into this little machine, but I did it.
Listing 1: Simple PWM interrupt routine.
if (left == 0)
// This function is called every time
// the RTCC (timer0) overflows (255->0).
if (right == 0)
if (PWMperiod == 0)
PWMperiod = SPERIOD;
left = sleft;
right = sright;
//C int maint makes this > 32us!
//255-239 =16, 16*2us = 32us
16 SERVO 10.2011