Page 330 - Amphibionics : Build Your Own Biologically Inspired Robot
P. 330

Amphibionics 07  3/24/03  9:13 AM  Page 309
                                        Chapter 7 / Turtletron: Build Your Own Robotic Turtle
                        then bounces back. Since we know that sound travels through air
                        at approximately 1129 feet per second when the temperature is 21
                        degrees Celsius, we can accurately determine distance by measur-
                        ing the amount of time between the transmission of the pulse and
                        the return echo. When the temperature drops, the speed of sound
                        through air slows down. If a temperature sensor was added, an
                        algorithm  to  determine  distance  based  on  the  speed  of  sound
                        through air could take the surrounding temperature into account
                        and adjust for differences.
                        The PicBasic Pro command called PULSIN returns the round trip
                        echo time in 10 µs units when using a 4-MHz oscillator. Since the
                        pulse width has a 10 µs resolution per increment, that means that
                        if PULSIN returns a value of 1, then 10 µs have elapsed. The fac-
                        tors to convert the raw data to inches and centimeters given in the
                        SRF04 manual are 74 for inches (73.746 µs per 1 inch) and 29 for
                        centimeters  (29.033  µs  per  1  cm)  based  on  the  Basic  Stamps
                        PULSIN  command  returning  values  in  2  µs  increments.  In  the
                        SRF04  manual,  the  calculation  to  determine  the  distance  is  not
                        divided in half to take into account the return time of the pulse
                        because  the  sample  program  is  for  the  Basic  Stamp  II,  which
                        returns  PULSIN  values  in  2  µs  increments.  Because  the  PULSIN
                        command with PicBasic Pro is returning values in increments of 10
                        µs, the conversion factor will need to be divided by 5, so that we
                        get the correct value based on our 10 µs increment. Taking the
                        PULSIN  increment  timing  difference  into  account  gives  us  an
                        approximate conversion factor of 15 for inches and 6 for centime-
                        ters. Testing with the ranger indicated that the raw value returned
                        by PULSIN when an object was 12 inches away was 180. One hun-
                        dred and eighty divided by the inch conversion factor of 15 gives
                        us the correct distance of 12 inches.
                        In order to test the SRF04 sonar ranger, a program will be written
                        to produce audible tones, based on the distance of an object from
                        the device. Compile the sonar-test.bas code listed in Program 7.5,

                                                                                                 309
   325   326   327   328   329   330   331   332   333   334   335