Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/ajegu (24-Jan @ 02:23)

Syntax Highlighted Code

  1. '****************************************************************
  2. '*  Name    : UNTITLED.BAS                                      *
  3. '*  Author  : Kyle Siopiolosz and Alyssa Mole                   *
  4. '*  Notice  : Copyright (c) 2011 iPod Chargers                  *
  5. '*          : All Rights Reserved                               *
  6. '*  Date    : 1/18/2011                                         *
  7. '*  Version : 1.0                                               *
  8. '*  Notes   :                                                   *
  9. '*          :                                                   *
  10. '****************************************************************
  11. 'NOTE: LINE SENSOR SEES NOTHING WHEN = 1, BOT SENSOR SEES NOTHING WHEN = 1
  12. CMCON = 7
  13. TRISA = %00000011
  14. TRISB = %00000000
  15.  
  16. REVERSECOUNT VAR BYTE                ' Counts how many times the bot has been moving backwards
  17. LEFTCOUNT VAR BYTE                   ' Counts how many times the bot has turned left
  18. RIGHTCOUNT VAR BYTE                  ' Counts how many times the bot has turned right
  19. SEED VAR BYTE                        ' Sets up the first seed within the main routine
  20. MAINCOUNT VAR BYTE                   ' Counts how many times the bot returns back to the MAINCOUNT routine
  21. SYMBOL FORWARD = %00000101           ' Required binary string to tell motors to move forwards
  22. SYMBOL BACKWARD = %00001010          ' Required binary string to tell motors to move backwards
  23. SYMBOL LEFTTURN = %00001001          ' Required binary string to tell motors to turn left
  24. SYMBOL RIGHTTURN = %00000110         ' Required binary string to tell motors to turn right
  25.  
  26. REVERSECOUNT = 0                     ' Set variable REVERSECOUNT to 0
  27. LEFTCOUNT = 0                        ' Set variable LEFTCOUNT to 0
  28. SEED = 0                             ' Set variable SEED to 0
  29. MAINCOUNT = 0                        ' Set variable MAINCOUNT to 0
  30.  
  31. MAIN:
  32.  
  33. IF MAINCOUNT < 4 THEN                ' Perfoms specificed actions while MAINCOUNT is less then 4
  34. WHILE PORTA.0 = 1                    ' Performs specified actions while line sensor sees nothing
  35. PORTB = LEFTTURN                     ' Bot turns left
  36. SEED = SEED + 1                      ' Adds 1 to the SEED variable
  37. IF SEED =>10 THEN                    ' Checks if SEED is equal to 10 or greater
  38. SEED = 0                             ' Sets SEED back to 0
  39. ENDIF                                ' Ends variable check
  40. IF PORTA.1 = 0 THEN GOSUB ATTACK     ' Checks to see if the botsensor sees sometbing, if it does it goes to the subroutine ATTACK, otherwise it stays in the MAIN loop
  41. WEND                                 ' Ends while statement
  42. GOSUB DODGE                          ' Goes to the DODGE subroutine
  43. ELSE                                 ' If MAINCOUNT is not less than 10
  44. GOTO TREE                            ' Goes to TREE
  45. ENDIF
  46.  
  47.  
  48. DODGE:
  49. WHILE REVERSECOUNT <= 1000           ' Performs action while REVERSECOUNT is less than or equal to 1000
  50. PORTB = BACKWARD                     ' Bot moves backwards
  51. IF PORTA.0 = 0 THEN                  ' If there is a black surface
  52. MAINCOUNT = MAINCOUNT + 1            ' Add 1 to MAINCOUNT variable
  53. GOTO MAIN                            ' Go back to the MAIN routine
  54. ENDIF                                ' Ends the if statement
  55. REVERSECOUNT = REVERSECOUNT + 1      ' Add 1 to REVERSECOUNT variable
  56. WEND                                 ' Ends the while statement
  57. REVERSECOUNT = 0                     ' Sets REVERSECOUNT back to 0
  58. WHILE LEFTCOUNT <= 1000              ' Performs action while LEFTCOUNT is less than or equal to 100
  59. PORTB = LEFTTURN                     ' Bot turns left                          
  60. IF PORTA.0 = 0 THEN                  ' If there is a black surface
  61. MAINCOUNT = MAINCOUNT + 1            ' Add 1 to MAINCOUNT variable
  62. GOTO MAIN                            ' Go back to the MAIN routine
  63. ENDIF                                ' Ends the if statement
  64. LEFTCOUNT = LEFTCOUNT + 1            ' Add 1 to REVERSECOUNT variable
  65. WEND                                 ' Ends the while statement
  66. LEFTCOUNT = 0                        ' Sets LEFTCOUNT back to 0
  67. IF PORTA.0 = 1 THEN                  ' If there is still a line
  68. GOSUB DODGE2                         ' Goes to DODGE2 Subroutine
  69. ENDIF                                ' Ends if
  70. IF PORTA.0 = 0 THEN                  ' If there is no line
  71. RETURN                               ' Returns to previous routine
  72. ENDIF                                ' Ends if
  73.  
  74.  
  75. DODGE2:
  76. WHILE RIGHTCOUNT <= 1000             ' Performs action while RIGHTCOUNT is less than or equal to 1000
  77. PORTB = RIGHTTURN                    ' Bot moves backwards
  78. IF PORTA.0 = 0 THEN                  ' If there is a black surface
  79. MAINCOUNT = MAINCOUNT + 1            ' Add 1 to MAINCOUNT variable
  80. GOTO MAIN                            ' Go back to the MAIN routine
  81. ENDIF                                ' Ends the if statement
  82. RIGHTCOUNT = RIGHTCOUNT + 1          ' Add 1 to RIGHTCOUNT variable
  83. WEND                                 ' Ends the while statement
  84. RIGHTCOUNT = 0                       ' Sets RIGHTCOUNT back to 0
  85. WHILE REVERSECOUNT <= 1000           ' Performs action while REVERSECOUNT is less than or equal to 1000
  86. PORTB = BACKWARD                     ' Bot moves backwards
  87. IF PORTA.0 = 0 THEN                  ' If there is a black surface
  88. MAINCOUNT = MAINCOUNT + 1            ' Add 1 to MAINCOUNT variable
  89. GOTO MAIN                            ' Go back to the MAIN routine
  90. ENDIF                                ' Ends the if statement
  91. REVERSECOUNT = REVERSECOUNT + 1      ' Add 1 to REVERSECOUNT variable
  92. WEND                                 ' Ends the while statement
  93. REVERSECOUNT = 0                     ' Ends the while statement
  94. IF PORTA.0 = 1 THEN                  ' If there is still a line
  95. GOSUB DODGE                          ' Goes to DODGE2 Subroutine
  96. ENDIF                                ' Ends if
  97. IF PORTA.0 = 0 THEN                  ' If there is no line
  98. RETURN                               ' Returns to previous routine
  99. ENDIF                                ' Ends if
  100.  
  101.  
  102. ATTACK:                              
  103. WHILE PORTA.1 = 0                    ' While bot sees another (bot)?
  104. PORTB = FORWARD                      ' Bot moves forward
  105. WEND                                 ' End if
  106. RETURN                               ' Returns to previous routine
  107.  
  108.  
  109. TREE:
  110.                                      
  111. IF SEED < = 3 THEN                   ' Checks if SEED is less than or equal to 3
  112. GOTO SEEK1                           ' Goes to SEEK1
  113. ENDIF                                ' Ends if statement
  114.  
  115. IF SEED < = 6 THEN                   ' SEED less than or equal to 6
  116. GOTO SEEK2                           ' Goes to SEEK2
  117. ENDIF                                ' Ends if statement
  118.  
  119. IF SEED < = 10 THEN                  ' SEED less than or equal to 10
  120. GOTO SEEK3                           ' Goes to SEEK3
  121. ENDIF                                ' Ends if statement
  122.  
  123.  

