Page 154 - The Definitive Guide to Building Java Robots
P. 154
Preston_5564C04.fm Page 135 Wednesday, October 5, 2005 7:22 AM
CHAPTER 4 ■ SENSORS 135
public static void main(String[] args) {
try {
// since i am testing at my desk and not on my robot
DistanceStamp s = new DistanceStamp(SingleSerialPort.getInstance(1));
System.out.println("Sharp IR Reading = " + s.getIR());
System.out.println("SRF04 reading = " + s.getSRF());
System.out.println("6500 reading = " + s.get6500());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
Section Summary
In this section, I discussed a few types of distance sensors: one infrared and two sonar. The first
sensor is the Sharp GP2D02 which is good for short distances. The second, the Devantech SRF04,
is a good all-purpose short- to medium-distance sonar, and the third is a Polaroid 6500 ranging
module with an instrument grade transducer, which works for up to distances of 35 feet.
The programs created were
• distance.bs2: Which is the BASIC Stamp program getting data from the distance sensors.
• DistanceStamp.java: Which gets this distance data from the distance.bs2 program.
I’d recommend choosing the Devantech SRF04 sensors for three reasons:
1. They use less power than the Polaroid 6500.
2. Their effective range is the same given most indoor conditions.
3. They’re more accurate than the Sharp IR sensor, and less prone to noise or floor echo.
4.4 Chapter Summary
In this chapter, our goal was to introduce some of the sensors you’ll use in robotics and explain
how to connect them with your microcontroller.
If you’re building robots with multiple sensors, however, it might be worth your time and
money to use a printed circuit board (PCB) for connecting and wiring your sensors to your
microcontroller. Two are available at www.prestonresearch.com, and are described in the
following bullets.
• CMPS03 Carrier Board: For connecting a Devantech CMPS03 compass to an RJ11
connector.
• Sonar Distribution Board: For connecting up to 14 I/O pins from your microcontroller to
your sensors.
If you’d like to create your own PCBs, however, check out www.ExpressPCB.com.