Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

MPU implemented as a compass compatible with Arduino Framework at C.

NotificationsYou must be signed in to change notification settings

jeimison3/MPUOrientation

Repository files navigation

Approach

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.

ESP32 native Core problem with I2C

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.

Using

Including LIB

#include<MPUOrientation.h>

Creating contexts

Contexts are useful in recursive operations (like in Kalman filter). So we need to use one for each MPU.

pCompassContextCNTX=createContext();

Calculating time between recall (Arduino)

//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

Calculating orientation as IMUFullFusion

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);

Or calculating orientation as IMUFusion (no Mag)

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.

Print orientation

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.

Some optimizations

We consider to port thelibfixmath to reduce cycles of calculation. Maybe a #define will be included in next versions ofcompassSet.h.

Description about examples

Examble pathFunctionality
ESP-NO-LIBCalculate the axisPitch,Roll andYaw using magnetometer without the library.
ESP-Kalman-NO-MAGCalculate the axisPitch andRoll with the library.
ESP-Kalman-CompassCalculate the axisPitch,Roll andYaw with the library.
ESP-Madgwick-Kalman-Full-CompareA comparision between Kalman Filter and Madgwick quaternions calculation result. Compatible with processing script "Graph"
ESP-All-Full-CompareA comparision bretween all fusion algorithms. Compatible with processing script "Graph3Mod".

Libraries

  • Kalman Filter. Now is already ported.
  • MPU9250Download here. That's a fork from original library frombolderflight but with some implementations that I made for ESP8266/ESP32 in the "begin" function.

[8]ページ先頭

©2009-2025 Movatter.jp