Plain Code

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : Kyle Siopiolosz and Alyssa Mole                   *
'*  Notice  : Copyright (c) 2011 iPod Chargers                  *
'*          : All Rights Reserved                               *
'*  Date    : 1/18/2011                                         *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
'NOTE: LINE SENSOR SEES NOTHING WHEN = 1, BOT SENSOR SEES NOTHING WHEN = 1
CMCON = 7
TRISA = %00000011
TRISB = %00000000

REVERSECOUNT VAR BYTE                ' Counts how many times the bot has been moving backwards
LEFTCOUNT VAR BYTE                   ' Counts how many times the bot has turned left 
RIGHTCOUNT VAR BYTE                  ' Counts how many times the bot has turned right
SEED VAR BYTE                        ' Sets up the first seed within the main routine 
MAINCOUNT VAR BYTE                   ' Counts how many times the bot returns back to the MAINCOUNT routine
SYMBOL FORWARD = %00000101           ' Required binary string to tell motors to move forwards
SYMBOL BACKWARD = %00001010          ' Required binary string to tell motors to move backwards
SYMBOL LEFTTURN = %00001001          ' Required binary string to tell motors to turn left
SYMBOL RIGHTTURN = %00000110         ' Required binary string to tell motors to turn right

REVERSECOUNT = 0                     ' Set variable REVERSECOUNT to 0
LEFTCOUNT = 0                        ' Set variable LEFTCOUNT to 0
SEED = 0                             ' Set variable SEED to 0
MAINCOUNT = 0                        ' Set variable MAINCOUNT to 0

MAIN:

