Now that you've learned how to make the Propeller Boe-Bot react to its whiskers, let's expand on that and make it roam with whiskers. To roam, the Propeller Boe-Bot needs to go forward until it bumps into something. When that happens, it needs to back up, turn away from the obstacle, and then go forward again. While the Propeller Boe-Bot is going forward, it should repeatedly check its whiskers with minimal delays between whisker checks. That way, it can know right away when it has encountered an object.
Stop and Download Updated Whisker Code
The "3 Whisker Navigation.spin" file in PropBOE-Whiskers-2012-05-30.zip has a mistake that makes it turn in place when it should go forward.
- IMPORTANT: Download and unzip this updated replacement whiskers code: PropBOE-Whiskers-2012-06-01.zip. It has the corrected example program.
- Make sure to use this new folder for the rest of the Whisker example programs.
Run the Example Code
- Open your PropBOE-Whiskers-2012-06-01 folder (not the zip file, the folder you unzipped it to), and then open "3 Whisker Navigation.spin" into your Propeller Tool software.
- Set the PWR switch to 1.
- Load the program into your bot's Propeller chip with F11.
- Set the Propeller Boe-Bot on the ground in an area with a few obstacles (that are high enough for the whiskers to bump into).
- Set the power switch to 2.
- Observe its roaming behavior.
How it Works
The repeat loop in the Main method has an if...elseif...elseif...else statement that does one of four different navigation routines depending on what combination of whiskers is pressed. If both whiskers are pressed, it makes the Propeller Boe-Bot back up for 1 second, then turn left for 0.8 seconds. If only the left whisker is pressed, it makes the Propeller Boe-Bot back up for 1 second, and then turn right for 0.4 seconds. If only the right whisker is pressed, it makes the Propeller Boe-Bot back up for 1 second, and then turn left for 0.4 seconds. If no whiskers are pressed, it just makes the Propeller Boe-Bot go forward.
'' Excerpt from: 3 Whisker Navigation.spin repeat ' Keep repeating if...else block if pin.In(6) == 0 and pin.In(9) == 0 ' If both whiskers pressed drive.Wheels(-100, -100) ' Back up 1 s time.Pause(1000) drive.Wheels(-100, 100) ' Turn left 0.8 s time.Pause(800) elseif pin.In(6) == 0 ' If only left whisker pressed drive.Wheels(-100, -100) ' Back up 1 s time.Pause(1000) drive.Wheels(100, -100) ' Turn right 0.4 s time.Pause(400) elseif pin.In(9) == 0 ' If only right whisker pressed drive.Wheels(-100, -100) ' Back up 1 s time.Pause(1000) drive.Wheels(-100, 100) ' Turn left 0.4 s time.Pause(400) else ' If no whiskers pressed drive.Wheels(100, 100) ' Just go forward
Did you Know?
There are two other versions of this example program. One starts with 3a, and it uses Maneuver Lists to navigate around obstacles. The other starts with 3b, and it uses Sequence Lists to do the same thing.
When you try to press both whiskers, the Propeller will be checking so quickly that it's really difficult to make them touch the 3-pin header posts at exactly the same time. Try adding time.Pause(30) below drive.Wheels(100, 100). That will give you some extra time to press both whiskers. You'll still need to make a quick, decisive tap of both whiskers so that they touch the 3-pin headers at almost exactly the same time. But with that extra pause, you should be able to get it to make that larger turn it's supposed to when both whiskers are pressed.
- Modify a copy of your program to back up half as far and turn twice as far for every whisker press.