Integrate the following sensors and functionality:
2 × Parallax servo --> movement
3 × Digital line sensor --> line tracking
1 × IR phototransistor --> robot detection
1 × Microphone --> 660 Hz detection
3 × IR range finder --> wall detection
Demonstrate a robot that successfully circles an arbitrary set of walls
through right-hand wall following, while performing line tracking, and
detection and avoidance for other robots and walls.
Wall Detection
We installed three IR range finders on our robot
Pointing straight ahead (in direction of movement)
To the left
To the right
This arrangement allows us to detect both the presence and absence of walls around our robot
We created two functions (with fairly self explanatory names) that read data from the range finders to detect walls:
detect_wall_3in(int pin)
detect_wall_6in(int pin)
NOTE - we experimented with this setup to calibrate the threshold values
Our IR range finder code is as follows:
#define VAL_6_INCH 100
#define VAL_3_INCH 200
#include "ir_rangefinder.h"
#include
int read_range_sensor(int pin){
return analogRead(pin);
}
bool detect_wall_6in(int pin){
int val = read_range_sensor(pin);
if(val > VAL_6_INCH)
return true;
else
return false;
}
bool detect_wall_3in(int pin){
int val = read_range_sensor(pin);
if(val > VAL_3_INCH)
return true;
else
return false;
}
System Integration - Attempt #1
Create a loop that runs all processes one-after-another
Begin by running the 660 Hz detection using the microphone circuit and mic FFT
Run this continuously until 660 Hz is detected 5 consecutive times
When this occurs, advance to the rest of the code and begin movement
This code will not be run again
Perform line tracking
Perform wall detection
Perform IR robot detection
Analysis:
Results are erratic; solution only partially works
Sometimes line tracking suddenly fails
Sometimes wall detection is too slow to respond
Sometimes IR hat dection is too slow to respond
Hypothesis = the IR_hat FFT function call is affecting these processes
The FFT library manually sets the ADC control registers
This breaks the analogRead() function from the Arduino library
Most of our functions utilize analogRead()
Fixing the FFT
The Open Music Labs Arduino FFT changes values in the following ADC control registers
ADCSRA
ADMUX
TIMSK0
DIDR0
This causes the PWM library’s timer to not function correctly since it uses the same timer registers
As a result, the servos do not behave in the intended manner
Our solution stores the ADC register values before calling the FFT function
We restore the ADC registers after the FFT function completes
System Integration - Attempt #2
GOAL: a robot that recognizes 660 Hz, does line tracking, and avoids robots and walls
After implementing the afromentioned FFT code fix, we further refined our main loop
Wait to begin operations until detect_660hz() returns TRUE 5 consecutive times
The green LED indicates that 660 Hz was detected
This is run in a separate loop from the below code
It is never run again
Check the line sensors and range finders - our conditional logic is:
// wall detected at intersection
if ((sensorStatus[0] == 0) && (sensorStatus[1] == 0) && (sensorStatus[2] == 0) && detect_wall_6in(3) ) {
if (detect_wall_6in(1)){
turnLeftIntersection(servo_L, servo_R);
}
else{
turnRightIntersection(servo_L, servo_R);
}
}
// wall detected but not at an intersection
else if (detect_wall_3in(3)) {
turnLeft(servo_L, servo_R);
}
// no wall detected --> just track the line
else if (sensorStatus[0] == 0) //turn Right
adjustRight(servo_L, servo_R, 85);
else if (sensorStatus[2] == 0) //turn Left
adjustLeft(servo_L, servo_R, 85);
else {
moveForward(servo_L, servo_R);
}
Run detect_6080hz() to check for other robots
This process is run in a while loop
Our robot will stop moving and continuously check for the presence of another robot
The red LED indicates that 6080 Hz is detected
When no robot is detected anymore, our robot will resume normal operations
NOTE - The IR detection circuit does correctly recognize the IR hat (another robot) and stop our robot
The physical location of the phototransistor, however, is obstructed by other components
This explains the difficulty Kenneth has getting the IR to be recognized
We plan on moving the phototransistor to a more optimal, unobstructed location in the front of our robot