PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0KB

  1. // Inertial Monitoring Unit (IMU) using Mahony filter.
  2. //
  3. // To view this data, use the Arduino Serial Monitor to watch the
  4. // scrolling angles, or run the OrientationVisualiser example in Processing.
  5. #include <NXPMotionSense.h>
  6. #include <MahonyAHRS.h>
  7. #include <Wire.h>
  8. #include <EEPROM.h>
  9. NXPMotionSense imu;
  10. Mahony filter;
  11. void setup() {
  12. Serial.begin(9600);
  13. imu.begin();
  14. filter.begin(100); // 100 measurements per second
  15. }
  16. void loop() {
  17. float ax, ay, az;
  18. float gx, gy, gz;
  19. float mx, my, mz;
  20. float roll, pitch, heading;
  21. if (imu.available()) {
  22. // Read the motion sensors
  23. imu.readMotionSensor(ax, ay, az, gx, gy, gz, mx, my, mz);
  24. // Update the Mahony filter
  25. filter.update(gx, gy, gz, ax, ay, az, mx, my, mz);
  26. // print the heading, pitch and roll
  27. roll = filter.getRoll();
  28. pitch = filter.getPitch();
  29. heading = filter.getYaw();
  30. Serial.print("Orientation: ");
  31. Serial.print(heading);
  32. Serial.print(" ");
  33. Serial.print(pitch);
  34. Serial.print(" ");
  35. Serial.println(roll);
  36. }
  37. }