Page 150 - The Definitive Guide to Building Java Robots
P. 150
Preston_5564C04.fm Page 131 Wednesday, October 5, 2005 7:22 AM
CHAPTER 4 ■ SENSORS 131
Figure 4-16. Three Polaroid 6500 Ranging Modules with Transducers
Code Objective
The objective here is to get range data from a variety of distance sensors.
Code Discussion
The first program I’ll discuss is the BASIC Stamp program, will return information from all
three distance sensors (see Example 4-6).
The three commands 101, 102, and 103 which will call the three subroutines ping_ir,
ping_srf, and ping_6500. Those three subroutines then return data from their respective sensors.
In ping_ir, the sensor uses the SHIFTIN command to get data from the sensor.
In both ping_srf and ping_6500, the sonars use RCTIME to measure the width of the echo
returned. The echo pulse width is proportional to the distance.