'PICAXE 20X2:
;need axe027
; pwr Qs
; hall effect
; rtc
'JONNY 4 & THREE QUARTERS
'All directions for 'HEAD' and Chasis movement
'are based on looking at the bot from
'behind (no pun intended:)
Setfreq M32 'setfreq to M32 for the 20X2
Symbol pan = B.1 'Replace 2(08M) with B.1 on the 20X2
Symbol tilt = B.7 'Replace 1(08M) with B.7 on the 20X2
Symbol Background_RCV = B.6
Symbol delay = 2500
'Experiment with this value, depending on the make of servo
'and pic (freq) speed, if this pause value is too low it
'may cause apparent jittering or miss position loci
'because the servopos command has been updated before
'the last command has had chance to be effected? i.e.
'before the servo horn has reached it's intended position ?
let dirsB = %11111111
let adcsetup = 0
'******************************************************************************
'* *
'* Key below: Each number can be used during the ASSESS_IR Subroutine to *
'* *
'* control motor/direction, handy to scroll back here during debugging *
'* *
'******************************************************************************
'-------------------------------------------------------------------------------
'STANDSTILL = "1"
'ONWARDS = "2"
'BACKWARDS = "3"
'FWDRIGHTTURN = "4"
'FWDLEFTTURN = "5"
'BACKWARDSLEFTTURN = "6"
'BACKWARDSRIGHTTURN = "7"
'-------------------------------------------------------------------------------
'******************************************************************************
'* *
'* Main Program to decide/select action *
'* *
'******************************************************************************
MAIN:
Goto AUTO_MODE
ASSESS_IR:
Gosub GETIR
Bintoascii b0,b1,b2,b3
'Debug b3 'remove the first apostrophe when debugging
Select Case b3
Case = "1"
Goto STANDSTILL
Case = "2"
Goto ONWARDS
Case = "3"
Goto BACKWARDS
Case = "4"
Goto FWDRIGHTTURN
Case = "5"
Goto FWDLEFTTURN
Case = "6"
Goto BACKWARDSLEFTTURN
Case = "7"
Goto BACKWARDSRIGHTTURN
Else Goto ASSESS_IR
End Select
Goto ASSESS_IR
'******************************************************************************
'* *
'* Subroutine: AUTO MODE - NEED TO MOVE TO 28X2 *
'* *
'* move the servo commands to the 28x2 * *
'******************************************************************************
AUTO_MODE:
Gosub SRF05
Servo pan, 150
Servo tilt, 220
Gosub SRF05
Select Case w1
Case > 25
Gosub ONWARDS
Case < 25
Gosub STANDSTILL
End Select
Goto SCAN
'******************************************************************************
'* *
'* Subroutine: STOPS THE BOT TO LOOK AROUND *
'* *
'******************************************************************************
SCAN:
Gosub Look_Up_Left
Pause delay
Gosub SRF05
w2=w1
Gosub Look_Up_Right
Pause delay
Gosub SRF05
w3=w1
Gosub Look_Down_Right:
Pause delay
Gosub SRF05
w4=w1
Gosub Look_Down_Left:
Gosub SRF05
w5=w1
Pause delay
If w4<10 or w5<10 Then Gosub BACKWARDS
if w4>10 or w5>10 Then Gosub ONWARDS
Goto SCAN
'Goto ASSESS_GROUND
'******************************************************************************
'* *
'* Subroutine: ASSESS THE GROUND IN FRONT OF BOT *
'* *
'******************************************************************************
ASSESS_GROUND:
if w6<25 Then Gosub BACKWARDSLEFTTURN
if w7<25 Then Gosub BACKWARDSRIGHTTURN
Gosub BACKWARDS
Goto SCAN
'******************************************************************************
'* *
'* Subroutine: Collect SRF05 DATA FROM 08M *
'* *
'******************************************************************************
GETIR:
irin [5000,AUTO_MODE], c.5,b0
'debug b0
'bintoascii w4,b0,b0,b0,b0,b0
'setfreq M64
Return
'******************************************************************************
'* *
'* Subroutine: Collect SRF05 DATA *
'* *
'******************************************************************************
SRF05: 'Waits for the 08M picaxe to send the range finder result
Setfreq m4
serin B.6,N2400_4,w1
'debug w1
Setfreq m32
Return
'******************************************************************************
'* *
'* Subroutines To Control Motors - NEEDS PWMing *
'* *
'******************************************************************************
ONWARDS: 'works
'Sertxd("Onwards",13,10)
High B.4,B.3
Pause 1500
Low B.4,B.3
Return
FWDRIGHTTURN: 'works
'Sertxd("Forward Right Turn",13,10)
High B.4 'B.3
Pause 7
Low B.4 'B.3
Return
FWDLEFTTURN: 'works
'Sertxd("Forward Right Turn",13,10)
High B.3
Pause 7
Low B.3
Return
BACKWARDS: 'works
'Sertxd("Reverse",13,10)
High B.5,B.2
Pause 1
High B.4,B.3
Pause 11
Low B.4,B.3
Low B.5,B.2
Return
BACKWARDSLEFTTURN: 'works
'Sertxd("Reverse Left",13,10)
High B.2
Pause 1
High B.3
Pause 7
Low B.3
Low B.2
Return
BACKWARDSRIGHTTURN: 'works
'Sertxd("Reverse Left",13,10)
High B.4
Pause 1
High B.5
Pause 7
Low B.5
Low B.4
Return
STANDSTILL: 'works
'Sertxd("Standstill",13,10)
low B.2,B.3,B.4,B.5
'b0=5
'Debug b0
pause 39
Return
'******************************************************************************
'* *
'* Subroutines To Control Servos - Move to 28x2 *
'* *
'******************************************************************************
Centre:
Servopos pan, 150 'Pan centre
Servopos tilt,150 'Tiltcentre
Return
Look_Up_Left:
Servopos pan, 80 'Pan Left
Servopos tilt, 80 'Tilt Up
Return
Look_Up_Right:
Servopos pan, 220 'Pan Right
Servopos tilt, 80 'Tilt Up
Return
Look_Down_Right:
Servopos pan, 220 'Pan Right
Servopos tilt, 220 'Tilt Down
Return
Look_Down_Left:
Servopos pan, 80 'Pan Left
Servopos tilt, 220 'Tilt Down
Return