mirror of
https://github.com/okalachev/flix.git
synced 2025-07-27 17:49:33 +00:00
Rotate IMU data to support standard axes orientation in new FlixPeriph
This commit is contained in:
parent
fcb426a16f
commit
77effa5577
@ -135,13 +135,13 @@ Complete diagram is Work-in-Progress.
|
|||||||
|
|
||||||
### IMU placement
|
### IMU placement
|
||||||
|
|
||||||
Required IMU orientation on the drone is **FLU** (Forward, Left, Up)⁷:
|
Default IMU orientation in the code is **LFD** (Left-Forward-Down):
|
||||||
|
|
||||||
<img src="docs/img/flu.svg" width=400 alt="GY-91 axis">
|
<img src="docs/img/gy91-lfd.svg" width=400 alt="GY-91 axes">
|
||||||
|
|
||||||
In case of using **FRD** orientation (Forward, Right, Down), use [the code for rotation](https://gist.github.com/okalachev/713db47e31bce643dbbc9539d166ce98).
|
In case of using other IMU orientation, modify the `rotateIMU` function in the `imu.ino` file.
|
||||||
|
|
||||||
*⁷ — This X/Y/Z IMU axis orientation is used in the Flix IMU library, internal accel/gyro/mag axes differ.*
|
See [FlixPeriph documentation](https://github.com/okalachev/flixperiph?tab=readme-ov-file#imu-axes-orientation) to learn axis orientation of other IMU boards.
|
||||||
|
|
||||||
## Version 0
|
## Version 0
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 47 KiB |
78
docs/img/gy91-lfd.svg
Normal file
78
docs/img/gy91-lfd.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 47 KiB |
@ -21,6 +21,7 @@ Do the following:
|
|||||||
* **Check the IMU data**. Perform `imu` command, check raw accelerometer and gyro output. The output should change as you move the drone.
|
* **Check the IMU data**. Perform `imu` command, check raw accelerometer and gyro output. The output should change as you move the drone.
|
||||||
* **Calibrate the accelerometer.** if is wasn't done before. Perform `ca` command and put the results to `imu.ino` file.
|
* **Calibrate the accelerometer.** if is wasn't done before. Perform `ca` command and put the results to `imu.ino` file.
|
||||||
* **Check the attitude estimation**. Connect to the drone using QGroundControl. Rotate the drone in different orientations and check if the attitude estimation shown in QGroundControl is correct.
|
* **Check the attitude estimation**. Connect to the drone using QGroundControl. Rotate the drone in different orientations and check if the attitude estimation shown in QGroundControl is correct.
|
||||||
|
* **Check the IMU orientation is set correctly**. If the attitude estimation is rotated, make sure `rotateIMU` function is defined correctly in `imu.ino` file.
|
||||||
* **Check the motors**. Perform the following commands using Serial Monitor:
|
* **Check the motors**. Perform the following commands using Serial Monitor:
|
||||||
* `mfr` — should rotate front right motor (counter-clockwise).
|
* `mfr` — should rotate front right motor (counter-clockwise).
|
||||||
* `mfl` — should rotate front left motor (clockwise).
|
* `mfl` — should rotate front left motor (clockwise).
|
||||||
|
13
flix/imu.ino
13
flix/imu.ino
@ -2,9 +2,6 @@
|
|||||||
// Repository: https://github.com/okalachev/flix
|
// Repository: https://github.com/okalachev/flix
|
||||||
|
|
||||||
// Work with the IMU sensor
|
// Work with the IMU sensor
|
||||||
// IMU is oriented FLU (front-left-up) style.
|
|
||||||
// In case of FRD (front-right-down) orientation of the IMU, use this code:
|
|
||||||
// https://gist.github.com/okalachev/713db47e31bce643dbbc9539d166ce98.
|
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <MPU9250.h>
|
#include <MPU9250.h>
|
||||||
@ -45,6 +42,16 @@ void readIMU() {
|
|||||||
// apply scale and bias
|
// apply scale and bias
|
||||||
acc = (acc - accBias) / accScale;
|
acc = (acc - accBias) / accScale;
|
||||||
gyro = gyro - gyroBias;
|
gyro = gyro - gyroBias;
|
||||||
|
// rotate
|
||||||
|
rotateIMU(acc);
|
||||||
|
rotateIMU(gyro);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rotateIMU(Vector& data) {
|
||||||
|
// Rotate from LFD to FLU
|
||||||
|
// NOTE: In case of using other IMU orientation, change this line:
|
||||||
|
data = Vector(data.y, data.x, -data.z);
|
||||||
|
// Axes orientation for various boards: https://github.com/okalachev/flixperiph#imu-axes-orientation
|
||||||
}
|
}
|
||||||
|
|
||||||
void calibrateGyro() {
|
void calibrateGyro() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user