PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

47 linhas
1.1KB

  1. // Full orientation sensing using NXP's advanced sensor fusion algorithm.
  2. //
  3. // You *must* perform a magnetic calibration before this code will work.
  4. //
  5. // To view this data, use the Arduino Serial Monitor to watch the
  6. // scrolling angles, or run the OrientationVisualiser example in Processing.
  7. #include <NXPMotionSense.h>
  8. #include <Wire.h>
  9. #include <EEPROM.h>
  10. NXPMotionSense imu;
  11. NXPSensorFusion filter;
  12. void setup() {
  13. Serial.begin(9600);
  14. imu.begin();
  15. filter.begin(100);
  16. }
  17. void loop() {
  18. float ax, ay, az;
  19. float gx, gy, gz;
  20. float mx, my, mz;
  21. float roll, pitch, heading;
  22. if (imu.available()) {
  23. // Read the motion sensors
  24. imu.readMotionSensor(ax, ay, az, gx, gy, gz, mx, my, mz);
  25. // Update the SensorFusion filter
  26. filter.update(gx, gy, gz, ax, ay, az, mx, my, mz);
  27. // print the heading, pitch and roll
  28. roll = filter.getRoll();
  29. pitch = filter.getPitch();
  30. heading = filter.getYaw();
  31. Serial.print("Orientation: ");
  32. Serial.print(heading);
  33. Serial.print(" ");
  34. Serial.print(pitch);
  35. Serial.print(" ");
  36. Serial.println(roll);
  37. }
  38. }