Last active
May 11, 2017 01:20
-
-
Save sasaco/e5c00d6245b6651dd1b527b5280ee1dc to your computer and use it in GitHub Desktop.
セグウェイを自作してみた ~電子回路組立編~ ref: http://qiita.com/sasaco/items/b72819993790443877ec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MPU6050 connection successful | |
Initializing Mortor Driver digital pins... | |
3.80 -2.61 62.21 | |
4.21 -2.29 59.24 | |
3.96 -2.11 59.01 | |
4.10 -2.42 60.26 | |
3.86 -2.58 61.87 | |
3.46 -2.83 64.63 | |
4.27 -2.49 60.12 | |
3.84 -2.40 60.95 | |
4.26 -2.19 58.56 | |
4.01 -2.33 60.09 | |
3.95 -2.30 60.09 | |
4.12 -2.50 60.62 | |
3.65 -2.47 62.04 | |
3.86 -2.14 59.49 | |
3.87 -2.55 61.66 | |
4.10 -2.40 60.14 | |
3.74 -2.94 64.09 | |
3.89 -2.22 59.84 | |
3.85 -2.22 59.97 | |
3.81 -3.00 64.11 | |
3.96 -2.01 58.46 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Wire.h" | |
#include "I2Cdev.h" | |
#include "MPU6050.h" | |
/* MPU-6050 Accelerometer + Gyro */ | |
MPU6050 accelgyro; | |
void setup() { | |
Wire.begin(); | |
Serial.begin(9600); | |
// initialize device | |
accelgyro.initialize(); | |
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); | |
} | |
void loop() { | |
int16_t ax, ay, az; | |
int16_t gx, gy, gz; | |
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); | |
float acc_x = ax / 16384.0; | |
float acc_y = ay / 16384.0; | |
float acc_z = az / 16384.0; | |
float rate_X = atan2(acc_x, acc_z) * 360 / 2.0 / PI; | |
float rate_Y = atan2(acc_y, acc_z) * 360 / 2.0 / PI; | |
float rate_Z = atan2(acc_x, acc_y) * 180 / 2.0 / PI; | |
Serial.print(rate_X); | |
Serial.print("\t"); | |
Serial.print(rate_Y); | |
Serial.print("\t"); | |
Serial.print(rate_Z); | |
Serial.print("\t"); | |
Serial.println(""); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment