Listing 1: A Search FSM.
void Track(void)
/*
We see something, try to get closer to it.
*/
{
//long
//enough
//to turn?
tState = 2;
}
else if (rightSONAR <
IN_SONAR)
{
static uint8_t dur=0; //timer holder
static uint8_t tState = 0; //state
//holder
static uint8_t direction = 0;//which way
//to go?
if (priority > TRACK)
{
return;
//something higher
//priority is running
}
if ((leftSONAR < IN_SONAR) || (rightSONAR
< IN_SONAR) || (priority == TRACK))
{
WinkTracker();
if (priority < TRACK) //we trump
//this
{
printf(“I see him\n\r”);
priority = TRACK;
tState = 1; //set up for
//tracking
//action
}
switch (tState)
//state
//machine
//here
direction = RIGHT;
lS = HALFFWD;
rS = HALFREV;
dur = 20; //is
//this
//long
//enough
//to turn?
tState = 2;
}
else
//nothing to do, go
//back to search
{
tState = 0;
priority = 0;
tState = 0;
}
break;
case 2:
//wait for turn to
//be over
if (dur == 0)
{
tState = 1; //go
//check
//again
{
case 1:
//turning
//left
if (leftSONAR < IN_SONAR)
{
}
else
{
dur—;
direction = LEFT;
lS = HALFREV;
rS = HALFFWD;
dur = 20; //is this }
}
break;
}
}
without a picture of the actual robot
in question! Figure 4 is my little mini
Sumo named “White Stripe” after one
of my current favorite Indy groups.
You’ll note there are no sonar units –
I replaced them with IR range finders
that hide inside. Another nice feature
of FSM programming and breaking
your code up is easy substitution of
new code and hardware! Enjoy.
Here we are again at the end of
another column, another month, and
coming up on another year. Where
did all the time go? I hope you got
something from me this month, and I
hope you keep sending letters with
questions. I like answering them! You
can reach me at
roboto@servomagazine.com. I’ll be
happy to work on your issues! Until
next time, keep on building those
robots! SV
SERVO 11.2010 17