I am trying to make a simple robot with picaxe 18m2 and picaxe 18m2 high power board...
i have ordered the chip and i have to wait 1 or 3 days..So i finished programming..
my idea is to make a robot which have two mode auto and ir controlled..
this is my code
so is there any problem with this code? need any improvements ? i need help
This is the plan how i want to connect everything{which i have attached}
Please reply
i have ordered the chip and i have to wait 1 or 3 days..So i finished programming..
my idea is to make a robot which have two mode auto and ir controlled..
this is my code
Code:
'----- Motors
symbol mot1p = b.7
symbol mot2p = b.5
symbol mot1n = b.6
symbol mot2n = b.4
symbol inf = c.7
'-----servo setup
symbol servop = b.0
symbol lkfw = 150
symbol lkrt = 75
symbol lklt = 225
'----- SRF05 setup
symbol SRF05_IO = c.0 ' In/out Pin connected to center pin of SRF05
symbol RangeF = w3 ' define the variable to hold Front SRF05 value
'led
symbol ledr = c.2
symbol ledg = c.3
symbol ledb = c.6
'----- Program variables setup
Symbol danger = 400 'Used in the main program when judging what to do within certain tresholds
Symbol objectinfront = 700 'Used in the main program when judging what to do within certain tresholds
symbol freespace = 800 'Used in the main program when judging what to do within certain tresholds
main:
high ledr
irin [1000,main],inf,b0 ; wait for new signal
if b0 = 1 then auto ; switch on 1
if b0 = 4 then manual ; switch off 1
goto main
auto:
low ledr
high ledg
setint %10000000,%10000000,C
gosub Readrange
if rangeF > danger then
hans:
gosub Readrange
gosub drivefw
if rangeF > freespace then
gosub drivert
goto hans
endif
if rangeF < objectinfront then
gosub drivelt
goto auto
endif
if rangeF > objectinfront and rangeF < freespace then
gosub drivefw
endif
else
gosub drivebk
goto auto
endif
goto auto
manual:
high ledb
low ledr
irin [1000,main],inf,b1 ; wait for new signal
if b1 = 5 then gosub drivefw ; switch on 1
if b1 = 4 then gosub drivebk ; switch off 1
if b1 = 1 then gosub drivert ; switch on 1
if b1 = 4 then gosub drivelt ; switch off 1
if b1 = 4 then main ; switch off 1
goto manual
interrupt:
low ledg
low ledb
goto main
drivefw:
high mot1p low mot1n high mot2p low mot2n
return
drivebk:
high mot1n low mot1p high mot2n low mot2p
return
drivelt:
high mot1p low mot1n high mot2n low mot2p
return
drivert:
high mot2p low mot2n high mot1n low mot1p
return
'----- Sub routine to work with the SRF05
ReadRange: ' sub routine to read distance
PULSOUT SRF05_IO, 10 ' issue 10uS trigger pulse
PULSIN SRF05_IO, 1, RangeF ' measure echo time, put it into the variable RangeF
pause 10
return ' end of sub routine
This is the plan how i want to connect everything{which i have attached}
Please reply
Attachments
-
149.9 KB Views: 55