Zanuark

Useless piece of shiz

Apr 21st, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 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 = 65; //back speed
  10. int turn = 60; //turn speed that worked
  11. int lBumperState; //detect bumper touch
  12. int rBumperState; //detect bumper touch
  13. void setup() {
  14.  
  15. //test code
  16.  
  17. //motors.leftMotor(-80);
  18. //motors.rightMotor(75);
  19. //delay(6000);
  20. //motors.stop();
  21. //delay(100);
  22. //motors.leftMotor(-100);
  23. //motors.rightMotor(-100);
  24. //delay(520);
  25. //motors.stop();
  26. Serial.begin(9600);
  27.  
  28. }
  29.  
  30. void loop() {
  31.  
  32. //test code
  33.  
  34. ///Serial.print(IRSensor1.read());
  35. //Serial.print("\t");// tab character
  36. //Serial.print(IRSensor2.read());
  37. //Serial.print("\t");
  38. motors.leftMotor(lSpeed);
  39. motors.rightMotor(rSpeed);
  40. lBumperState = lBumper.read();
  41. rBumperState = rBumper.read();
  42.  
  43. if(lBumperState == LOW || rBumperState == LOW) { //it touched something
  44. motors.stop();
  45. delay(500);
  46. motors.leftMotor(-1*lSpeed);
  47. motors.rightMotor(-1*rSpeed);
  48. delay(500);
  49. motors.stop();
  50. delay(500);
  51. motors.leftMotor(-70);
  52. motors.rightMotor(-70);
  53. delay(700);
  54. motors.stop();
  55. delay(500);
  56. motors.leftMotor(lSpeed);
  57. motors.rightMotor(rSpeed);
  58. delay(2500);
  59. motors.stop();
  60. delay(500);
  61. motors.leftMotor(70);
  62. motors.rightMotor(70);
  63. delay(1000);
  64. motors.stop();
  65. delay(500);
  66. motors.leftMotor(lSpeed);
  67. motors.rightMotor(rSpeed);
  68. delay(3500);
  69. motors.stop();
  70. delay(500);
  71. motors.leftMotor(70);
  72. motors.rightMotor(70);
  73. delay(1000);
  74. motors.stop();
  75. delay(500);
  76. motors.leftMotor(lSpeed);
  77. motors.rightMotor(rSpeed);
  78. delay(2500);
  79. motors.stop();
  80. motors.leftMotor(-70);
  81. motors.rightMotor(-70);
  82. delay(700);
  83. motors.stop();
  84. delay(500);
  85. }
  86.  
  87. if(IRSensor1.read() > thr) { //Left sensor is off the line, compensate by adjusting right.
  88. motors.leftMotor(lSpeed+10);
  89. motors.rightMotor(rSpeed);
  90. }
  91. if (IRSensor2.read() > thr){ //Right sensor is off the line, compensate by adjusting left
  92. motors.leftMotor(lSpeed);
  93. motors.rightMotor(rSpeed+10);
  94. }
  95. //test code
  96.  
  97. //Serial.print(IRSensor1.read());
  98. //Serial.print("\t");// tab character
  99. //Serial.print(IRSensor2.read());
  100. //Serial.print("\t");
  101. }
Advertisement
Add Comment
Please, Sign In to add comment