Make your own free website on Tripod.com
Back to Fighter Bot Design Notes Back to TRCY Homepage FighterBots.gif (18739 bytes)

Sir Dinadan     Sir Sagramore

Programming sure is neat!  But you have to understand some basic building blocks and know the logic of programming.  If you don't know those things, programming can be like trying to drill through concrete with a tooth pick!  I will not go into teaching programming here, because I myself am still very much a student of the subject.   I do hope to include here in coming months tips and short tutorials on programming structure. For any Basic Stamp a fantastic book for a beginner is, Programming and Customizing the Basic Stamp Computer, by Scott Edwards.

Programming Structure:
The first thing you want to do in a program like this is declare what everything is or stands for, so it can be used throughout the program. This includes declaring the pin states (such as which are input or output), variables and constants (and their symbols).   After you declare what your set perimeters are for your program then you write out all the steps involved.  Then you improve it by using statements that shorten the length of your code. 

Tips:
No Tips yet.

You'll find the different complete programs the Fighter Bots of TRCY use on this page. When code is complete it will be available for downloading in .bas format.  Below is my best program for my Sir Dinadan to date.  It commands my fighter to roam around in a forward direction.  If the IR vision sensor picks up something to left or right the robots turns toward the object to bring it into full view the fighter than plunges forward.  If the shut off switches are hit they "die".  Also inserted are the commands to make the robot stay in the ring, via the IR edge detectors.  If the bot sees the black edge of the ring, the bot backs up and turns right. 

I stole this code from the Lynxmotion Carpet Rover because I was having problems getting the my IR vision sensor to work in my other programs. 

This is not exactly how I want to my fighter to roam around searching for other bots, but for now it works.  It also eats up about 3/4 of the program space on my Basic Stamp I. 


Sir Dinadan's Program
Code Last updated October 8th:

Program Name = Dinadan1.BAS
'This program uses part of the Lynxmotion Carpet Rover program
'Converted code that helped Dinadan win two test fight against Dennis's bot Evil Empire

dirs = %11000011 'pin0-1 = output, pin2-5 = input, pin6-7 = output

'* Pin Allocation *
'pin0 Right Wheel
'pin1 Left Wheel
'pin2 Right IR Edge Detector
'pin3 Left IR Edge Detector
'pin4 Motor shut off
'pin5 IR Sensor Input
'pin6 Left IR LED
'pin7 Right IR LED

'* Initialize Symbols *
symbol templ = b0            'holds left IR det/passes to step
symbol tempr = b1            'holds right IR det/passes to step
symbol left_center_pos = b2        'left center position value
symbol right_center_pos = b3        'right center position value
symbol avoid = b8            'holds behavour value
symbol tempm = b9            'pass to step
symbol x = b10                 'general purpose
symbol y = b11                 'general purpose

'* Initialize Variables *
left_center_pos = 155             'Adjust these for center of throw
right_center_pos = 139            '

'temp:                                      'Use this to adjust the servos if you need to
' templ = left_center_pos        'stop value (center of throw)
' tempr = right_center_pos
' for x=1 to 30
' pulsout 0,tempr
' pulsout 1,templ
' pause 10
' next x
'goto temp

pause 100
start:
if pin4=1 then dead
if pin2=1 then edge
if pin3=1 then edge
tempr = 0
for x=1 to 10
pin7 = 1
tempr = tempr + pin5
pin7 = 0
next x
templ = 0
for x=1 to 10
pin6 = 1
templ = templ + pin5
pin6 = 0
next x
avoid = 0
if templ>7 then avoid1
avoid = avoid + 1
avoid1:
if tempr>7 then avoid2
avoid = avoid + 2
avoid2:
branch avoid,(forward,turn_right,turn_left,backup)
goto start

forward:
templ = left_center_pos - 50
tempr = right_center_pos + 50
for x=1 to 15
pulsout 0,tempr
pulsout 1,templ
pause 10
next x
goto start

turn_right:
templ = left_center_pos - 40
tempr = right_center_pos - 40
for x=1 to 15
pulsout 0,tempr
pulsout 1,templ
pause 10
next x
goto start

turn_left:
templ = left_center_pos + 40
tempr = right_center_pos + 40
for x=1 to 15
pulsout 0,tempr
pulsout 1,templ
pause 10
next x
goto start

