Final Robot Design
Final Robot Integration and Design
All the information for the final robot integration and base station can be found on the Lab 4/Milestone 4 webpage. The only missing part is in regards to the microphone which will be discussed here.
FFT and Microphone Integration
The last step of our robot integration process involved adding the FFT tone detection algorithm into the rest of the code. We didn't have to change much from the code that we used in lab 2. The main change that we had to make involved saving the values of the adc registers before changing them for the FFT detection and then changing the values of the registers back to their original setting so that the rest of the robot's functionality wouldn't be compromised.
The code for the FFT integration and a video of the working tone detection is shown below.
// Detection of 950Hz tone
bool FFT_start(){
old_TIMSK0 = TIMSK0;
old_ADCSRA = ADCSRA;
old_ADMUX = ADMUX;
old_DIDR0 = DIDR0;
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
while(1) { // reduces jitter
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fft_input[i] = k; // put real data into even bins
fft_input[i+1] = 0; // set odd bins to 0
}
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_log(); // take the output of the fft
sei();
pushButtonInput=digitalRead(pushButtonPin);
if(pushButtonInput == HIGH || fft_log_out[7] >= 130){
//digitalWrite(led, HIGH);
// Restore old values
TIMSK0 = old_TIMSK0;
ADCSRA = old_ADCSRA;
ADMUX = old_ADMUX;
DIDR0 = old_DIDR0;
return true;
}
else{
//digitalWrite(led, LOW);
// Restore old values
TIMSK0 = old_TIMSK0;
ADCSRA = old_ADCSRA;
ADMUX = old_ADMUX;
DIDR0 = old_DIDR0;
return false;
}
}
// Restore old values
TIMSK0 = old_TIMSK0;
ADCSRA = old_ADCSRA;
ADMUX = old_ADMUX;
DIDR0 = old_DIDR0;
}
FFT Tone Detection Code
FFT Tone Detection Video
Round 1 Competition Footage
Our robot starts in the top left corner during round 1.
Round 1 Base Station Display
Round 2 Competition Footage
Our robot starts in the bottom left corner during round 2.
Round 3 Competition Footage
Our robot starts in the top right corner during round 3. Our video footage is very short because we had some initial issues with line following, but ultimately were able to get back on track after restarting!
Group Picture