Spin, using the RoboProp library.
Check out the main body of the RoboProp-Bot
roaming code, side by side with the Boe-Bot version in the
Listings included here.
As you can see, the code is very similar; the greatest
difference is how the bumpers are handled.
On the BOE, the whiskers use digital inputs declared
as PIN variables which were used directly in the
expressions. The BASIC Stamp does not support
procedures or functions, so the movement commands
had to be written as subroutines invoked by the GOSUB
keyword. The servo speed is controlled by global variables,
as is the time to travel.
On RoboProp, the analog short range IR sensors were
connected to analog inputs, read using a function call,
and compared to a constant BUMPER distance. Had I
used whiskers, I could have written
“if ina[lwhisker] == 0 AND ina[rwhisker] == 0”
Initially, I wrote:
“if (robot.ain(lbumper) > BUMPER) AND
(robot.ain(rbumper) > BUMPER) “
However, to make it easier for readers, I added some
helper functions allowing me to write:
“if left_bumper AND right_bumper”
54 SERVO 09.2011
Spin supports methods with arguments (think
functions and procedures), so I passed the “time to travel”
(in milliseconds) at the current speed as a parameter to
the helper forward/backward/left/right methods. I could
have also passed the speed, but I decided to use a global
variable for that purpose.
Take a look at Listing 3 to see what the main body
of code looks like after adding support for the rear virtual
bumper. Robbie sprints away when any object approaches
too closely from behind.
I encourage you to download the full source code for
both versions and compare them. You will see how easy it
is to program robots in Spin.
In Part 2, Robbie gets more sensors, greatly
expanding his capabilities! SV
Robotics with the Boe-Bot, Parallax Inc., ISBN: 1-928982-03-4.
BASIC Stamp Syntax and Reference Manual v2.2, Parallax Inc.,
Propeller Manual v1.1, Parallax Inc., ISBN: 9781928982470.