Created
December 23, 2019 02:14
-
-
Save jokandre/31e18e49eec75bd0f4176c5f2f817797 to your computer and use it in GitHub Desktop.
M5StickC resources
This file contains hidden or 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
| int xAng = map(AcX,minVal,maxVal,-90,90); int yAng = map(AcY,minVal,maxVal,-90,90); int zAng = map(AcZ,minVal,maxVal,-90,90); | |
| x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI); y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI); z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI); | |
| https://docs.platformio.org/en/latest/ide/pioide.html | |
| https://github.com/AazimHassan/M5StickC | |
| https://m5stack.hackster.io/shasha-liu/magic-wand-752f52 | |
| https://github.com/m5stack/MagicWand | |
| https://www.pieter-jan.com/node/11 | |
| ``` | |
| #define ACCELEROMETER_SENSITIVITY 8192.0 | |
| #define GYROSCOPE_SENSITIVITY 65.536 | |
| #define M_PI 3.14159265359 | |
| #define dt 0.01 // 10 ms sample rate! | |
| void ComplementaryFilter(short accData[3], short gyrData[3], float *pitch, float *roll) | |
| { | |
| float pitchAcc, rollAcc; | |
| // Integrate the gyroscope data -> int(angularSpeed) = angle | |
| *pitch += ((float)gyrData[0] / GYROSCOPE_SENSITIVITY) * dt; // Angle around the X-axis | |
| *roll -= ((float)gyrData[1] / GYROSCOPE_SENSITIVITY) * dt; // Angle around the Y-axis | |
| // Compensate for drift with accelerometer data if !bullshit | |
| // Sensitivity = -2 to 2 G at 16Bit -> 2G = 32768 && 0.5G = 8192 | |
| int forceMagnitudeApprox = abs(accData[0]) + abs(accData[1]) + abs(accData[2]); | |
| if (forceMagnitudeApprox > 8192 && forceMagnitudeApprox < 32768) | |
| { | |
| // Turning around the X axis results in a vector on the Y-axis | |
| pitchAcc = atan2f((float)accData[1], (float)accData[2]) * 180 / M_PI; | |
| *pitch = *pitch * 0.98 + pitchAcc * 0.02; | |
| // Turning around the Y axis results in a vector on the X-axis | |
| rollAcc = atan2f((float)accData[0], (float)accData[2]) * 180 / M_PI; | |
| *roll = *roll * 0.98 + rollAcc * 0.02; | |
| } | |
| } | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment