Vulpes

BOB_subs

Jun 8th, 2011
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' {$STAMP BS2}
  2. ' {$PBASIC 2.5}
  3. 'Sample Sonar test....
  4. DEBUG "Mobility Functions!!",CR
  5. PAUSE 500
  6.  
  7. GOSUB Jingle                  'Start Program Tone
  8.  
  9. counter         VAR     Word        'Required for functions
  10. counter1  VAR Word
  11. lcounter      VAR    Bit        'Required for functions
  12. rawDist         VAR     Word
  13. cm              VAR     Word
  14. init_far CON 2000
  15. init_large CON 4000
  16.  
  17.  
  18.  
  19.  
  20.  
  21. ' -----[ Constants ]-------------------------------------------------------
  22.  
  23. '-----[MAIN]-------------------------------------------------
  24. cm =1000
  25. rawDist = 2501
  26. DO
  27.   counter1 = 0
  28.   lcounter = 0
  29.   DO UNTIL (lcounter = 1)
  30.     GOSUB Look_Straight
  31.  
  32.     FOR counter = 1 TO 24
  33.         PULSOUT 15, 1500
  34.         GOSUB Get_Sonar
  35.         IF rawDist <init_far + counter1 THEN
  36.           PAUSE 20
  37.             GOSUB Look_Straight
  38.             rawDist = init_large
  39.           DO  UNTIL rawDist <init_far + counter1
  40.  
  41.             GOSUB Get_Sonar
  42.             'DEBUG CLS,DEC rawDist
  43.             GOSUB Left_Pulse
  44.             PAUSE 21
  45.           LOOP
  46.  
  47.           PAUSE 20
  48.  
  49.           DO  WHILE rawDist <init_far + counter1
  50.                   GOSUB Get_Sonar
  51.                   'DEBUG CLS,DEC rawDist
  52.                   GOSUB Forward_Pulse
  53.                   PAUSE 21
  54.           LOOP
  55.         EXIT
  56.         ENDIF
  57.     NEXT
  58.  
  59.     PAUSE 20
  60.     GOSUB Look_Straight
  61.     PAUSE 60
  62.  
  63.     FOR counter = 1 TO 24
  64.         PULSOUT 15, 1
  65.         GOSUB Get_Sonar
  66.         IF rawDist <init_far + counter1 THEN
  67.           PAUSE 20
  68.             GOSUB Look_Straight
  69.             rawDist = init_large
  70.           DO  UNTIL rawDist <init_far + counter1
  71.  
  72.             GOSUB Get_Sonar
  73.             'DEBUG CLS,DEC rawDist
  74.             GOSUB Right_Pulse
  75.             PAUSE 21
  76.           LOOP
  77.  
  78.           PAUSE 20
  79.  
  80.           DO  WHILE rawDist <init_far + counter1
  81.                   GOSUB Get_Sonar
  82.                   'DEBUG CLS,DEC rawDist
  83.                   GOSUB Forward_Pulse
  84.                   PAUSE 21
  85.           LOOP
  86.         EXIT
  87.         ENDIF
  88.     NEXT
  89.  
  90.     PAUSE 20
  91.  
  92.  
  93.     lcounter = lcounter + 1
  94.  
  95.   LOOP
  96.   GOSUB Look_Straight
  97.   PAUSE 60
  98.   rawDist = init_large
  99.   lcounter = 0
  100.   DO  UNTIL rawDist <init_far + counter1
  101.         DEBUG ? counter1
  102.         IF lcounter = 1 THEN
  103.           counter1 = 1000
  104.         ENDIF
  105.         GOSUB Get_Sonar
  106.         'DEBUG CLS,DEC rawDist
  107.         GOSUB Left_Pulse
  108.         lcounter = lcounter +1
  109.         PAUSE 21
  110.   LOOP
  111.  
  112.  
  113. LOOP
  114.  
  115.  
  116.  
  117.  
  118.  
  119. END
  120.  
  121.  
  122.  
  123. main1:
  124.   DO
  125.     DO  UNTIL rawDist <1200
  126.         GOSUB Get_Sonar
  127.         'DEBUG CLS,DEC rawDist
  128.         GOSUB Left_Pulse
  129.         PAUSE 21
  130.     LOOP
  131.  
  132.     PAUSE 200
  133.     rawDist = 2501
  134.     DO  UNTIL rawDist <1200
  135.         GOSUB Get_Sonar
  136.         'DEBUG CLS,DEC rawDist
  137.         GOSUB Right_Pulse
  138.         PAUSE 21
  139.     LOOP
  140.  
  141.     PAUSE 200
  142.  
  143.     DO  WHILE rawDist <1200
  144.         GOSUB Get_Sonar
  145.         'DEBUG CLS,DEC rawDist
  146.         GOSUB Backward_Pulse
  147.         PAUSE 21
  148.     LOOP
  149.  
  150.   LOOP
  151. RETURN
  152.  
  153. END
  154. '-----[MAIN_END]---------------------------------------------
  155.  
  156. Get_Sonar:
  157.                                    ' make trigger 0-1-0
  158.   PULSOUT 11, 5                         ' activate sensor
  159.   PULSIN  11, 1, rawDist                 ' measure echo pulse
  160.   RETURN
  161.  
  162. Look_Left:
  163.   FOR counter = 1 TO 24
  164.     PULSOUT 15, 1500
  165.     PAUSE 20
  166.   NEXT
  167.   PAUSE 20
  168. RETURN
  169.  
  170. Look_Straight:
  171.   FOR counter = 1 TO 24
  172.     PULSOUT 15, 750
  173.     PAUSE 20
  174.   NEXT
  175.   PAUSE 20
  176. RETURN
  177.  
  178. Look_Right:
  179.   FOR counter = 1 TO 24
  180.     PULSOUT 15, 1
  181.     PAUSE 20
  182.   NEXT
  183.   PAUSE 20
  184. RETURN
  185.  
  186.  
  187. Forward1:
  188.   FOR counter = 1 TO 43
  189.     PULSOUT 12, 850
  190.     PULSOUT 13, 650
  191.     PAUSE 20
  192.   NEXT
  193.   PAUSE 200
  194.   RETURN
  195.  
  196. Forward3:                             'Move forward for 3 seconds
  197.   FOR counter = 1 TO 122
  198.     PULSOUT 12, 820
  199.     PULSOUT 13, 650
  200.     PAUSE 20
  201.   NEXT
  202.   PAUSE 200
  203.   RETURN
  204.  
  205. Forward10:                            'Move forward 10 seconds (calibration)
  206.   FOR counter = 1 TO 407
  207.     PULSOUT 12, 850
  208.     PULSOUT 13, 650
  209.     PAUSE 20
  210.   NEXT
  211.   PAUSE 200
  212.   RETURN
  213.  
  214. Forward_Pulse:                       'Move forward for a single pulse
  215.   PULSOUT 12, 820
  216.   PULSOUT 13, 650
  217.   PAUSE 20
  218.   RETURN
  219.  
  220. Backward1:
  221.   FOR counter = 1 TO 43
  222.     PULSOUT 12, 650
  223.     PULSOUT 13, 850
  224.     PAUSE 20
  225.   NEXT
  226.   PAUSE 200
  227.   RETURN
  228.  
  229. Backward3:                           'Move backward for 3 seconds
  230.   FOR counter = 1 TO 122
  231.     PULSOUT 12, 680
  232.     PULSOUT 13, 850
  233.     PAUSE 20
  234.   NEXT
  235.   PAUSE 200
  236.   RETURN
  237.  
  238. Backward10:                          'Move backward 10 seconds (calibration)
  239.   FOR counter = 1 TO 407
  240.     PULSOUT 12, 650
  241.     PULSOUT 13, 850
  242.     PAUSE 20
  243.   NEXT
  244.   PAUSE 200
  245.   RETURN
  246.  
  247. Backward_Pulse:                      'Move backward for a single pulse
  248.   PULSOUT 12,680
  249.   PULSOUT 13, 850
  250.   PAUSE 20
  251.   RETURN
  252.  
  253. Right_Pulse:
  254.   PULSOUT 13, 850
  255.   PULSOUT 12, 850
  256.   PAUSE 20
  257.   RETURN
  258.  
  259. Right90:                             'Hard right 90 degrees
  260.   FOR counter = 1 TO 20
  261.     PULSOUT 13, 850
  262.     PULSOUT 12, 850
  263.     PAUSE 20
  264.   NEXT
  265.   PAUSE 200
  266.   RETURN
  267.  
  268. RightRamp45:                          'Smooth right 45 degrees
  269.  FOR counter = 1 TO 30
  270.    PULSOUT 13, 750 + counter
  271.    PULSOUT 12, 750 + counter
  272.    PAUSE 20
  273.  NEXT
  274.  
  275.  FOR counter = 1 TO 15
  276.    PULSOUT 13, 765 - counter
  277.    PULSOUT 12, 765 - counter
  278.    PAUSE 20
  279.  NEXT
  280.  PAUSE 200
  281.  RETURN
  282.  
  283. RightRamp90:                         'Smooth right 90 degrees
  284.   FOR counter = 1 TO 30
  285.     PULSOUT 13, 750 + counter
  286.     PULSOUT 12, 750 + counter
  287.     PAUSE 20
  288.   NEXT
  289.  
  290.   FOR counter = 1 TO 30
  291.     PULSOUT 13, 780 - counter
  292.     PULSOUT 12, 780 - counter
  293.     PAUSE 20
  294.   NEXT
  295.   PAUSE 200
  296.   RETURN
  297.  
  298. RightRamp180:                        'Smooth right 180 degrees
  299.   FOR counter = 1 TO 56
  300.     PULSOUT 13, 750 + counter
  301.     PULSOUT 12, 750 + counter
  302.     PAUSE 20
  303.   NEXT
  304.  
  305.   FOR counter = 1 TO 30
  306.     PULSOUT 13, 780 - counter
  307.     PULSOUT 12, 780 - counter
  308.     PAUSE 20
  309.   NEXT
  310.   PAUSE 200
  311.   RETURN
  312.  
  313. Left_Pulse:
  314.   PULSOUT 13, 650
  315.   PULSOUT 12, 650
  316.   PAUSE 20
  317.   RETURN
  318.  
  319. Left90:                              'Hard left 90 degrees
  320.   FOR counter = 1 TO 20
  321.     PULSOUT 13, 680
  322.     PULSOUT 12, 650
  323.     PAUSE 20
  324.   NEXT
  325.   PAUSE 200
  326.   RETURN
  327.  
  328. LeftRamp45:                          'Smooth left 45 degrees
  329.  FOR counter = 1 TO 30
  330.    PULSOUT 13, 750 - counter
  331.    PULSOUT 12, 750 - counter
  332.    PAUSE 20
  333.  NEXT
  334.  
  335.  FOR counter = 1 TO 15
  336.    PULSOUT 13, 735 + counter
  337.    PULSOUT 12, 735 + counter
  338.    PAUSE 20
  339.  NEXT
  340.  PAUSE 200
  341.  RETURN
  342.  
  343. LeftRamp90:                          'Smooth left 90 degrees
  344.  FOR counter = 1 TO 30
  345.    PULSOUT 13, 750 - counter
  346.    PULSOUT 12, 750 - counter
  347.    PAUSE 20
  348.  NEXT
  349.  
  350.  FOR counter = 1 TO 28
  351.    PULSOUT 13, 714 + counter
  352.    PULSOUT 12, 714 + counter
  353.    PAUSE 20
  354.  NEXT
  355.  PAUSE 200
  356.  RETURN
  357.  
  358. LeftRamp180:                         'Smooth left 180 degrees
  359. FOR counter = 1 TO 56
  360.     PULSOUT 13, 750 - counter
  361.     PULSOUT 12, 750 - counter
  362.     PAUSE 20
  363.   NEXT
  364.  
  365.   FOR counter = 1 TO 30
  366.     PULSOUT 13, 715 + counter
  367.     PULSOUT 12, 715 + counter
  368.     PAUSE 20
  369.   NEXT
  370.   PAUSE 200
  371.   RETURN
  372.  
  373. Jingle:                            'End Program Jingle
  374.   FREQOUT 8, 25, 1865
  375.   FREQOUT 8, 25, $92D
  376.   FREQOUT 8, 25, $AE9
  377.   FREQOUT 8, 50, 3728
  378.   FREQOUT 8, 50, 4186
  379.   RETURN
Advertisement
Add Comment
Please, Sign In to add comment