You are on page 1of 2

Chapter 8 Challenges

Questions
1. What would the relative sensitivity of the IR detector be if you use tone to send a 35 kHz
signal?
The relative sensitivity at 35 kHz is 30%. For 36 kHz, its 50%.
2. What is the relative sensitivity with a 36 kHz signal?
Precede a variable declaration with the const keyword.
3. What keyword is used to declare a constant?
A for loop that starts indexing at 38000 and increases by 1000 with each repetition..
4. What statement is used to sweep through the list of frequencies used for IR distance
measurements?
A summing junction is a part of a block diagram that indicates two inputs are added together (or
one subtracted from another) resulting in an output.
5. Whats a summing junction?
The error term is the measured level subtracted from the desired set point level.
6. In our closed loop proportional control block diagrams, what two values are used to
calculate the error term?
If a distance sample is taken with each repetition of the loop function, then the delays more or
less determine how long it takes between each sample. Thats called the sample interval, and 1
sample interval = sampling rate.
7. How do delays in the loop function contribute to setting the sampling rate?
The loop make sure everything goes in a loop while the sampling rate slows the loop down
Exercises
1. Write a segment of code that does the frequency sweep for just four frequencies instead
of five.
for(long f = 38000; f <= 42000; f += 1000) {
distance += irDetect(irLedPin, irReceivePin, f);
}

2. Write global constant declarations that initialize kpl as 45 and kpr as 55.
const int setpoint = 2; // Target distances
const int kpl = -45; // Proportional control constants
const int kpr = -55;
Projects
1. Write a sketch that allows you to hold your hand in front of the BOE Shield-Bot and push
it backwards and forwards with no turning.

void loop() // Main loop auto-repeats


{
int irLeft = irDistance(9, 10); // Measure left distance
int irRight = irDistance(2, 3); // Measure right distance

// Left and right proportional control calculations


int driveLeft = (setpoint - irLeft) * kpl;
int driveRight = (setpoint - irRight) * kpr;

int drive = (driveLeft + driveRight)/2; // Average drive levels

maneuver(drive, drive, 20); // Apply same drive to both

delay(10); // 0.1 second delay


}