Datasheet

Tactile Navigation with Whiskers • Chapter 5
Robotics with the BOE Shield-Bot 169
4. What statements did this chapter use to call different navigation functions based
on whisker states?
5. What is the purpose of having nested
if statements?
Exercises
1. Write a routine that uses a single variable named whiskers to track whisker
contacts. It should store a 3 when no whiskers are contacted, a 2 if the right
whisker is contacted, a 1 if the left whisker is contacted, or 0 if both whiskers are
contacted. Hint: multiply the result by two.
2. Modify the
loop function in RoamingWithWhiskers so that it makes the BOE
Shield-Bot stop and not restart when both whiskers contact at the same time.
3. Add a function named
pause to RoamingWithWhiskers. It should make the BOE
Shield-Bot stay still for a certain amount of time.
4. Modify the
loop function so that the BOE Shield-Bot stays still for 0.5 seconds
before backing up and turning.
Projects
1. Modify RoamingWithWhiskers so that the BOE Shield-Bot stops and makes a 4
kHz beep that lasts 100 ms before executing its usual evasive maneuver. Make it
beep twice if both whisker contacts are detected during the same sample. HINT:
Use the
pause function you developed in the Exercises section to make it pause
immediately after the tone starts playing. Also, a 0.2 second pause after the tone
call separates the 0.1 second tone from servo motion, or allows you to hear a
second tone.
2. Modify RoamingWithWhiskers so that the BOE Shield-Bot roams in a 1 yard (or 1
meter) diameter circle. When you touch one whisker, it will cause the BOE
Shield-Bot to travel in a tighter circle (smaller diameter). When you touch the
other whisker, it will cause the BOE Shield-Bot to navigate in a wider diameter
circle.
Question Solutions
1. A normally open, momentary, single-pole, single-throw tactile switch.
2. Zero (0) volts, resulting in binary zero (0) returned by
digitalRead.
digitalRead(8)== 0 when whisker is pressed.
digitalRead(8)== 1 when whisker is not pressed.
3.
digitalRead(7)== 1 means the right whisker is not pressed.
digitalRead(7)== 0 means the right whisker is pressed.
digitalRead(5)== 1 means the left whisker is not pressed.
digitalRead(5)== 0 means the left whisker is pressed.
4. This chapter used
if, if…else, and if…else if…else statements to evaluate
whisker conditions and call navigation functions.