SpamButcher Combat Robotics Home

Autonomous Bastard 2.0

Auto B 2.0 is coming along well. I just installed the new copal drive motors (50:1 metal gears) in the test chassis - surprisingly didn't effect the code that much.

The copals are a bit slower than I'd like - but they're still reasonable when used with 3" wheels and 7.2v. At 11v these motors would be great - but I'm sticking with 2 cells (not feeling like replacing my voltage regulator).

Auto B can now very reliably locate an enemy bot (ok - at least a stationary beer bottle) and then deploy one of several attack sequences.

I think it will be very effective against slower moving bots - faster ones will be much harder to track.

The bot generally does not have trouble confusing the other robot from the arena. I was having trouble with some "noise" from the SRF04 range finder (stray readings that something was much closer than it was) - but this was solved by mounting it back further. I think it sees echos when its mounted entirely out in the open. here's the current source:
(does not include RC interface or weapon control yet)


'auto b 2.0
'this code is free for use
'
'SpamButcher - Get Rid of Unwanted Spam!

Trig  Con P6            ' Define pin for Trigger pulse
Echo  Con P7            ' Define pin for Echo pulse

distance Var Word         ' 16 bit variable for distance
holding Var Word          ' 16 bit variable for hold loop

y var long
x var long
z var long

attack_dist var long

d1 var long
d2 var long

avg_dist var long

randnum var long

semirandom var long

stay0 con 0
stay1 con 0

rturn0 con -750
rturn1 con 0

lturn0 con 750
lturn1 con 0

fwd0 con 0
fwd1 con 750

bk0 con 0
bk1 con -750

motor con 165

sound P9, [100 \ 1200]
sound P9, [100 \ 1500]

'box size
avg_dist = 36

Main


	gosub find_center
	
	sound P9, [100 \ 1500]

	gosub find_target
	
	if y < 100 then	

		sound P9, [25 \ 1500]
		sound P9, [25 \ 2500]
		sound P9, [25 \ 3500]
		
		semirandom = distance.nib0 / 4 
		
		if semirandom = 0 then
			gosub straight
		endif
		if semirandom = 1 then
			gosub oval
		endif
		if semirandom = 2 then
			gosub zigzag
		endif
		if semirandom = 3 then
			mservo 0, 0 \ 750, 22		
			gosub spiral		
		endif
		
		else
		sound P9, [125 \ 2500]
		gosub spiral
	endif
	

goto main

	
find_center:

'back off if needed
	
	gosub sonar
	
	y = 0 
	while distance < 25 and y < 10
		y = y + 1
		mservo 0, 0 \ 700, 4
		gosub sonar
	wend

for z = 1 to 60

	gosub sonar
	
	if distance > avg_dist + 1 then
		mservo 0, 0 \ 600, 4
	endif
	
	
	y=0
	while distance > avg_dist + 1 and y < 12
		y = y + 1
		mservo 0, 0 \ 700, 4
		gosub sonar
	wend
	
	'if going forward for too long, turn around
	if y = 12 then
		mservo 0, 0 \ -600, 15	
		mservo 0, 700 \ 0, 15	
		z = 1
	endif

	mservo 0, 600 \ 0, 1
		
next


return



find_target:

gosub sonar

attack_dist = 17

y = 0
while distance > attack_dist and y < 100
	gosub sonar	
	y = y + 1
		
	mservo 0, -480 \ 0, 2
	
	if y > 40 then
		attack_dist = 20
	endif
	
	if y > 60 then
		attack_dist = 24
	endif
		
	
wend

'compensate
	mservo 0, 440 \ 0, 4



return

	
end

'Free Download Filters Spam


report:

gosub sonar
Serout S_OUT, i9600, ["distance = ", DEC (distance), 13]


goto report




sonar

    high trig   'sends the trigger pulse
    low trig

'loops until the echo pin (IN7) goes high (max of 200 loops in case it never does)

    holding = 0
    waiting:
    IF IN7 = 0 and holding < 200 then
    	holding = holding + 1
    	goto waiting
    endif


'measures distances as a function of how many times the processor
'can loop before the echo pin goes low

'This is a total hack.  Normally rctime or pulsin would be used however, these routines
'seem to be unreliable with the Basic Atom Pro at least for the durations required.
'Stop Unwanted Messages

    distance = 0
    waiting_for_echo:
    IF IN7 = 1 THEN
    	distance = distance + 1
    	goto waiting_for_echo
    endif

    distance = distance / 3	'very roughly converts output to inches

    'Serout S_OUT, i9600, ["Distance = ", DEC distance, 13]    
    
    Pause 20
    
    if distance > 100 then
'    	sound P9, [1500 \ 3500]
    	distance = 1
    endif
    	
return


spiral:
mservo 0, -750 \ 0, 10
mservo 0, 0 \ 750, 10
mservo 0, -750 \ 0, 10
mservo 0, 0 \ 750, 17
mservo 0, -750 \ 0, 10
mservo 0, 0 \ 750, 17
mservo 0, -750 \ 0, 10
mservo 0, 0 \ 750, 33
mservo 0, -750 \ 0, 10
mservo 0, 0 \ 750, 33
mservo 0, -750 \ 0, 10
mservo 0, 0 \ 750, 35
return

oval:
mservo 0, 0 \ 750, 7
mservo 0, -750 \ 0, 7
mservo 0, 290 \ 750, 45
mservo 0, 750 \ 0, 10
mservo 0, 290 \ 750, 45
return

zigzag:
mservo 0, 750 \ 550, 12
mservo 0, -750 \ 550, 24
mservo 0, 750 \ 550, 24
mservo 0, -750 \ 550, 24
mservo 0, 750 \ 550, 24
mservo 0, -750 \ 550, 12
mservo 0, 750 \ 0, 19
mservo 0, 0 \ 750, 19
return

straight:
mservo 0, 0 \ 750, 26
mservo 0, 750 \ 0, 60
mservo 0, 0 \ -750, 26
return

Unwanted Spam Mail Stopper | Spam Removal | Block Junk Email | Stop Unwanted Email | Free Anti-Spam Filter Download