Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Sunday, 25 April 2010

Programming Code

main1: if pin0 = 0 then ; if the line tracker mode is on

high 0 ;turn left motor clockwise
high 3 ;turn right motor clockwise

Right: if pin1 = 1 and pin2 = 1 and pin6 = 0 then ;if tank meets right turn
low 0 ;stop left motor
low 3 ;stop right motor
high 0 ;turn left motor clockwise
high 4 ;turn right motor anticlockwise
loop1: if pin7 = 1 then ;if front sensor meets the line
low 0 ;stop left motor
low 4 ;stop right motor
else
goto loop1 ;keep turning until front sensor hits line
endif


Left: elseif pin1 = 1 and pin6 = 1 and pin2 = 0 then ;if tank meets left turn
low 0 ;stop left motor
low 3 ;stop right motor
high 1 ;turn left motor anticlockwise
high 3 ;turn right motor clockwise
loop2: if pin7 = 1 then ;if center front sensor hits line
low 1 ;stop left motor
low 3 ;stop right motor
else
goto loop2 ;keep turning until front sensor hits line
endif


Offtrack: elseif pin1 = 0 then


OffLeft: if pin2 = 1 then ;if right sensor hits line
low 0 ;stop left motor
low 3 ;stop right motor
high 0 ;turn left motor clockwise
high 4
loop3: if pin7 = 1 then ;turn right motor anticlockwise
low 0
low 4
high 0
high 3
else
goto loop3
endif
loop4: if pin1 = 1 then
low 0
low 3
high 3
high 1
else
goto loop4
endif
loop5: if pin7 = 1 then
low 3
low 1
else
goto loop5
endif

OffRight: elseif pin6 = 1 then
low 0
low 3
high 3
high 1
loop6: if pin7 = 1 then ;turn right motor anticlockwise
low 3
low 1
high 0
high 3
else
goto loop6
endif
loop7: if pin1 = 1 then
low 0
low 3
high 0
high 4
else
goto loop7
endif
loop8: if pin7 = 1 then
low 0
low 4
else
goto loop8
endif

else
goto OffLeft ;keep reversing until center sensor hits line
endif
elseif pin0 = 1 then
goto main2

endif
endif
goto main1

main2: if pin0 = 1 then ; if the signal tracker mode is on

high 0 ;turn left motor clockwise
high 1 ;turn right motor clockwise



RightSig: if pin7 = 1 and pin2 = 1 and pin6 = 0 then ;if tank meets right turn
pause 100
if pin6 = 1 then
goto Failsafe
endif
pause 2000 ;drive until center sensor is at apex
low 0 ;stop left motor
low 3 ;stop right motor
high 0 ;turn left motor clockwise
high 4 ;turn right motor anticlockwise
loop9: if pin7 = 1 then ;if front sensor meets the line
low 0 ;stop left motor
low 4 ;stop right motor
else
goto loop9 ;keep turning until front sensor hits line
endif


LeftSig: elseif pin7 = 1 and pin6 = 1 and pin2 = 0 then ;if tank meets left turn
pause 100
if pin2 = 1 then
goto Failsafe
endif
pause 2000 ;drive until center sensor is at apex
low 0 ;stop left motor
low 3 ;stop right motor
high 1 ;turn left motor anticlockwise
high 3 ;turn right motor clockwise
loop10: if pin7 = 1 then ;if center front sensor hits line
low 1 ;stop left motor
low 3 ;stop right motor
else
goto loop10 ;keep turning until front sensor hits line
endif


StopRev: elseif pin7 = 1 and pin2 = 1 and pin6 = 1 then

Failsafe: low 0 ;stop left motor
low 3 ;stop right motor
high 1 ;turn left motor anticlockwise
high 4 ;turn right motor anticlockwise
pause 2000
loop11: if pin1 = 1 then ;if center sensor hits line
low 1 ;stop left motor
low 4 ;stop right motor
goto Endprogram
else
goto loop11
endif

elseif pin0 = 0 then
goto main1
endif

endif
goto main2

Endprogram: End

Tuesday, 16 March 2010

Software Update

Problems Faced

  • Reed switches were not sensitive enough for magnetic tape.
  • Only 3 analog to digital converters on chip.

Actions on Problems

  • Changed code to suit LDRs.
  • Chose to not use the ADC's and plan to use the LDR's digitally. If they provide a voltage of over 2.25V then PICAXE will read as logic 1. If under 2.25V then logic 0 will be read.

Future Intentions and Learning Outcomes

  • LDR's will need to be calibrated for light conditions in the room.
  • Debug code on buggy testing in order to remove faults and include possible failsafe.
  • Include extra code for unique additional functions which will be revealed on competition day.

Current Situation

  • Code for both line following and signal reading modes is complete, tested and fully operational.
  • Input output variables may change but are easily edited in the code.

Project Schedule

  • Project Set - 09/03/10
  • Group meeting - 16/03/10 - 12pm [Labs/costa]
  • Group meeting - 19/03/10 - 12pm [Labs/costa]
  • Group meeting - 23/03/10 - 12pm [Labs/costa]
  • Group meeting - 08/04/10 - James Flat c.1pm
  • Group meeting - 20/04/10 - 12pm [Labs/costa]
  • Group Meeting/buggy test - 24/04/10 - James' Flat
  • Buggy deadline - 27/04/10 - 1pm [mb168]