Chapter 5: Tactile Navigation with Whiskers · Page 191
To modify the Main Routine, replace the three GOSUB commands under the first
IF condition with this single line:
GOSUB Turn_Away
P1. The key to solving this problem is to write a statement that makes a beep with
the required parameters:
FREQOUT 4, 100, 4000 ' 4kHz beep for 100ms
This statement must be added to the Main Routine in the appropriate places, as
shown below. The rest of the program is unchanged.
' -----[ Main Routine ]----------------------------------------
DO
IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect
FREQOUT 4, 100, 4000 ' 4 kHz beep for 100 ms
FREQOUT 4, 100, 4000 ' Repeat twice
GOSUB Back_Up ' Back up & U-turn
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN ' Left whisker contacts
FREQOUT 4, 100, 4000 ' 4 kHz beep for 100 ms
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN ' Right whisker contacts
FREQOUT 4, 100, 4000 ' 4 kHz beep for 100 ms
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both whiskers 1, no
GOSUB Forward_Pulse ' contacts
ENDIF ' Apply a forward pulse
LOOP ' and check again
P2. We found from Chapter 4 Projects that a 1 yard circle can be achieved with
PULSOUT 13, 850 and PULSOUT 12, 716. Using these values as the 1y circle,
the radius can be adjusted by slightly increasing or decreasing the pulse width
from the starting value of 716. Each time a whisker is pressed the program will
add or subtract a bit from the right wheel's pulse width.
In the solution below, an audible beeping indicator was added. This acts as
feedback to verify that the whisker was pressed. This is entirely optional.