Looking back at one of the examples you gave of this idea (from kind of the beginning), Wall Racers used no interrupts. It was all done using basic statements, and blocking commands. These cars seem to go a bit slower than yours though, if I were to guestimate. Is the accuracy and speed they have in this video what you are aiming for? I think I saw them hit a wall here and there ... maybe. I am guessing around 4 to 5mph in the video?
Here is the code they used in PicAxe Basic.
Code:
' WALLRACERS By Frits Lyneborg
' Right turns on the track must be gentle (this code does not skid/slide on them), left can be hard (skid/slide is build in)
' <"left"> opposite just <left> in the remarks means that wheels are turning left, but direction is backwards, so "left" is actually moving right
symbol trigright = 0 ‘ Define output pin for Trigger pulse
symbol trigfront = 1 ‘ Define output pin for Trigger pulse
symbol echoright = 7 ‘ Define input pin for Echo pulse
symbol echofront = 6 ‘ Define input pin for Echo pulse
symbol rangeright = w1 ‘ 16 bit word variable for range
symbol rangefront = w2 ‘ 16 bit word variable for range
symbol oldrangeright = w3 ‘ 16 bit word variable for range
symbol differencerangeright = w4 ‘ used to calculate how hard a turn is
symbol frontfreetostopreverse = w5
symbol turnon = 7 ' the relay that if on makes the car turn to one side
symbol steerto = 6 ' the relay that if on turning is on, then decides the direction
symbol stopon = 5 ' the relay that if on makes the car stop
symbol forrev = 4 ' the relay that if on and is not on stop makes the car reverse
symbol frontdanger = 200 ' At what point should we realize we are getting too close? (note that breaking takes a lot, so this should be much higher than the real distance)
symbol frontfreetostopreversesetup = 201' must be higher than "frontdanger" - higher value means more backing out after close encounters
symbol frontfree = 350' set higher to turn earlier when something is in front, and get less skid-turning, but more likeliness to miss sharp right turns
symbol desiredtrack = 100
'symbol innertrack = 50
symbol outertrack = 150
high stopon
wait 5
low stopon
'''''''''''
main:
oldrangeright = rangeright
gosub puls
gosub skidandreverse
if rangefront < frontfree then 'turn left as there is something ahead in front
high turnon low steerto
goto main 'this is second priority above all loop till this is secured
end if
'' Normal drive to the right - we are too far away from the lane, so turn. This code contains no right-slide-turn for cool long right turns without slides to give more of a race-feeling oposed to zig-zag and robot-behaviour, so space must on thr track be higher than turning-radius in front of right turns - or the car vill turn left and miss the right turn.
if rangeright > outertrack then 'turn right as we are too far away
high turnon high steerto
end if
' Now we know that there is nothing closer than (frontdanger and) frontfree - and we are on track - so let's keep on track
'***
' First check if we are on the right path and have a positive development.
' If so, then keep us there by straightening up wheels that might be turned
if rangeright < desiredtrack and oldrangeright < rangeright then
low turnon low steerto ' drive straight forward as we are on the wrong side of desired track, but we are moving the right direction
end if
if rangeright > desiredtrack and oldrangeright > rangeright then
low turnon low steerto ' drive straight forward as we are on the wrong side of desired track, but we are moving the right direction
end if
'***
' Then see if we are moving away from the good path and do something about it if so.
if rangeright > desiredtrack and oldrangeright < rangeright then
high turnon high steerto 'turn right as we are in the outer lane and getting away
end if
if rangeright < desiredtrack and oldrangeright > rangeright then
high turnon low steerto 'turn left as we are in the inner lane and getting closer
end if
goto main
'***************************************
yankright:' there was an empty space to the right. Skid right to be sure we are turning if it is a turn in the track
'''''''''' Skidsecure start
high turnon high steerto 'turn right
pause 25' wait short for the car to give a small yank to the left before reversing.. all to start a skid turn to the right side
'''''''''' Skidsecure end
high forrev 'set in reverse gear
Skidright:
b0 = 0
do
gosub puls
b0 = b0 +1
loop while rangefront > frontfreetostopreverse and rangeright > outertrack and b0 < 20
'dildo:
'high stopon goto dildo
low forrev 'set in forward gear
pause 300
return
'***************************************
'***************************************
reverseoutoftrouble:
'''''''''' Skidsecure start
high turnon low steerto 'turn left
pause 25' wait short for the car to give a small yank to the left before reversing.. all to start a skid turn to the right side
'''''''''' Skidsecure end
high forrev 'set in reverse gear
rev:
frontfreetostopreverse = frontfreetostopreversesetup
keepreversing:
frontfreetostopreverse = frontfreetostopreverse - 3' making sure we are not backing and reversing and going nowhere, as we have a wall behind us
if frontfreetostopreverse < 50 then
gosub stuckerror
end if
gosub puls
if rangefront < frontfreetostopreversesetup then
if rangeright < desiredtrack and oldrangeright < rangeright and rangefront > frontdanger then
low turnon low steerto ' drive ahead as we are on the wrong side, but we are moving the right direction and we are not too close
end if
if rangeright > desiredtrack and oldrangeright > rangeright and rangefront > frontdanger then
low turnon low steerto ' drive ahead as we are on the wrong side, but we are moving the right direction and we are not too close
end if
if rangeright > desiredtrack and oldrangeright < rangeright and rangefront > frontdanger then
high turnon low steerto 'turn left (reversed) as we are in the inner lane and getting closer
end if
if rangeright < desiredtrack and oldrangeright > rangeright then
high turnon high steerto 'turn right (reversed) as we are in the outer lane and getting away
end if
goto keepreversing
end if
high turnon low steerto 'turn "left"
low forrev 'set in forward gear
return
'*************
skidandreverse:
if rangefront < frontdanger then ' too close, reverse out of trouble!
gosub reverseoutoftrouble
goto main ' this is first priority above all - loop till this is secured
end if
return
'*************
puls:
pulsout trigright,2 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echoright,1,rangeright ‘ measures the range in 10uS steps
pulsf:
pulsout trigfront,2 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echofront,1,rangefront ‘ measures the range in 10uS steps
pause 10 ‘ recharge period after ranging completes
return
stuckerror:
high stopon
low forrev
low steerto
low turnon
dadaa:
goto dadaa
Bookmarks