IF MAINCOUNT < 4 THEN                ' Perfoms specificed actions while MAINCOUNT is less then 4
WHILE PORTA.0 = 1                    ' Performs specified actions while line sensor sees nothing 
PORTB = LEFTTURN                     ' Bot turns left
SEED = SEED + 1                      ' Adds 1 to the SEED variable
IF SEED =>10 THEN                    ' Checks if SEED is equal to 10 or greater
SEED = 0                             ' Sets SEED back to 0
ENDIF                                ' Ends variable check
IF PORTA.1 = 0 THEN GOSUB ATTACK     ' Checks to see if the botsensor sees sometbing, if it does it goes to the subroutine ATTACK, otherwise it stays in the MAIN loop
WEND                                 ' Ends while statement
GOSUB DODGE                          ' Goes to the DODGE subroutine
ELSE                                 ' If MAINCOUNT is not less than 10
GOTO TREE                            ' Goes to TREE
ENDIF


DODGE:
WHILE REVERSECOUNT <= 1000           ' Performs action while REVERSECOUNT is less than or equal to 1000
PORTB = BACKWARD                     ' Bot moves backwards
IF PORTA.0 = 0 THEN                  ' If there is a black surface
MAINCOUNT = MAINCOUNT + 1            ' Add 1 to MAINCOUNT variable
GOTO MAIN                            ' Go back to the MAIN routine
ENDIF                                ' Ends the if statement
REVERSECOUNT = REVERSECOUNT + 1      ' Add 1 to REVERSECOUNT variable
WEND                                 ' Ends the while statement
REVERSECOUNT = 0                     ' Sets REVERSECOUNT back to 0
WHILE LEFTCOUNT <= 1000              ' Performs action while LEFTCOUNT is less than or equal to 100
PORTB = LEFTTURN                     ' Bot turns left                           
IF PORTA.0 = 0 THEN                  ' If there is a black surface
MAINCOUNT = MAINCOUNT + 1            ' Add 1 to MAINCOUNT variable
GOTO MAIN                            ' Go back to the MAIN routine
ENDIF                                ' Ends the if statement
LEFTCOUNT = LEFTCOUNT + 1            ' Add 1 to REVERSECOUNT variable
WEND                                 ' Ends the while statement
LEFTCOUNT = 0                        ' Sets LEFTCOUNT back to 0
IF PORTA.0 = 1 THEN                  ' If there is still a line
GOSUB DODGE2                         ' Goes to DODGE2 Subroutine 
ENDIF                                ' Ends if
IF PORTA.0 = 0 THEN                  ' If there is no line
RETURN                               ' Returns to previous routine
ENDIF                                ' Ends if


DODGE2:
WHILE RIGHTCOUNT <= 1000             ' Performs action while RIGHTCOUNT is less than or equal to 1000
PORTB = RIGHTTURN                    ' Bot moves backwards
IF PORTA.0 = 0 THEN                  ' If there is a black surface
MAINCOUNT = MAINCOUNT + 1            ' Add 1 to MAINCOUNT variable
GOTO MAIN                            ' Go back to the MAIN routine
ENDIF                                ' Ends the if statement
RIGHTCOUNT = RIGHTCOUNT + 1          ' Add 1 to RIGHTCOUNT variable
WEND                                 ' Ends the while statement
RIGHTCOUNT = 0                       ' Sets RIGHTCOUNT back to 0
WHILE REVERSECOUNT <= 1000           ' Performs action while REVERSECOUNT is less than or equal to 1000
PORTB = BACKWARD                     ' Bot moves backwards
IF PORTA.0 = 0 THEN                  ' If there is a black surface
MAINCOUNT = MAINCOUNT + 1            ' Add 1 to MAINCOUNT variable
GOTO MAIN                            ' Go back to the MAIN routine
ENDIF                                ' Ends the if statement
REVERSECOUNT = REVERSECOUNT + 1      ' Add 1 to REVERSECOUNT variable
WEND                                 ' Ends the while statement
REVERSECOUNT = 0                     ' Ends the while statement
IF PORTA.0 = 1 THEN                  ' If there is still a line
GOSUB DODGE                          ' Goes to DODGE2 Subroutine 
ENDIF                                ' Ends if
IF PORTA.0 = 0 THEN                  ' If there is no line
RETURN                               ' Returns to previous routine
ENDIF                                ' Ends if


ATTACK:                              
WHILE PORTA.1 = 0                    ' While bot sees another (bot)?
PORTB = FORWARD                      ' Bot moves forward
WEND                                 ' End if
RETURN                               ' Returns to previous routine


TREE:
                                     
IF SEED < = 3 THEN                   ' Checks if SEED is less than or equal to 3
GOTO SEEK1                           ' Goes to SEEK1
ENDIF                                ' Ends if statement

IF SEED < = 6 THEN                   ' SEED less than or equal to 6
GOTO SEEK2                           ' Goes to SEEK2
ENDIF                                ' Ends if statement

IF SEED < = 10 THEN                  ' SEED less than or equal to 10
GOTO SEEK3                           ' Goes to SEEK3
ENDIF                                ' Ends if statement

Permalink: http://codedumper.com/ajegu