Timendainum

Wanderer1.ino

Nov 6th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include "RangeFinder.h"
  2. #include "MotorDriver.h"
  3. #include "Timer.h"
  4.  
  5. #include "Behavior.h"
  6. #include "Motivator.h"
  7. #include "Task.h"
  8.  
  9. #include "WandererMotivator.h"
  10.  
  11. //Motor users D8-13
  12. #define TP 6      //Trig_pin
  13. #define EP 7      //Echo_pin
  14.  
  15. WandererMotivator motivator;
  16.  
  17. void setup()
  18. {
  19.   Serial.println("*************************************");
  20.   Serial.println("***************Startup***************");
  21.   Serial.println("*************************************");
  22.  
  23.   //Setup serial
  24.   Serial.begin(9600);      // init serial 9600
  25.  
  26.   //timer
  27.   timer.init();
  28.  
  29.   //Configure the motor A to control the wheel at the left side.
  30.   //Configure the motor B to control the wheel at the right side.
  31.   motordriver.init();
  32.   motordriver.setSpeed(200,MOTORA);
  33.   motordriver.setSpeed(200,MOTORB);
  34.  
  35.   //configure rangefinder
  36.   rangeFinder.init(TP, EP, 1);
  37. }
  38.  
  39. void loop()
  40. {
  41.   //Serial.println("SL: ");
  42.   timer.update();
  43.  
  44.   motivator.motivate();
  45.   //Serial.println(":EL");
  46. }
  47.  
  48.  
  49. /*
  50. void loop()
  51. {
  52.   //Sensor update
  53.   distance = rangeFinder.getDistance();
  54.  
  55.   //Update Time
  56.   timer.update();
  57.  
  58.   //Determine behavior
  59.   activeBehavior = determineBehavior();
  60.  
  61.   //call behavior
  62.   switch(activeBehavior)
  63.   {
  64.     case B_STOP:
  65.     behaveStop();
  66.     break;
  67.     case B_DRIVE:
  68.     behaveDrive();
  69.     break;
  70.     case B_AVOID:
  71.     behaveAvoid();
  72.     break;
  73.     case B_SCAN:
  74.     behaveScan();
  75.     break;
  76.     default:
  77.     behaveStop();
  78.     break;
  79.   }
  80. }
  81.  
  82. int determineBehavior()
  83. {
  84.   int result = B_INVALID;
  85.   if (distance < T_DISTANCE)
  86.   {
  87.     result = B_AVOID;
  88.   }
  89.   else
  90.   {
  91.     result = B_DRIVE;
  92.   }
  93.   return result;
  94. }
  95.  
  96. // --------------- behavior functions ---------------
  97. void behaveStop()
  98. {
  99.   if (activeBehavior != B_STOP)
  100.   {
  101.     elapsedBehavior = 0;
  102.     elapsedTask = 0;
  103.   }
  104.   motordriver.stop();
  105. }
  106.  
  107. void behaveDrive()
  108. {
  109.   if (activeBehavior != B_DRIVE)
  110.   {
  111.     elapsedBehavior = 0;
  112.     elapsedTask = 0;
  113.   }
  114.   motordriver.goForward();
  115. }
  116.  
  117. void behaveAvoid()
  118. {
  119.   if (activeBehavior != B_AVOID)
  120.   {
  121.     elapsedBehavior = 0;
  122.     elapsedTask = 0;
  123.   }
  124.   motordriver.goRight();
  125. }
  126.  
  127. void behaveScan()
  128. {
  129.   int turnDelay = 1000;
  130.   motordriver.goLeft();
  131.   delay(turnDelay);
  132.   motordriver.stop();
  133.   motordriver.goRight();
  134.   delay(turnDelay);
  135.   delay(turnDelay);  
  136.   motordriver.goLeft();
  137.   delay(turnDelay);
  138. }
  139.  
  140. */
Advertisement
Add Comment
Please, Sign In to add comment