Nesting loops in Boe-Bot whisker navigation
Robostooge
Posts: 3
Greetings. We are new to Basic Stamp and the forum. We are going through the Boe-Bot Manual, and have a question about using whisker navigation. We used the code from the manual (Example Program: RoamingWithWhiskers.bs2, page 192 of the Acrobat version). The whisker navigation works great, and we decided to add flashing LED’S. (LED’S continually flash as the Boe- Bot moves)
·
We used the following code to flash LED’s
·
Do
High 1························· ‘LED ·1 on
High 10······················· ‘LED 2 on
Pause 500
Low 1························· ‘LED off
High 10······················· ‘LED off
Pause 500
Loop
·
This code works on it’s own, but we can’t seem to figure out where to put it without it messing up the main program or the subroutines.
·
In other words, we want the flashing LED subroutine to be continuously executed as the whisker decision trees for the navigation work independently.
·
We’ve tried it at every place in the program we can think of, and it messes up the subroutines.
·
Are we missing something basic or is this actually more complicated to do than we think?
·
PS we did not write out the code from the book to save space, but can if that will help get the question answered.
Any ideas?
Many thanks
·
We used the following code to flash LED’s
·
Do
High 1························· ‘LED ·1 on
High 10······················· ‘LED 2 on
Pause 500
Low 1························· ‘LED off
High 10······················· ‘LED off
Pause 500
Loop
·
This code works on it’s own, but we can’t seem to figure out where to put it without it messing up the main program or the subroutines.
·
In other words, we want the flashing LED subroutine to be continuously executed as the whisker decision trees for the navigation work independently.
·
We’ve tried it at every place in the program we can think of, and it messes up the subroutines.
·
Are we missing something basic or is this actually more complicated to do than we think?
·
PS we did not write out the code from the book to save space, but can if that will help get the question answered.
Any ideas?
Many thanks
Comments
Recall from Chapter 2, Activity #6 that servo pulses repeat about every 25 ms.· To delay for 0.5 seconds, this program's Flash_Leds subroutine·counts up to 20 servo pulses (20 x .025 s = 0.5 s), then changes the state of the LEDs.· The Flash_Leds subroutine is called from everywhere the program delivers a servo pulse.· More importantly, the program is doing it from inside the various FOR...NEXT loops.· If those Flash_Leds subroutine calls were outside the FOR...NEXT loops, there would be interruptions in the flashing every time a maneuver was executed.
BTW, another interesting modification is to light up the left LED while the Boe-Bot is avoiding an object on the left, the right LED while the Boe-Bot is avoiding an object on its right, etc.
Post Edited (Andy Lindsay (Parallax)) : 1/23/2006 4:05:00 AM GMT