The direction selection circuit is implemented below in pseudocode.
All variables/constants bytes unless otherwise specified
Constants:
External variables:
objR // Object on right side of center
objL // Object on left side of center
objA // Object dead ahead
seek // go toward the object
avoid // go around or away from the object
Internal variables:
seekAhead
seekRight
seekLeft
avoidAhead
avoidRight
avoidLeft
Exportable variables:
goRight
goLeft
goAhead
turn180
turned
Initialize:
Set all internal and exportable variables to 0
Utilities:
double bound(double v)
{
double ret = 0.0;
if (v > 0.99) ret = 0.99;
else if (v < 0.0) ret = 0.01;
return ret;
}
double random(double max)
{
generate a random double in the range 0.0 .. max
}
loop:
end loop