'************************************************************************ '* GrowBot BS2-IC Version * '* BotBash - Novice Class Maze Competition * '* May 5, 2002 * '* * '* TO USE * '* * '* Put switch in "run" mode. * '* Actuate right bumper to be in right wall follow mode. * '* Actuate left bumper to be in left wall follow mode. * '* Default is right wall follow mode. * '* Press the pushbutton to start the robot. * '* * '* HOW IT WORKS * '* * '* The servo motor does not turn if Pulsout is about 750. * '* The right servo needs a value of <750 to go forward. * '* The left servo needs a value of >750 to go forward. * '* Rbumper, Lbumper, button1 inputs are normally a "1", not "0". * '* LED outputs need to be a "1" to illuminate them. * '* Radius of curves also depends on freshness of batteries. * '* * '* CODE DOCUMENTATION * '* * '* For right wall follow the bot is mostly in the CurveRight * '* routine. When the right wall is bumped, it turns slightly to * '* the left using Lbkup, then jumps into CurveRight again. * '* * '* * '* * '* * '* GROWBOT PROGAMMING STATUS * '* * '* Bumpers - Yes * '* Does corner case 1-5 * '* Select R or L wall - Yes * '* Calibrate left wall follow speeds - Yes * '* Line sensors - No * '* Wait and song before start - Yes * '* Victory dance/song - No * '* * '************************************************************************ 'Define Movement I/O Lbumper var in9 ' Left Bumper Rbumper var in10 ' Right Bumper Rled con 11 ' Right LED rightWheel con 13 ' Right Wheel (servo) leftWheel con 12 ' Left Wheel (servo) Lled con 15 ' Left LED 'Define Music I/O spkr con 8 ' speaker output pin button1 var in14 ' start button 'Define Music Constants and Variables Db4 con 1102 ' Notes Gb4 con 1476 G4 con 1563 A4 con 1754 Bb4 con 1856 BE4 con 1960 C5 con 2084 Db5 con 2204 D5 con 2326 G5 con 3126 R con $FF indx var byte tune var byte note var word dura var word 'Define Movement RAM used temp var byte ' Temporary Byte speedl var word ' Holds desired speed of left drive speedr var word ' Holds desired speed of right drive counter var byte ' a counter tomuch var byte ' counter for case 5 wall turns wall var bit ' 0 is right wall follow, 1 is left (just need one bit) 'Define Movement Constants rightOff con 750 ' "off" pulse for servo leftOff con 750 ' "off" pulse for servo Init: dirh = $B9 'Set I/O directions outh = $00 'Set outputs = OFF tune = 0 wall = 0 'Default mode is right wall follow - may not need DELAY: note = 0 dura = 0 indx = 0 pause 200 READWALL: 'Detect bumper to decide R or L wall follow if Rbumper = 0 then Lwall 'left bumper hit if Lbumper = 0 then Rwall 'right bumper hit if button1 = 0 then PLAY 'Read pushbutton to start goto READWALL Rwall: out15 = 1 'Turn on Left LED wall = 0 'Set code for right wall follow pause 500 'Keep LED on for 1/2 second out15 = 0 'Turn left LED off goto READWALL Lwall: out11 = 1 'Turn on Right LED wall = 1 'Set code for left wall follow pause 500 'Keep LED on for 1/2 second out11 = 0 'Turn right LED off goto READWALL PLAY: 'Wait for 5 seconds before starting movement pause 5000 goto LOOP LOOP: 'Play song. Get the next note to be played gosub GetSong 'for the selected song and play if note = 0 then Main 'it. if note = R then REST freqout spkr,dura,note NXT: indx = indx + 1 goto LOOP REST: pause dura goto NXT GetSong: if tune = 1 then Song1 Song0: lookup indx,[Db4,Gb4,Bb4,Db5,R,Bb4,Db5,0],note lookup indx,[150,150,150,300,9,200,600],dura return Song1: lookup indx,[ G4, D5, C5,BE4, A4, G5, D5, C5,BE4, A4, G5, D5, C5,BE4, C5, A4,0],note lookup indx,[800,800,150,150,150,800,800,150,150,150,800,800,150,150,150,800],dura return Main: out15 = Lbumper^1 'If Lbumper = 0 then Lled = ON out11 = Rbumper^1 'If Rbumper = 0 then Rled = ON RightWall: 'if Lbumper = 0 and Rbumper = 0 then backup 'both bumpers hit 'backup removed since not needed if NOT wall = 0 then LeftWall if Rbumper = 0 then Rbkup '-left bumper hit if Lbumper = 0 then Lbkup '-right bumper hit if tomuch > 80 then FindWall '150 is too big CurveRight: 'to go straight temp = 2 : speedl = 100 : speedr = -65 'keep speedr between 40-60 gosub drive 'lower speedr is smaller radius tomuch = tomuch + 1 goto Main LeftWall: if Rbumper = 0 then RbkupLeft 'left bumper hit if Lbumper = 0 then LbkupLeft 'right bumper hit if tomuch > 80 then FindWallLeft '150 is too big CurveLeft: 'to go straight temp = 2 : speedl = 50 : speedr = -100 'keep speedl between 40-60 gosub drive 'lower speedl is smaller radius tomuch = tomuch + 1 goto Main Rbkup: temp = 50 : speedl = -100 : speedr = -50 'to get out of corner gosub drive tomuch = 0 goto Main RbkupLeft: temp = 50 : speedl = 70 : speedr = 70 'spin to right gosub drive '70 and 70 tomuch = 0 goto Main Lbkup: temp = 50 : speedl = -70 : speedr = -70 'spin to left gosub drive '70 and 70 tomuch = 0 goto Main LbkupLeft: temp = 50 : speedl = 70 : speedr = 70 'to get out of corner gosub drive ' tomuch = 0 goto Main FindWall: temp = 50 : speedl = 70 : speedr = 70 'spin to right and ... gosub drive temp = 50 : speedl = 100 : speedr = -100 '... go to wall gosub drive tomuch = 0 goto Main FindWallLeft: temp = 50 : speedl = -70 : speedr = -70 'spin to left and ... gosub drive temp = 50 : speedl = 100 : speedr = -100 '... go to wall gosub drive tomuch = 0 goto Main backup: 'NOT USED temp = 200 : speedl = -100 : speedr = 100 gosub drive temp = 100 : speedl = 100 : speedr = 100 gosub drive tomuch = 0 goto Main drive: 'Turn the servos for counter = 1 to temp pulsout leftWheel,leftOff +speedl pulsout rightWheel,rightOff+speedr next return