-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
455 additions
and
447 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
# basicMPU6050 | ||
The purpose of this library is to make a basic and lightweight interface for the MPU6050. It can do the following: | ||
- Configure the inbuilt low pass filter | ||
- Configure the sensitivity of the accelerometer and gyro | ||
- Retrieve the raw output of the sensor | ||
- Output scaled accelerometer and gyro values | ||
|
||
The library includes two functions to calibrate the gyro and remove bias. The first is intended to be called when the sensor is turned on and is not moving. It takes a long term average of the output of each axis and subtracts these values from the raw signals. | ||
|
||
The second function is designed to update the averages. It updates the values with a moving average and the gain is controlled by something akin to a kalman filter. By polling this function one can correct for drift in the gyro bias. | ||
|
||
By combining these two functions one can obtain stable and consistent gyro outputs. The accelerometer needs to calibrated manually by correcting the bias and scale. | ||
|
||
See this link for the information on the registers of the MPU6050: | ||
[MPU 6050 register map](https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf) | ||
# basicMPU6050 | ||
The purpose of this library is to make a basic and lightweight interface for the MPU6050. It can do the following: | ||
- Configure the inbuilt low pass filter | ||
- Configure the sensitivity of the accelerometer and gyro | ||
- Retrieve the raw output of the sensor | ||
- Output scaled accelerometer and gyro values | ||
|
||
The library includes two functions to calibrate the gyro and remove bias. The first is intended to be called when the sensor is turned on and is not moving. It takes a long term average of the output of each axis and subtracts these values from the raw signals. | ||
|
||
The second function is designed to update the averages. It updates the values with a moving average and the gain is controlled by something akin to a kalman filter. By polling this function one can correct for drift in the gyro bias. By combining these two functions one can obtain stable and consistent gyro outputs. However, The accelerometer needs to calibrated manually by correcting the bias and scale. | ||
|
||
Finally, the library was written for a single MPU6050 connected to a MEGA board as follows. It may require some modifications to work succesfully on other boards: | ||
|
||
<img src = "https://www.prometec.net/wp-content/uploads/2015/10/MPU-6050-Board-GY-521-MEGA_bb.png" width = "60%"></img> | ||
|
||
See this link for the information on the registers of the MPU6050: | ||
[MPU 6050 register map](https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf) |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,73 @@ | ||
/* | ||
This sketch shows how to configure the output | ||
*/ | ||
|
||
#include <basicMPU6050.h> | ||
|
||
//-- Input parameters: | ||
|
||
// Gyro settings: | ||
#define LP_FILTER 3 // Low pass filter. Value from 0 to 6 | ||
#define GYRO_SENS 0 // Gyro sensitivity. Value from 0 to 3 | ||
#define ACCEL_SENS 0 // Accelerometer sensitivity. Value from 0 to 3 | ||
|
||
// Accelerometer offset: | ||
constexpr int AX_OFFSET = 552; // Use these values to calibrate the accelerometer. The sensor should output 1.0g if held level. | ||
constexpr int AY_OFFSET = -241; // These values are unlikely to be zero. | ||
constexpr int AZ_OFFSET = -3185; | ||
|
||
// Output scale: | ||
constexpr float AX_SCALE = 1.00457; // Multiplier for accelerometer outputs. Use this to calibrate the sensor. If unknown set to 1. | ||
constexpr float AY_SCALE = 0.99170; | ||
constexpr float AZ_SCALE = 0.98317; | ||
|
||
constexpr float GX_SCALE = 0.99764; // Multiplier to gyro outputs. Use this to calibrate the sensor. If unknown set to 1. | ||
constexpr float GY_SCALE = 1.0; | ||
constexpr float GZ_SCALE = 1.01037; | ||
|
||
// Bias estimate: | ||
#define GYRO_BAND 35 // Standard deviation of the gyro signal. Gyro signals within this band (relative to the mean) are suppresed. | ||
#define BIAS_COUNT 5000 // Samples of the mean of the gyro signal. Larger values provide better calibration but delay suppression response. | ||
|
||
//-- Set the template parameters: | ||
|
||
basicMPU6050<LP_FILTER, GYRO_SENS, ACCEL_SENS, | ||
AX_OFFSET, AY_OFFSET, AZ_OFFSET, | ||
&AX_SCALE, &AY_SCALE, &AZ_SCALE, | ||
&GX_SCALE, &GY_SCALE, &GZ_SCALE, | ||
GYRO_BAND, BIAS_COUNT | ||
>imu; | ||
|
||
void setup() { | ||
// Set registers - Always required | ||
imu.setup(); | ||
|
||
// Initial calibration of gyro | ||
imu.setBias(); | ||
|
||
// Start console | ||
Serial.begin(38400); | ||
} | ||
|
||
void loop() { | ||
// Update gyro calibration | ||
imu.updateBias(); | ||
|
||
//-- Scaled and calibrated output: | ||
// Accel | ||
Serial.print( imu.ax() ); | ||
Serial.print( " " ); | ||
Serial.print( imu.ay() ); | ||
Serial.print( " " ); | ||
Serial.print( imu.az() ); | ||
Serial.print( " " ); | ||
|
||
// Gyro | ||
Serial.print( imu.gx() ); | ||
Serial.print( " " ); | ||
Serial.print( imu.gy() ); | ||
Serial.print( " " ); | ||
Serial.print( imu.gz() ); | ||
Serial.println(); | ||
} | ||
/* | ||
This sketch shows how to configure the output | ||
*/ | ||
|
||
#include <basicMPU6050.h> | ||
|
||
//-- Input parameters: | ||
|
||
// Gyro settings: | ||
#define LP_FILTER 3 // Low pass filter. Value from 0 to 6 | ||
#define GYRO_SENS 0 // Gyro sensitivity. Value from 0 to 3 | ||
#define ACCEL_SENS 0 // Accelerometer sensitivity. Value from 0 to 3 | ||
#define ADDRESS_A0 HIGH // I2C address from state of A0 pin. A0 -> GND : ADDRESS_A0 = LOW | ||
// A0 -> 5v : ADDRESS_A0 = HIGH | ||
// Accelerometer offset: | ||
constexpr int AX_OFFSET = 552; // Use these values to calibrate the accelerometer. The sensor should output 1.0g if held level. | ||
constexpr int AY_OFFSET = -241; // These values are unlikely to be zero. | ||
constexpr int AZ_OFFSET = -3185; | ||
|
||
// Output scale: | ||
constexpr float AX_SCALE = 1.00457; // Multiplier for accelerometer outputs. Use this to calibrate the sensor. If unknown set to 1. | ||
constexpr float AY_SCALE = 0.99170; | ||
constexpr float AZ_SCALE = 0.98317; | ||
|
||
constexpr float GX_SCALE = 0.99764; // Multiplier to gyro outputs. Use this to calibrate the sensor. If unknown set to 1. | ||
constexpr float GY_SCALE = 1.0; | ||
constexpr float GZ_SCALE = 1.01037; | ||
|
||
// Bias estimate: | ||
#define GYRO_BAND 35 // Standard deviation of the gyro signal. Gyro signals within this band (relative to the mean) are suppresed. | ||
#define BIAS_COUNT 5000 // Samples of the mean of the gyro signal. Larger values provide better calibration but delay suppression response. | ||
|
||
//-- Set the template parameters: | ||
|
||
basicMPU6050<LP_FILTER, GYRO_SENS, ACCEL_SENS, ADDRESS_A0, | ||
AX_OFFSET, AY_OFFSET, AZ_OFFSET, | ||
&AX_SCALE, &AY_SCALE, &AZ_SCALE, | ||
&GX_SCALE, &GY_SCALE, &GZ_SCALE, | ||
GYRO_BAND, BIAS_COUNT | ||
>imu; | ||
|
||
void setup() { | ||
// Set registers - Always required | ||
imu.setup(); | ||
|
||
// Initial calibration of gyro | ||
imu.setBias(); | ||
|
||
// Start console | ||
Serial.begin(38400); | ||
} | ||
|
||
void loop() { | ||
// Update gyro calibration | ||
imu.updateBias(); | ||
|
||
//-- Scaled and calibrated output: | ||
// Accel | ||
Serial.print( imu.ax() ); | ||
Serial.print( " " ); | ||
Serial.print( imu.ay() ); | ||
Serial.print( " " ); | ||
Serial.print( imu.az() ); | ||
Serial.print( " " ); | ||
|
||
// Gyro | ||
Serial.print( imu.gx() ); | ||
Serial.print( " " ); | ||
Serial.print( imu.gy() ); | ||
Serial.print( " " ); | ||
Serial.print( imu.gz() ); | ||
Serial.println(); | ||
} |
Empty file.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=basicMPU6050 | ||
version=0.1.0 | ||
version=0.2.0 | ||
author=RCmags <memoryofatrufestival@gmail.com> | ||
maintainer=RCmags <memoryofatrufestival@gmail.com> | ||
sentence=light library for the MPU6050. | ||
paragraph=Lightweight library to configure and retrieve the raw sensor outputs of the MPU6050. It includes simples routines to calibrate the gyro. | ||
sentence=lightweight library for the MPU6050. | ||
paragraph=library to configure and retrieve the raw sensor outputs of the MPU6050. It includes simples routines to calibrate the gyro. | ||
category=Device Control | ||
url=https://github.com/RCmags/basicMPU6050.git | ||
architectures=* |
Oops, something went wrong.