www.youtube.com/watch?v=VixxZHM02Ok):
Now, it’s your turn to
build a robot of your own. You have the tools and
knowledge. If you need more I/O pins, then it’s easy to
step up to a 14M2 or a 20M2. Figure out what you want it
to do. Roll, walk, or fly? Incidentally, the wheels shown here
can be swapped for simple leg mechanisms to make
walking robots. Two examples are my Spiderbot and
Theobot walkers, previously featured in SERVO’s March and
April 2014 issues. Yep, there’s videos for these at
www.youtube.com/watch?v=08YB5BOLzgU and
www.youtube.com/watch?v=5rcjZZreLFY.
SERVO 2,139 ‘left stop fwd+
rev-SERVO 4,138 ‘right stop fwd- rev+
MAIN: ‘ label main begins loop
READADC 1,B0 ‘ read sensor value
IF B0<55 THEN GOTO STOPP ‘ nothing close
IF B0<80 THEN GOTO SPINL ‘ hand very high
IF B0<110 THEN GOTO FWD ‘ hand medium high
IF B0<170 THEN GOTO SPINR ‘ hand low
REVV: SERVOPOS 2,130:SERVOPOS 4,147:GOTO MAIN
FWD: SERVOPOS 2,150:SERVOPOS 4,128:GOTO MAIN
SPINL:SERVOPOS 2,135:SERVOPOS 4,134:GOTO MAIN
STOPP:SERVOPOS 2,139:SERVOPOS 4,138:GOTO MAIN
SPINR:SERVOPOS 2,143:SERVOPOS 4,142:GOTO MAIN
The program reads the Sharp sensor distance (closer =
higher) and stores the value in B0. Each of those four IF
checks — when true — make the program branch to a
different label, with different SERVOPOS values. Values
under 55 (nothing nearby) branch to STOPP. Values 170
and above (hand very close) do not branch and “fall
though” the IF checks to default at label REVV (reverse).
This wraps up this series on PICAXEs and BASIC Bots.
We have barely scratched the surface of the subject, but
hopefully I have whet your appetite for building,
programming, and learning. I find it very rewarding to
create something from scratch. As simple as these robots
are, building and using them really bridges the gap
between theory and reality. Programming a robot to do
even a simple task is much harder than most people think.
Even failing can be helpful as a learning experience, so keep
at it.
Everything loops back to MAIN afterwards and the cycle
repeats.
That’s sufficient information to get you started
programming this robot on your own. Making the robot
drive around in a consistent square, star, or figure 8 pattern
is a great place to start. Use the SERVOPOS values we
determined to go straight for a while (PAUSE 3000), then
turn for a while (PAUSE 2000), then repeat in a loop.
Join a robotics club, and/or find a robotics contest or
event. Join an online forum to chat with like-minded people.
Try www.picaxeforum.co.uk, http://forums.parallax.
com/categories/robotics, and www.robotrebels.org.
I’m “erco” in all those forums.
Lots of smart and friendly people are waiting there to
help. Drop in, say hi, and show us what you’ve been
building in your basement. SV
For your next challenge,
use the Sharp IR sensor as
an obstacle detector. Write a
simple program to let the
robot roam randomly while
avoiding obstacles. You
might start by simply driving
forward until the sensor
voltage goes up (indicating
an obstacle), back up, turn a
bit, then repeat. After that,
you might try driving
forward for a timed interval,
then stop and rotate in place
while measuring distances,
selecting a direction with no
obstacles, then repeating.
Unlike simpler IR sensors
(such as RoboCar used last
month), the Sharp sensor
works equally well on most
colors. Being able to aim the
sensor high and low is also a
nice feature. Select which
works best for your
environment.
SERVO 01.2016 43
Figure 14.