Advertisement
Guest User

Redbot Acclerometer Test Code

a guest
Feb 18th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.39 KB | None | 0 0
  1. //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  2. //  Title: Accelrometer readings though 90 degrees
  3. //  Author: Third_meow - 三喵
  4. //  Discription: Redbot takes (and displayes on serial monitor) the accelerometer readings, then turns a small amount and takes(and diplays) accel readings.
  5. //    Redbot repeats this 14 times, ending up at 90 degrees right of the starting point. This program was written to help understand how the accelerometor readings correlate to
  6. //    redbot movment.
  7. //  Date: 16 Febuary 2017
  8. //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  9.  
  10.  
  11. #include <RedBot.h>
  12. RedBotMotors motors;
  13. RedBotAccel accelerometer;
  14. const int buzzerPin = 9;
  15. int loop_amount = 0;
  16.  
  17. //sets up the redbot libary, the motors, the accelerometer and the buzzer.
  18.  
  19. void setup(void)
  20. {
  21.   pinMode(buzzerPin, OUTPUT);   // configures the buzzerPin as an OUTPUT
  22.  
  23.   Serial.begin(9600);
  24.   Serial.println("Accelerometer Readings:");
  25.   Serial.println();
  26.   Serial.println("(X, Y, Z) -- [X-Z, Y-Z, X-Y]");
  27.   Serial.println("_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-");
  28.  
  29.   //prints the tilte info about accelerometer to screen
  30.  
  31.   //**************************************************************************
  32.   accelerometer.read();   // updates the x, y, and z axis readings on the acceleromter
  33.  
  34.   Serial.print("(");
  35.   Serial.print(accelerometer.x);
  36.   Serial.print(", ");
  37.  
  38.   Serial.print(accelerometer.y);
  39.   Serial.print(", ");
  40.  
  41.   Serial.print(accelerometer.z);
  42.   Serial.print(") -- ");
  43.  
  44.   Serial.print("[");
  45.   Serial.print(accelerometer.angleXZ);
  46.   Serial.print(", ");
  47.   Serial.print(accelerometer.angleYZ);
  48.   Serial.print(", ");
  49.   Serial.print(accelerometer.angleXY);
  50.   Serial.println("]");
  51.   // prints the accerlerometer readings to screen
  52.  
  53.   Serial.print("INITIAL READING COMPLETE");    //prints INITIAL READING COMPLETE to your screen
  54.   delay(1000);   // waits 1000 milliseconds
  55.   Serial.print("TURN STARTING");   //prints TURN STARTING to your screen
  56.   //tone(buzzerPin, 1000);   // Creats a buzzing sound
  57.   delay(2000);   // waits 2000 milliseconds
  58.   noTone(buzzerPin);   //turns off buzzing sound
  59.  
  60.   // warns you program setup is finished and loop is about to start
  61.  
  62.  
  63.  
  64.   while (loop_amount < 14) { //repeats code below 14 times
  65.  
  66.     motors.rightMotor(-150);
  67.     motors.leftMotor(-150);
  68.     delay(100);
  69.     motors.brake();
  70.     delay(1000);
  71.  
  72.  
  73.     //pivits robot a small amount
  74.  
  75.     accelerometer.read();   // updates the x, y, and z axis readings on the acceleromter
  76.  
  77.     Serial.print("(");
  78.     Serial.print(accelerometer.x);
  79.     Serial.print(", ");
  80.  
  81.     Serial.print(accelerometer.y);
  82.     Serial.print(", ");
  83.  
  84.     Serial.print(accelerometer.z);
  85.     Serial.print(") -- ");
  86.  
  87.     Serial.print("[");
  88.     Serial.print(accelerometer.angleXZ);
  89.     Serial.print(", ");
  90.     Serial.print(accelerometer.angleYZ);
  91.     Serial.print(", ");
  92.     Serial.print(accelerometer.angleXY);
  93.     Serial.println("]");
  94.     // prints the accerlerometer readings to screen
  95.     delay(100);
  96.  
  97.     loop_amount = loop_amount + 1;
  98.  
  99.   }
  100.  
  101. }
  102.  
  103. void loop(void)   // repeats code below infinely
  104. {
  105. // this has been deliberately left blank
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement