Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
hideakitai committed May 28, 2021
1 parent 23fb7d9 commit 5af360f
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "MPU9250.h"
#include "ArduinoOSC.h"
#include "ArduinoOSCWiFi.h"

MPU9250 mpu;

Expand All @@ -26,6 +26,12 @@ struct Euler {
float z;
} euler;

struct RPY {
float r;
float p;
float y;
} rpy;

void setup() {
Serial.begin(115200);
Wire.begin();
Expand All @@ -48,6 +54,10 @@ void setup() {
}
}

// mpu.selectFilter(QuatFilterSel::NONE);
// mpu.selectFilter(QuatFilterSel::MADGWICK);
// mpu.selectFilter(QuatFilterSel::MAHONY);

// calibrate anytime you want to
Serial.println("Accel Gyro calibration will start in 5sec.");
Serial.println("Please leave the device still on the flat plane.");
Expand All @@ -65,6 +75,7 @@ void setup() {

OscWiFi.publish(host, publish_port, "/quat", quat.x, quat.y, quat.z, quat.w);
OscWiFi.publish(host, publish_port, "/euler", euler.x, euler.y, euler.z);
OscWiFi.publish(host, publish_port, "/rpy", rpy.r, rpy.p, rpy.y);
}

void loop() {
Expand All @@ -81,6 +92,9 @@ void loop() {
euler.x = mpu.getEulerX();
euler.y = mpu.getEulerY();
euler.z = mpu.getEulerZ();
rpy.r = mpu.getRoll();
rpy.p = mpu.getPitch();
rpy.y = mpu.getYaw();
}
OscWiFi.update();
}
Expand All @@ -91,7 +105,21 @@ void print_roll_pitch_yaw() {
Serial.print(", ");
Serial.print(mpu.getPitch(), 2);
Serial.print(", ");
Serial.println(mpu.getRoll(), 2);
Serial.print(mpu.getRoll(), 2);
Serial.print(" ");
Serial.print("Mag : ");
Serial.print(mpu.getMagX(), 2);
Serial.print(", ");
Serial.print(mpu.getMagY(), 2);
Serial.print(", ");
Serial.print(mpu.getMagZ(), 2);
Serial.print(", ");
Serial.print("lin_acc = ");
Serial.print(mpu.getLinearAccX(), 2);
Serial.print(", ");
Serial.print(mpu.getLinearAccY(), 2);
Serial.print(", ");
Serial.println(mpu.getLinearAccZ(), 2);
}

void print_calibration() {
Expand Down

0 comments on commit 5af360f

Please sign in to comment.