Boe-Bot Whisker Roaming Help
Sabbobot
Posts: 3
So I have a USB Board of Education Boe-Bot with the whisker sensor circuit built, but I have run into trouble programming it to roam on its own. Parallax provides a roaming navigation code in their student guide along with a version with a "corner" failsafe for getting out of a corner (in which the boe bot would turn left then right then left again etc). I modified this program to have a "trap" failsafe (so that the Boe-Bot does not get stuck going back and forth between two parallel walls). Also, I added certain beeps and LED flashes to signal certain things like the start and end of an evasive maneuver or to count how many times the robot has gone back between two parts of the corner or the parallel walls. Corner escaping and both whiskers are individually working just fine, but the Boe-Bot refuses to ever register a double whisker press, whether to do a regular turn around or to do something in the trap counter. Instead it registers one or the other and completes those commands. When running the basic version (no LEDs, beeps, or failsafes) of the code that Parallax provides, it registered one and both whisker presses without a problem. I tried rebuilding the circuit, and retesting, same thing occurred. Help!
'-----[Variables]------------------------------------------------------------------------------------ pulseCount [B]VAR[/B] [B]BYTE[/B] cornercounter [B]VAR[/B] [B]NIB[/B] trapcounter [B]VAR[/B] [B]NIB[/B] counter [B]VAR[/B] [B]NIB[/B] MEM7 [B]VAR[/B] [B]BIT[/B] MEM5 [B]VAR[/B] [B]BIT[/B] '-----[ Initialization ]----------------------------------------------------------------------------- [B]FREQOUT[/B] 4, 2000, 3000 'Brownout and program start/reset indicator cornercounter = 1 'Set to 1 so that the for ... next loop can run trapcounter = 1 'Set to 1 so that the for ... next loop can run MEM7 = 1 MEM5 = 0 '-----[ Main Routine ]------------------------------------------------------------------------------- '----------[ Corner Escaping ]----------------------------------------------------------------------- DO [B]IF[/B] ([B]IN7[/B] <> [B]IN5[/B]) [B]THEN[/B] ' One or other is pressed [B]IF[/B] (MEM7 <> [B]IN7[/B]) [B]AND[/B] (MEM5 <> [B]IN5[/B]) [B]THEN[/B] ' Different from previous [B]FOR[/B] counter = 1 [B]TO[/B] cornercounter ' Run this loop how ever many times the cornercounter is [B]FREQOUT[/B] 4, 750, 5000 ' Short high beep to mark the cornercounter [B]HIGH[/B] 10 ' Flash both lights to mark the cornercounter [B]HIGH[/B] 1 [B]PAUSE[/B] 400 [B]LOW[/B] 10 [B]LOW[/B] 1 [B]NEXT[/B] cornercounter = cornercounter + 1 ' Alternate whisker count + 1 MEM7 = [B]IN7[/B] ' Record this whisker press MEM5 = [B]IN5[/B] ' for next comparison [B]IF[/B] (cornercounter > 4) [B]THEN[/B] ' If alternate whisker count = 4 cornercounter = 1 ' Reset whisker counter [B]FREQOUT[/B] 4, 1250, 3000 ' Beep to signal that an obstacle was detected [B]HIGH[/B] 10 ' Light both LED indicators [B]HIGH[/B] 1 [B]GOSUB[/B] B_U ' Execute a U-turn [B]GOSUB[/B] T_L [B]GOSUB[/B] T_L ENDIF ' ENDIF counter > 4 ELSE ' Not alternate, reset counter cornercounter = 1 MEM7 = [B]IN7[/B] ' Record this whisker press MEM5 = [B]IN5[/B] ' For next comparison anyway ENDIF ' ENDIF (MEM7<>IN7) AND (MEM5<>IN5) ENDIF ' ENDIF (IN7<>IN5) '----------[ Trap Escaping ]------------------------------------------------------------------------- [B]IF[/B] ([B]IN5[/B] = 0) [B]AND[/B] ([B]IN7[/B] = 0) [B]THEN[/B] ' Both whiskers detect an obstacle [B]IF[/B] (MEM5 = [B]IN5[/B]) [B]AND[/B] (MEM7 = [B]IN7[/B]) [B]THEN[/B] ' Both whiskers were pressed last time as well [B]FOR[/B] counter = 1 [B]TO[/B] trapcounter ' Run this loop how ever many times the trapcounter is [B]FREQOUT[/B] 4, 750, 5000 ' Short high beep to mark trapcounter [B]HIGH[/B] 10 ' Flash both lights to mark the trapcounter [B]HIGH[/B] 1 [B]PAUSE[/B] 400 [B]LOW[/B] 10 [B]LOW[/B] 1 [B]NEXT[/B] trapcounter = trapcounter + 1 ' Double whisker count + 1 MEM7 = [B]IN7[/B] ' Record this whisker press MEM5 = [B]IN5[/B] [B]IF[/B] (trapcounter > 3) [B]THEN[/B] ' If double whisker count = 3 trapcounter = 1 ' Reset whisker counter [B]FREQOUT[/B] 4, 1250, 3000 ' Beep to signal that an obstacle was detected [B]HIGH[/B] 1 ' Light the left LED indicator [B]GOSUB[/B] B_U ' Execute left turn [B]GOSUB[/B] T_L [B]FREQOUT[/B] 4, 1250, 3000 ' Beep to signal resume of normal forward movement ENDIF ' ENDIF counter > 3 ELSE ' Not 3 consecutive times trapcounter = 1 ' Reset counter MEM7 = [B]IN7[/B] ' Record this whisker press MEM5 = [B]IN5[/B] ' For next comparison anyway [B]FREQOUT[/B] 4, 1250, 3000 ' Beep to signal that an obstacle was detected [B]HIGH[/B] 10 ' Light both LED indicators [B]HIGH[/B] 1 [B]GOSUB[/B] B_U ' Back up & U-turn (left twice) [B]GOSUB[/B] T_L [B]GOSUB[/B] T_L [B]FREQOUT[/B] 4, 1250, 3000 ' Beep to signal resume of normal forward movement ENDIF ' ENDIF (MEM5 = IN5) and (MEM7 = IN7) ENDIF ' ENDIF (IN5 = 0) and (IN7 = 0) '----------[ Regular Roaming ] ---------------------------------------------------------------------- [B]IF[/B] ([B]IN5[/B] = 0) [B]THEN[/B] ' Left whisker contacts [B]FREQOUT[/B] 4, 1250, 3000 ' Beep to signal that an obstacle was detected [B]HIGH[/B] 1 ' Right reverse light [B]GOSUB[/B] B_U ' Back up & turn right [B]GOSUB[/B] T_R [B]FREQOUT[/B] 4, 1250, 3000 ' Beep to signal resume of normal forward movement ELSEIF ([B]IN7[/B] = 0) [B]THEN[/B] ' Right whisker contacts [B]FREQOUT[/B] 4, 1250, 3000 ' Beep to signal that an obstacle was detected [B]HIGH[/B] 10 ' Left reverse light [B]GOSUB[/B] B_U ' Back up & turn left [B]GOSUB[/B] T_L [B]FREQOUT[/B] 4, 1250, 3000 ' Beep to signal resume of normal forward movement ELSE ' Both whiskers 1, no contacts [B]GOSUB[/B] P_F ' Apply a forward pulse [B]LOW[/B] 10 ' Both lights turned off [B]LOW[/B] 1 ENDIF LOOP ' and check again '-----[ Subroutines ] ------------------------------------------------------------------------------- [B]P_F:[/B] [B]PULSOUT[/B] 13,850 [B]PULSOUT[/B] 12,655 [B]PAUSE[/B] 20 [B]RETURN[/B] [B]T_L:[/B] [B]FOR[/B] pulseCount = 0 [B]TO[/B] 19 [B]PULSOUT[/B] 13, 666 [B]PULSOUT[/B] 12, 655 [B]PAUSE[/B] 20 [B]NEXT[/B] [B]RETURN[/B] [B]T_R:[/B] [B]FOR[/B] pulseCount = 0 [B]TO[/B] 19 [B]PULSOUT[/B] 13, 850 [B]PULSOUT[/B] 12, 850 [B]PAUSE[/B] 20 [B]NEXT[/B] [B]RETURN[/B] [B]B_U:[/B] [B]FOR[/B] pulseCount = 0 [B]TO[/B] 40 [B]PULSOUT[/B] 13, 666 [B]PULSOUT[/B] 12, 850 [B]PAUSE[/B] 20 [B]NEXT[/B] [B]RETURN[/B]
Comments
Why did you change the variable old5, old7, and counter to MEM5, MEM7, and cornercounter? There was nothing wrong with the old names and the text clearly explains what the code.
I saw that added signaling for when the Boe-Bot encounters a corner and when it executes the escape maneuver, but I don't understand why in the ELSE portion you added the recording of the whisker presses. Nothing had changed if the ELSE is executed so resaving the whisker presses does nothing.
The next section has me really confused. I can understand the escaping from the 2 parallel walls but why are you doing a U-Turn if you are not stuck?
And I also don't understand why you broke up the long IF...THEN...ELSEIF...ELSE...ENDIF in 2 piecies. You added an ENDIF and then changed an ELSEIF to an IF.
Thank you for the reply.
The variables old5 and old7 were not changed to MEM5 and MEM7 for any particular reason. I have changed them and some other things back to their original states.
I changed the counter to cornercounter because I needed two separate counters (one for the corner escaping and one for the trap escaping). If the counters were the same, four presses of any kind would trigger the escaping maneuver.
As for the secondary saving of the memory in the ELSE portion, I do that to make use of the single memory slot for each whisker. With the memory saving in the first loop, the Boe-Bot only remembers the press providing that the first conditions are met. In this case, the Boe-Bot will never remember a single press if the first is a double, or a double press if the first is a single. Since I initialize old7 and old5 and 0 and 1, if I don't have the memory saved there, trap escaping will never work.
I tried to answer most of what I could answer in comments placed next to your commented questions in the code posted (I will re-post the changed code below), and changed anything you thought I should change or noted was different.
One last note you have probably noticed from my code that I am relatively new at this, so most things - with the exception of a few that I can explain - that seemed/seem counter-productive, redundant, or like they make no sense probably are so because I don’t know any better. If you have any other discrepancies with the code please point them out.
http://boebotteacher.com/Animation-EscapeCorners.aspx