Extra Feature #1: Music Controlled Steering
5/4/2010
For our first extra feature, we decided to try to control steering based on the pitch of an instrument being played nearby the car. We used the built-in microphone on the board (which is linked to the ADC) to pick up sound, and this sound was sent through the wireless serial to be processed on the base station (since it would have been a pain to program any DSP routines on the board itself due to its limited memory and slow processing power). During research, we found out that the ADC has a lowpass filter of 4000hz built into it, so we sampled the sound from the ADC at 8000hz (twice that Nyquist Rate) using an Interrupt timer with a period of 125 microseconds. We also set it to be 8-bit samples so that they could easily be sent on the byte without byte-packing and unwrapping.
8000hz 8-bit sound would require a baud rate of 64000, which is beyond the capability of our 38500 baud rate serial. Therefore we sent the sound out in chunks instead; we had a double buffering scheme set up where the board would be continually sampling the sound and sending it out as fast as it could. There were gaps in between the chunks of sound that got sent out because of the limited baud rate, and this caused noise, but the hope was that periodic modes could still be identified even in the face of missing data.
On the base station end, a serial library was used in Java called “Java Communications” which is an add-on library that we had to install:
http://java.sun.com/products/javacomm/index.jsp
We read in data through a data input stream and displayed it to the screen as a waveform.
We then did our own Cooley-Tukey in-place FFT in Java, doing a real-time transform of length 512 as soon as data came in. At first we though we could identify frequency peaks and correlate turning directly to them, but finding individual FFT bins that were peaks turned out to be difficult. So instead, we decided to reduce the problem to finding a range of the spectrum that had the most power, and to map each one of these ranges to a specific turning direction. The idea was that each range would be ten musical halfsteps wide (5 to the left and 5 to the right), and that there would be five ranges: hard left, soft left, center, soft right, hard right. If we had a signal that was “loud” enough (loudness was determined by variance of the signal), we would attempt to figure out which one of these regions had the most power and to tell the car to turn in the corresponding direction.
5/6/2010
We had a slight problem getting the car to listen to communications going back to it; so we repeat each turning command that we want to give it about 30 times and that seems to fix the problem
Here is a screenshot of our program running on the base station. On top the waveform is displayed (note its periodicity), on the bottom the FFT is displayed. In the FT window, there are 6 vertical lines drawn to mark out the 5 regions of turning, with the leftmost being turning hard left and the rightmost being turning hard right. Note how their width increases exponentially since we hear pitches on a logarithmic scale.
References:
FFT: http://www.librow.com/articles/article-10
Serial Library: http://www.seattlerobotics.org/Encoder/200205/gbcam.html