Zanuark

Lab 7

Apr 23rd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #include <RedBot.h> //includes the redbot library
  2. RedBotMotors motors;// Instantiate the motor control object.
  3. RedBotSensor IRSensor1 = RedBotSensor(A4);// initialize sensors - left IR
  4. RedBotSensor IRSensor2 = RedBotSensor(A5);// right IR
  5. RedBotBumper lBumper = RedBotBumper(3); // Left bumper
  6. RedBotBumper rBumper = RedBotBumper(11); //Right bumper
  7. int thr = 950; // wood floor varies more
  8. int lSpeed = -70; //forward speed
  9. int rSpeed = 55; //right speed significantly slowed so it can slowly curve right when moving forward.
  10. int lBumperState; //detect bumper touch
  11. int rBumperState; //detect bumper touch
  12. void setup() {
  13.  
  14. //test code
  15.  
  16. //motors.leftMotor(-80);
  17. //motors.rightMotor(75);
  18. //delay(6000);
  19. //motors.stop();
  20. //delay(100);
  21. //motors.leftMotor(-100);
  22. //motors.rightMotor(-100);
  23. //delay(520);
  24. //motors.stop();
  25. Serial.begin(9600);
  26.  
  27. }
  28.  
  29. void loop() {
  30.  
  31. //test code
  32.  
  33. ///Serial.print(IRSensor1.read());
  34. //Serial.print("\t");// tab character
  35. //Serial.print(IRSensor2.read());
  36. //Serial.print("\t");
  37. motors.leftMotor(lSpeed);
  38. motors.rightMotor(rSpeed);
  39. lBumperState = lBumper.read();
  40. rBumperState = rBumper.read();
  41.  
  42. if(lBumperState == LOW && rBumperState == HIGH) { //Left bumper triggered, back up and turn left large.
  43. motors.stop();
  44. delay(250);
  45. motors.leftMotor(60);
  46. motors.rightMotor(-56);
  47. delay(1000);
  48. motors.stop();
  49. motors.leftMotor(60);
  50. motors.rightMotor(60);
  51. delay(700);
  52. motors.leftMotor(lSpeed);
  53. motors.rightMotor(rSpeed);
  54. }
  55. if(lBumperState == LOW && rBumperState == LOW) { //Left and right bumper triggered, back up and left large.
  56. motors.stop();
  57. delay(250);
  58. motors.leftMotor(60);
  59. motors.rightMotor(-56);
  60. delay(1000);
  61. motors.stop();
  62. delay(250);
  63. motors.leftMotor(60);
  64. motors.rightMotor(60);
  65. delay(600);
  66. motors.leftMotor(lSpeed);
  67. motors.rightMotor(rSpeed);
  68. }
  69. if(rBumperState == LOW && lBumperState == HIGH){ //Right bumper triggered, back up and turn left small
  70. motors.stop();
  71. motors.leftMotor(60);
  72. motors.rightMotor(-56);
  73. delay(500);
  74. motors.stop();
  75. delay(250);
  76. motors.leftMotor(60);
  77. motors.rightMotor(60);
  78. delay(400);
  79. motors.stop();
  80. motors.leftMotor(lSpeed);
  81. motors.rightMotor(rSpeed);
  82. }
  83.  
  84. //test code
  85.  
  86. //Serial.print(IRSensor1.read());
  87. //Serial.print("\t");// tab character
  88. //Serial.print(IRSensor2.read());
  89. //Serial.print("\t");
  90. }
Advertisement
Add Comment
Please, Sign In to add comment