Page 260 - The Ultimate Palm Robot
P. 260

Color profile: Generic CMYK printer profile
           Composite  Default screen
                                                          Bots /The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 9






                                                              Chapter 9  Sensors and Enhancements    243



                                      When attaching the Hamamatsu photoreflector to the SV203, the Vcc and
                                    GND pins are attached to the Vcc and GND pins in block J4. The Vo pin is
                                    attached to one of the A/D ports in block J3. This is the same way we attached
                                    the IR rangers to the SV203. We recommend that you use a circuit board or
                                    breadboard to mount the sensor. This will give you a way to attach the sensor
                                    to the frame of the robot. For best operation, the sensor needs to be mounted
                                    within just a few millimeters of the surface. The specification sheet that comes
                                    withthesensorgivestheoperatingcharacteristicsat3mm.Thatisapproximately
                                    1/8 inch. The sensor will work if it is slightly further away than the optimal
                                    3mm, but its performance will be degraded.
                                      Recall from Chapter 7 that we can read the analog port with the command
                                    ADn, where n is the port number from 1 to 5. Thus, to use this sensor, you will
                                    send the AD command to the board and read the output. If the sensor is in the
                                    high state, you will receive a value of 255. When the sensor is in the low state,
                                    you will receive a very low value (but not necessarily 0). Arepresentative code
                                    listing to do this using HotPaw Basic is shown next. This code listing assumes
                                    that the P5587 IR photoreflector is connected to port 1. You would need to
                                    change the listing to reflect the actual port you use.

                                   print #5, "BD1 AD1" : rem tell board sensor 1
                                   result = get$(#5, 0) : rem read 1 byte
                                   if (result < 50)
                                      /* P5587 sensor is not over line */
                                   else
                                      /* P5587 sensor is over line */
                                   endif


                                      Connecting this sensor to the BrainStem is just as easy. Just as with the
                                    SV203, you will connect the GND, Vcc, and Vo pins of the sensor to the correct
                                    pins of the BrainStem.
                                      After connecting the sensor to the BrainStem and mounting it to the robot
                                    at approximately 3mm over the surface to be sensed, we can read its output
                                    using the TEA language. Here is sample TEA code for the BrainStem that
                                    assumes the IR photoreflector is connected to port 1.


                                   r1=aA2D_ReadInt(APPRK_IR1);
                                   if (r1<50) {











           P:\010Comp\Bots\880-6\ch09.vp
           Monday, May 12, 2003 4:33:41 PM
   255   256   257   258   259   260   261   262   263   264   265