Inline graphics on this page: 44K

 

Sound

 

Our culture favours the visual far above sound. But we do blink and sometimes voluntarily close our eyes for while, without feeling uncomfortable. Close your ears and your mind immediately turns inward. Sudden deafness has a surprisingly strong impact, patients describing the world as being 'dead', lacking movement. It appears that sounds caused by interaction with objects (footsteps, writing on a keyboard, a door closing) connect us to the world on a primitive level, even deeper than vision; perhaps that is why we don't have `earlids'. It is believed that life heard, and listened, before it could see.

For a small robot like the Spider, recognizing a great variety of sounds is out of the question. But it is possible to let simple hardware concentrate on a specific kind of `chirp', somewhat like a cricket. A chirping voice and well-tuned hearing would allow Spiders to tell each other what is going on, to get a good idea of the distance between them, and to track and find one another when they want. Worth looking into, don't you think?

Five demands were made of the Spider sound system:

  1. It should be capable of locating a device which is chirping, even when that sound source is around a corner - not in line of sight.
  2. Accurate timing must be available to measure distance (knowing the speed of sound).
  3. It has to work despite a reasonable noise level, such as normal conversation, or a radio playing in the background.
  4. The system should allow the encoding of simple messages.
  5. It has to be cheap, light, and easy to build.

Top

 

Sound direction finding

Sound in air is a pattern of pressure differences, best thought of as waves. If the source of a sound is right in front of you, the wave tops will reach your ears at the same time; they are said to be `in phase'. Sound waves originating left or right of center will have a different phase relationship. Human hearing also pays attention to other properties of sound. Frequency dependent attenuation caused by the head, the auricles and the shoulders is used to determine whether the source of a sound is above or below, in front or behind. But accurate direction finding in the horizontal plane is mostly done by processing phase differences.

Biological systems are capable of processing continuous sound. They actually need a sound to last for some time - or a series of short bursts - to determine the direction of the source with accuracy. Using simple electronic means, continuous sound is very hard to deal with, at least indoors. Why? Because sound bounces around. The waves pass the ears, hit walls, floor and ceiling, and come back to create complex patterns that take serious processing to make sense of.

So instead of imitating life to the letter, we should take advantage of silicon strong points:

  1. Even very simple electronic devices easily handle events lasting just a few microseconds.
  2. Using a cheap (about 1 dollar) crystal, we can do incredibly precise timing.

This thinking leads us to using very short chirps, sounding almost like clicks. The Spider `ears' merely detect the arrival of the first waves, and then stop listening until all echoes have disappeared. This allows all the things we want - direction finding, distance measurement and communication. But let's first look at the basic hardware.

Top

 

Circuit diagrams

An explanation of the abbreviations is here if your need it.

Circuit diagram of one Spider `ear'

Above you see the circuit diagram of one Spider `ear', intended for a chirp sound frequency of about 4.5 KHz. The upper half of the diagram is an elektret microphone followed by a pre-amplifier providing up to 55 dB gain at that frequency, and also a bit of pre-filtering. The lower half of the diagram is an Andreyev filter - a tuneable version of the well-known double-T. When tuned as described below this filter will have its -6 dB points at about 4000 and 5000 Hz, while giving upwards of 20 dB gain at the center frequency. It is followed by something best described as a threshold detector. Normally, the output will be high. But when a chirp is recognized, the output goes low for as long as the sound is present (plus a short recovery period). 4.5 KHz was chosen as the chirp sound, because a cheap (less than 2 dollars) and readily available piezo transducer was found to be especially efficient at this frequency.

At this point, you may wonder why discrete components have been used instead of an integrated circuit. My arguments are supply voltage tolerance, availability and price. The ear above uses less than 1mA at around 4V. It performs well at 3V and even lower supply voltages, reliably recognizing a Spider chirping 6 meters away in another room (door open), while a radio is playing rather loudly just 70 centimeters from the mike. The most expensive part is the microphone, which costs about one dollar. All parts together (not counting a printed circuit board) should set you back less than six dollars.

The number of `ears' and transducers needed varies with the application. The first Spider will get two ears, and `talk' to a transponder equipped with one ear. Both will have a transducer to chirp with. The diagram below shows the other hardware involved, most notably the AT90S1200 microcontroller.

