Page 334 - Amphibionics : Build Your Own Biologically Inspired Robot
P. 334
Amphibionics 07 3/24/03 9:13 AM Page 313
Chapter 7 / Turtletron: Build Your Own Robotic Turtle
Obstacle Avoidance Using the
Ultrasonic Range Finder
In the next experiment, the robot will explore its environment and
will react to obstacles based on the distance information obtained
from the SRF04 sonar module. The robot will normally travel in a
forward direction while sonar distance measurements are taken.
When it is determined that the robot is within 12 inches of an
object, it will reverse, and then alternate between rotating to the
left and rotating to the right each time an obstacle is sensed. The
distance that the robot travels in reverse and how far it rotates in
either direction is determined by the amount of time that the
motors are activated. The robot will rotate a further distance to the
right than to the left so that it does not get stuck in corners. You
can try experimenting with the pause values to change the behav-
ior. When the avoidance maneuver is complete, the robot will con-
tinue moving forward. Compile the avoidance.bas code listed in
Program 7.7, and then program the PICmicro MCU 16F84 with the
avoidance.hex file listed in Program 7.8. After watching the robot
behavior, it is obvious that a better system to track the distance
that the robot has traveled or rotated is needed. Later in the chap-
ter, a linear optical shaft encoder will be added to track distance
traveled, and to develop a more precise motor control method.
'------------------------------------------------------------------------------------------------------------------------------
PROGRAM 7.7
' Name : avoidance.bas
avoidance.bas program
' Compiler : PicBasic Pro - MicroEngineering Labs
listing
' Notes : Obstacle avoidance using the sonar ranger
'------------------------------------------------------------------------------------------------------------------------------
' PortA set as outputs. Pin 1 input.
trisa = %00000010
' PortB set as outputs.
trisb = %00000000
313