backup:
templ = left_center_pos - 50
tempr = right_center_pos + 50
for x=1 to 50
pulsout 0,tempr
pulsout 1,templ
pause 15
next x
' templ = left_center_pos + 20       This was part of the rover code, but I don't need it right not so it is being ignored
' tempr = right_center_pos - 20      This backup sub loop is what makes my robot plunge forward at opponents
' for x=1 to 30
' pulsout 0,tempr
' pulsout 1,templ
' pause 10
' next x
goto start

edge:
templ = left_center_pos + 50
tempr = right_center_pos - 50
for x=1 to 50
pulsout 0,tempr
pulsout 1,templ
pause 15
next x
templ = left_center_pos + 20
tempr = right_center_pos + 20
for x=1 to 30
pulsout 0,tempr
pulsout 1,templ
pause 10
next x
goto start

dead:
templ = left_center_pos
tempr = right_center_pos
end

 


Sir Sagramore's Program
Code Last updated October 15th:

This program is designed for Sir Sagramore who now has a servo positioned motion sensor hacked from a toy line called SpyTech (no longer sold)  This is the first functional code that makes Sagramore first look forward, left, then right until he sees movement.  He then turns toward the movement and heads forward.  If nothing happens he stops and begins to search for movement again.  

The toy sensor was designed to sound an alarm buzzer for a few seconds or for as long as motion is detected.  The Basic Stamp is wired to the leads to the buzzer which get 1.5 volts for a high reading.  The problem is that when the servo moves the sensor, the alarm of course goes off.  So I have used a lot of counting for-next loops in this program to make Sagramore move his head and ignore the sensor for a short while to make sure the sensor calms down, then for a few more seconds watch pin5 for a high, this repeats untill he sees something. 

This method eats up all of my code space for the BSI.  It also slows down Sagramore far more than I would like.  It's hard to watch him fight when he just sits there looking for other faster robots in the fighting ring.  Never the less it does work.  I have one open i/o pin I could use for a transistor or relay to turn the power to the sensor on and off when he moves his head, but I fear that would only eat up my extra pin and not give me much code space in return.  If you have any suggestions, please e-mail me.

'Sir Sagramore's Figter Program/Vision Program
'Created by Justin Ratliff 10.15.99

INPUT PIN2
INPUT PIN3
INPUT PIN4
INPUT PIN5

' ==Variables and Constants
SYMBOL mot_L = b7      ' Left-motor speed.
SYMBOL mot_R = b6      ' Right-motor speed.
SYMBOL mot_H = b5      ' Head-motor speed.
SYMBOL Lp = 0               ' Left-motor pin.
SYMBOL Rp = 1               ' Right-motor pin.
SYMBOL Hp = 6               ' Head-motor pin.
SYMBOL ticks = b8

'==Main Program Loop
Main:
'==look foward==
for ticks = 1 to 250       
mot_H = 160
pulsout Hp,mot_H
if PIN4=1 then dead
pause 15
next
for ticks = 1 to 250
if PIN4=1 then dead
if PIN5=1 then forward
pause 15
next
'==looking left==
for ticks = 1 to 250
mot_H = 100
pulsout Hp,mot_H
if PIN4=1 then dead
pause 15
next
for ticks = 1 to 250
if PIN4=1 then dead
if PIN5=1 then T_left
pause 15
next
'==looking right==
for ticks = 1 to 250
mot_H = 240
pulsout Hp,mot_H
if PIN4=1 then dead
pause 15
next
for ticks = 1 to 250
if PIN4=1 then dead
if PIN5=1 then T_right
pause 15
next
goto main


forward:
for ticks = 1 to 250           
mot_L = 120: mot_R = 180    ' Forward to servos
mot_H = 160
if PIN4=1 then dead
if PIN2=1 then back
if PIN3=1 then back
pulsout Lp,mot_L       
pulsout Rp,mot_R
pulsout Hp,mot_H
pause 15
next
goto Main           

T_left:
for ticks = 1 to 30             
mot_L = 120: mot_R = 120
mot_H = 160
pulsout Lp,mot_L       
pulsout Rp,mot_R
pulsout Hp,mot_H
pause 15
next
goto forward

T_right:
for ticks = 1 to 30             
mot_L = 180: mot_R = 180   
mot_H = 160
pulsout Lp,mot_L       
pulsout Rp,mot_R
pulsout Hp,mot_H
pause 15
next
goto forward

back:
for ticks = 1 to 30
mot_L = 170: mot_R = 130
pulsout Lp,mot_L   
pulsout Rp,mot_R
pause 15
next
goto T_right

dead:
mot_L = 150: mot_R = 150
mot_H = 160
end