Circuit diagram of a Spider controller with `ears' and
     `voice'

As you see, the piezo transducer is driven directly by the controller, using software to generate proper chirps (typically 20 cycles each). The ears are each connected to an i/o pin. At this stage of development, power is supplied by the PC to which range and direction data are being reported, through the cable that is also used to program the controller. The five parallel port data pins (2-6) provide power with ease, and are reasonably protected by 220 ohm resistors.

The transponder mentioned above is identical, except that it has only one ear and its own power source, a nicad battery connected to Vcc (which is disconnected during programming). The transponder is to be developed into a feeding station for the Spider's nicad batteries, using a fast and safe delta charge method. This will be under control of the same microcontroller, needing very little extra hardware.

Top

 

Measuring distance

Originally I had the transponder chirping at fixed intervals (so it wasn't a transponder then) and flashing a light source at the same time. Range was to be obtained by measuring the difference between the arrival times of the chirp and the light flash. Ken Huntington suggested the following transponder method:
The distance between Spider and transponder is found by measuring the time between emitting a questioning chirp and receiving the transponder's answer. The transponder inserts a known delay (about 0.5 seconds) to avoid trouble with reflections. The Spider subtracts this delay from the total time, and the remainder is divided by two. Multiplication by the speed of sound in centimers per second (taken to be 34000) is the final step.

Top

 

Results

The present software version consists of 3 programs - one for the Spider's ears, one for the attached PC, and one for the transponder. When all are active, you hear this:

   Spider: "Chirp, chirp?"
   Transponder, after a 0.5 second pause: "Chirp"

This repeats every 5 seconds. Range and direction data are reported to the PC, which shows range in centimeters, followed by which ear was the last to detect the answering chirp (and thus furthest from the transponder). The third reported item is `delta,' the time difference between the ears in steps of 64us, or about 2cm of sound travel. What direction in degrees this should result in depends on the distance between the left and right ear.

Range accuracy depends on how well the reaction time of a sound channel can be taken into account. For the prototype, good accuracy when close meant about 10cm error at a range of 2 meters. In the tables below, part of the lack of accuracy at 4 meters is caused by the rather haywired nature of the prototype ears; the transducer is at some number of centimeters from the microphones (about 25), which changes as the assembly is turned. When the transponder is not in line of sight, the sound is unlikely to follow the shortest route to the ears, so range will be a rough indication at best.

The delta is quite accurate at ranges less than 2 meters or so, when reflections don't interfere. And even when the sound reaches the ears `around a corner' (transponder not in line of sight, distance 6 meters or more), the left/right info tends to be good enough for a robot using the ears to find the transponder. Some of the delta inaccuracies seen below were caused by me, when moving closer to turn the ears board in the 5 seconds between chirps.

The tables below were created by adding the number of degrees left or right off center to the raw output of the software. The two microphones of the ears were mounted on a pcb (13cm apart), which was loosely placed on the Spider chassis. Both Spider and transponder were on the floor, and all microphones and transducers faced towards the ceiling (the system is intended to be omnidirectional).

   Line of sight, transponder at 4.20m
   
   range in cm: 435, right ear, delta: 9           +60°
   range in cm: 435, right ear, delta: 8
   range in cm: 435, right ear, delta: 8
   range in cm: 435, right ear, delta: 9
   range in cm: 435, right ear, delta: 9
   range in cm: 435, right ear, delta: 4           +45°
   range in cm: 435, right ear, delta: 4
   range in cm: 435, right ear, delta: 4
   range in cm: 435, right ear, delta: 4
   range in cm: 435, right ear, delta: 4
   range in cm: 435, right ear, delta: 3           +30°
   range in cm: 435, right ear, delta: 3
   range in cm: 435, right ear, delta: 3
   range in cm: 435, right ear, delta: 3
   range in cm: 443, right ear, delta: 2           +15°
   range in cm: 443, right ear, delta: 2
   range in cm: 443, right ear, delta: 2
   range in cm: 443, right ear, delta: 2
   range in cm: 435, right ear, delta: 3
   range in cm: 443, right ear, delta: 0           +0°
   range in cm: 443, right ear, delta: 0
   range in cm: 443, right ear, delta: 0
   range in cm: 443, right ear, delta: 0
   range in cm: 443, left ear, delta: 1            -15°
   range in cm: 443, left ear, delta: 1
   range in cm: 443, left ear, delta: 1
   range in cm: 443, left ear, delta: 1
   range in cm: 443, left ear, delta: 2            -30°
   range in cm: 443, left ear, delta: 3
   range in cm: 452, left ear, delta: 2
   range in cm: 443, left ear, delta: 3
   range in cm: 461, left ear, delta: 4            -45°
   range in cm: 461, left ear, delta: 4
   range in cm: 461, left ear, delta: 5
   range in cm: 461, left ear, delta: 4
   range in cm: 452, left ear, delta: 6            -60°
   range in cm: 452, left ear, delta: 6
   range in cm: 452, left ear, delta: 5
   range in cm: 452, left ear, delta: 6


   Transponder around the corner to the left, 90°, two doorways:
   
                             |
                             _
           transponder 
                             -  
                             |
                             |----|        |-----
                             |
                             |
                             |      Spider
   
   Total distance about 4 meters
                             
   range in cm: 452, right ear, delta: 23          +60°
   range in cm: 452, right ear, delta: 23
   range in cm: 452, right ear, delta: 23
   range in cm: 452, right ear, delta: 30
   range in cm: 452, right ear, delta: 20          +45°
   range in cm: 400, right ear, delta: 13
   range in cm: 400, right ear, delta: 13
   range in cm: 409, right ear, delta: 13
   range in cm: 426, right ear, delta: 8           +30°
   range in cm: 426, right ear, delta: 11
   range in cm: 426, right ear, delta: 8
   range in cm: 417, right ear, delta: 15
   range in cm: 417, left ear, delta: 3            +15°
   range in cm: 417, right ear, delta: 5
   range in cm: 417, left ear, delta: 2
   range in cm: 417, right ear, delta: 5
   range in cm: 426, left ear, delta: 4            0°
   range in cm: 417, left ear, delta: 1
   range in cm: 409, left ear, delta: 7
   range in cm: 417, left ear, delta: 2
   range in cm: 417, right ear, delta: 5           -15°
   range in cm: 417, left ear, delta: 2
   range in cm: 417, left ear, delta: 2
   range in cm: 417, left ear, delta: 6
   range in cm: 417, left ear, delta: 3            -30°
   range in cm: 417, left ear, delta: 6
   range in cm: 417, left ear, delta: 10
   range in cm: 409, left ear, delta: 5
   range in cm: 426, left ear, delta: 8            -45°
   range in cm: 417, left ear, delta: 9
   range in cm: 417, left ear, delta: 5
   range in cm: 417, left ear, delta: 6
   range in cm: 417, left ear, delta: 11           -60°
   range in cm: 426, left ear, delta: 17
   range in cm: 417, left ear, delta: 7
   range in cm: 417, left ear, delta: 13

Top

 

Noise rejection

As has been noted above, the ear hardware is sufficiently selective to reliably recognize a Spider chirping 6 meters away in another room (door open), while a radio is playing rather loudly just 70 centimeters from the mike. But sudden, loud sounds - like some kitchen noises, a clap of your hands, or even a good flick of the fingers at close range - will pierce through the filtering. To avoid errors that might be caused by such noise, both transponder and Spider's ears only listen during short, carefully timed periods. Moreover, the transponder expects the Spider to identify itself with two questioning chirps separated by a short pause.

The process of cooperative ranging and direction finding starts with two chirps emitted by the Spider. After detection of what might be a first chirp, the transponder waits 0.35 seconds before listening for the second chirp, which must follow within 65 milliseconds. Only if it does an answering chirp is given, after a delay of 0.5 seconds. The transponder does not resume listening until a further 5 seconds have passed.
In the mean time, the Spider keeps its ears closed until 0.5 seconds after emitting the second chirp. Then it listens for just 65 milliseconds with both ears for the answering chirp. As soon as one ear has detected the chirp, it pays full attention to the other ear for a further 16ms. At the end of that period, all ears activity stops for 5 seconds. Then the next questioning chirps are emitted.

All this results in a listening duty cycle of about 1.3 percent, giving noise little time in which to cause errors. When development is complete, the 5 second pause will be doubled to give the Spider sufficient time to move between chirps - it can't move while listening, because of the noise caused by its feet and motors. This further reduces the listening duty cycle, thus increasing the noise margin.

Note: The strategy of having the Spider listen for just 65ms results in a maximum range of about 11 meters (65ms * 340m/s / 2).

Top

 

Software

The software described above is available under the GNU General Public Licence. Here you have a self-extractor containing both sources and executables:

The complete ear package (73K)

NOTE: The hardware/software combination described here counts on the PC parallel port to provide about 4.5V at a few mA. Modern PCs may not supply much more than 3V, in which case the hardware and software as described here will NOT work.

You will also need programmer software to upload the transponder and ears programs to the microcontrollers. This can be found on a previous page.

Top

 

PCB layout

PCB layout of a single `ear'

Above you see the circuit board layout used for the ear prototypes. The distance between the two holes for almost every resistor and capacitor was 5mm. If you use a 2Nxxxx equivalent for the BC549C, be careful: they often come in a similar case, but with a different pin-out.

Using ordinary parts on a pertinax PCB, the weight of an ear is about 10 grams, which I consider to be too much. So for my own Spider proper, surface-mounted devices will be used. The layout looks like this:

PCB layout of a single `ear' using SMT

All resistors and ceramic capacitors are type 1206 (3.2 x 1.6 mm). The transistors are of type BC847C. And The weight of an ear using this technology, on a 0,5mm thick epoxy PCB, is 4 grams. That includes the microphone!

Two ears in SMT, during experiments

Top

 

Adjusting an `ear'

Connect the little test circuit on the right to the ear's output. Upload test.rom (in the self-extractor mentioned above) to the transponder, or at least an AT90S1200 board equipped with a piezo transducer as shown in the circuit diagram above. Power up the transponder; it will emit one chirp a second. Power up the ear and the test circuit. Test circuit

The distance between the chirper and the ear should be about 1 meter to begin with. Center all three potentiometers. Turn the 50K pot (adjusting the sharpness of the filter) until the LED lights continuously (filter too sharp and oscillating). Turn it back about 20 degrees.
Turn the 25K pot slowly (frequency adjustment), looking for the point where the LED lights up when the chirper chirps. This is likely to happen within a wide tuning range. Gradually turn back the 100K pot (to decrease pre-amplification). This will narrow the tuning range. Center the 25K pot within the range found, and increase the sharpness.
Move the chirper to a distance of about 3 meters and check the tuning. Then move the chirper to a distance of 8 meters or so, perhaps out of the room (leaving the door open), and check the tuning again. Try to get response from the LED with as little pre-amplification as possible. Finally check that the filter is not prone to oscillation, reducing sharpness a little if necessary. Disconnect the test circuit.

The Spider's two ears also need their balance adjusted. This is best achieved using the software described earlier. Place the transponder exactly in front of the ears, about 1 meter away, and make sure there are no sound reflecting objects near. With everything switched on, the attached PC should report a steady 0 delta. If the delta is not 0 or not steady, turn one of the 100K pots to improve matters - a large difference in sensitivity will cause one of the ears to need significantly less time to recognize a chirp. This must be avoided, especially at short range.

Top

 

Encoding messages

The two chirps the Spider uses to ask for a single chirp from the transponder form a very simple message. A protocol for communication between a number of Spiders might use 4 chirps for each call, to give far more possibilities. The three delays between the chirps would identify:

  1. The chirper
  2. The intended recipient
  3. The command or question

All delays must have a minimum length sufficient to allow echoes to disappear. The variable part of each delay can easily be determined using 256 steps, allowing over a hundred different chirpers, recipients and messages.

Top

 

Multiple Spiders communicating

The Spiders would probably have to talk in turn, operating on a synchronized move, stop and listen, move basis. A Spider skipping its turn would be assumed to be out of range or dead, and the next one could use its time slot. To be investigated.

Top

 

Other uses

These are just a few observations made while developing the ears, which may or may not be useful for other applications of the hardware.

To begin with, there is a considerable reserve in timing accuracy. Under ideal conditions - line of sight, limited distance, no reflecting objects nearby - it is possible to measure the time difference between the ears with 16 microsecond resolution and get meaningful results. The table below shows what happened under such ideal circumstances, with a distance of 2 meters between transponder and ears board. The Spider was aimed at the transducer, left in position for 4 answering `chirps', and then rotated left in 15 degree steps, each time spending two calls in the same position. An older version of the software was used to create the raw output for this table. It did not display range, but look at the accuracy of the delta...

   a is the angle off center in degrees
   The distance between the `ears' is 15cm
   The speed of sound is taken to be 340m/s
   delta is measured in steps of 16us
   
   Thus, the expected delta becomes  0.15 * sin(a) / 340 / 16e-6
   
     a                            expected delta 
                                                
     0    right ear, delta: 1         0         
     0    right ear, delta: 0         0         
     0    right ear, delta: 1         0         
     0    right ear, delta: 1         0         
    15    left ear, delta: 6          7         
    15    left ear, delta: 6          7         
    30    left ear, delta: 12        13         
    30    left ear, delta: 12        13         
    45    left ear, delta: 19        19         
    45    left ear, delta: 19        19         
    60    left ear, delta: 23        23         
    60    left ear, delta: 24        23         
    75    left ear, delta: 39        26         
    75    left ear, delta: 38        26         
    90    left ear, delta: 55        27         
    90    left ear, delta: 55        27         

Quite impressive for angles up to 60 degrees. At higher angles, the circuit board itself apparently interfered with the sound, delaying the recognition.

Another interesting possibility is direction finding with a single `ear.' The procedure described below was tried with specially written software, and did work. There is a little drift in the numbers caused by the crystal clocks of chirper and Spider not running exactly in step, but timing accuracy was such that a Spider moving just 15 centimeters between chirps could easily `hear' what it was doing.

Suppose that instead of the transponder, we use a much simpler device that chirps once every 10 seconds exactly. The Spider - itself silent and equipped with just one ear - knows that interval, and starts listening for the second chirp 10s - 8ms after the first has been received. It listens for just 16ms, makes a move, listens for the third chirp 10s - 8ms after receiving the second, then compares the two intervals. The sums:

The chirper chirps at T1. The sound takes d1 seconds to arrive at the Spider and be recognized. 10 seconds later, at T2, the transmitter chirps again. This sound is recognized by the Spider at T1 + 10s + d2. The Spider perceives the interval between the two chirps to be 10s + d2 - d1 = 10s, because the Spider didn't move, so d1 is exactly as long as d2. As the chirp will arrive after about half of the 16ms listening period has passed, it will register for instance 130 (about half of 256).

Now suppose that after receiving a chirp, the Spider moves closer to the transmitter, before receiving the next chirp. The first chirp is again recognized at T1 + d1 seconds, and the next at T1 + 10s + d2 seconds. But this time d2 is a little shorter than d1, because the Spider moved closer to the source. So 10s + d2 - d1 is a little less than 10 seconds, and registers let's say 123. The Spider compares this to the previously registered 130 and knows it has moved closer to the source. A successive approximation algorithm consisting of turns and walks could be used to achieve the shortest possible route towards the target.

Each time the spider stops between chirps, the time difference will be exactly 10s again, independent of the Spider's new position, resulting in registering 130. The distance measured is only relative - but it could still be useful for certain applications.

Top

 

Thanks to...

Finally, a word of thanks to Ken Huntington, for coming up with the method used for measuring distance, confirming the performance of the amplifier and filter circuits, and providing great feedback during development. I would also like to thank various contributors to the BEAM mailing list for bringing up the idea of using sound, and making me take it seriously :)

So how about a complete Spider control board, and a walking prototype? I'm working on it...

previous (Spider vision) / next (IR `radar')