- Notifications
You must be signed in to change notification settings - Fork5
jeimison3/MPUOrientation
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Not every sensor comes with a library which include orientation calculation.This library is compatible with C and C++ compilers and solve the calculations by applying the Kalman filter.
The Arduino IDE with Espressif native port for ESP32 has conflicted withWire
library.So I met the core ofstickbreaker (click here) so currently is not necessary any change in the code between ESP32 and ESP8266.The code pressupose a valid and calibrated value to sensors input.
#include<MPUOrientation.h>
Contexts are useful in recursive operations (like in Kalman filter). So we need to use one for each MPU.
pCompassContextCNTX=createContext();
//Declare global variable:uint32_ttimer;...// Inside loop(), when need to use delta time "dt"doubledt= (double)(micros()-timer) /1000000;// Calculate as secondtimer=micros();// Reset time
IMUFullFusionSENS;SENS.ACCEL.x=IMU.getAccelX_mss();SENS.ACCEL.y=IMU.getAccelY_mss();SENS.ACCEL.z=IMU.getAccelZ_mss();SENS.GYRO.x=IMU.getGyroX_rads();SENS.GYRO.y=IMU.getGyroY_rads();SENS.GYRO.z=IMU.getGyroZ_rads();SENS.MAG.x=IMU.getMagX_uT();SENS.MAG.y=IMU.getMagY_uT();SENS.MAG.z=IMU.getMagZ_uT();// Context, ALGO, IMUFullFusion and time variance in secondsIMUOrientationori=getFullOrientation(CNTX,ALGO_SOMETHING,SENS,dt);
IMUFusionSENS;SENS.ACCEL.x=IMU.getAccelX_mss();SENS.ACCEL.y=IMU.getAccelY_mss();SENS.ACCEL.z=IMU.getAccelZ_mss();SENS.GYRO.x=IMU.getGyroX_rads();SENS.GYRO.y=IMU.getGyroY_rads();SENS.GYRO.z=IMU.getGyroZ_rads();// Context, ALGO, IMUFusion and time variance in secondsIMUOrientationori=getOrientation(CNTX,ALGO_SOMETHING,SENS,dt);
Remember to replace "ALGO_SOMETHING" byALGO_KALMAN_V1
orALGO_MADGWICK_V1
.
Serial.printf("\t%f\t%f\t%f\n",ori.pitch,ori.roll,ori.yaw );
This and other examples you can find in examples folder.
We consider to port thelibfixmath
to reduce cycles of calculation. Maybe a #define will be included in next versions ofcompassSet.h
.
Examble path | Functionality |
---|---|
ESP-NO-LIB | Calculate the axisPitch ,Roll andYaw using magnetometer without the library. |
ESP-Kalman-NO-MAG | Calculate the axisPitch andRoll with the library. |
ESP-Kalman-Compass | Calculate the axisPitch ,Roll andYaw with the library. |
ESP-Madgwick-Kalman-Full-Compare | A comparision between Kalman Filter and Madgwick quaternions calculation result. Compatible with processing script "Graph" |
ESP-All-Full-Compare | A comparision bretween all fusion algorithms. Compatible with processing script "Graph3Mod". |
Kalman Filter
. Now is already ported.- MPU9250
Download here
. That's a fork from original library frombolderflight but with some implementations that I made for ESP8266/ESP32 in the "begin" function.