Skip to content

Commit

Permalink
fix #54, calibrate() (#55)
Browse files Browse the repository at this point in the history
- fix #54, calibrate() function, Kudos to jens-kuerten and MArimont3
- minor edits
  • Loading branch information
RobTillaart authored Jun 24, 2024
1 parent 3b08088 commit e23401c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.6.0] - 2024-06-22
- fix #54, calibrate() function, Kudos to jens-kuerten and MArimont3
- minor edits

----

## [0.5.3] - 2024-05-08
- fix #52, add **uint8_t getAddrress()**
- fix #51, add **bool setDLPFMode(uint8_t mode)** and **uint8_t getDLPFMode()**
- add const float GRAVITY=9.80655;
- minor edits


## [0.5.2] - 2024-01-16
- fix #48, use float variables in example GY521_test_1.ino
- add **void calibrate(uint16_t times)** to API
Expand Down Expand Up @@ -72,7 +77,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- update library.json, license, minor edits

## [0.3.5] - 2021-10-20
- update build-CI, badges
- update build-CI, badges
- fix #28 add wakeup to begin().

## [0.3.4] - 2021-07-12
Expand All @@ -85,7 +90,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- fix #20 support multiWire

## [0.3.1] - 2021-06-13
- added more unit test
- added more unit test
- some initialization

## [0.3.0] - 2021-04-07
Expand Down
42 changes: 25 additions & 17 deletions GY521.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: GY521.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.5.3
// VERSION: 0.6.0
// PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor
// URL: https://github.com/RobTillaart/GY521

Expand Down Expand Up @@ -78,31 +78,39 @@ void GY521::calibrate(uint16_t times)
bool oldThrottle = _throttle;
_throttle = false;

// set errors to zero
// set all errors to zero, to get the raw reads.
axe = aye = aze = 0;
gxe = gye = gze = 0;

// use local error sums, to calculate the average error.
float _axe = 0, _aye = 0, _aze = 0;
float _gxe = 0, _gye = 0, _gze = 0;

// adjust times if zero.
if (times == 0) times = 1;

// summarize (6x) the measurements.
for (uint16_t i = 0; i < times; i++)
{
read();
axe -= getAccelX();
aye -= getAccelY();
aze -= getAccelZ();
gxe -= getGyroX();
gye -= getGyroY();
gze -= getGyroZ();
_axe -= getAccelX();
_aye -= getAccelY();
_aze -= getAccelZ();
_gxe -= getGyroX();
_gye -= getGyroY();
_gze -= getGyroZ();
}

// adjust calibration errors so table should get all zero's.
// adjust calibration errors so read() should get all zero's on average.
float factor = 1.0 / times;
axe *= factor;
aye *= factor;
aze *= factor;
gxe *= factor;
gye *= factor;
gze *= factor;

// restore throttle state
axe = _axe * factor;
aye = _aye * factor;
aze = _aze * factor;
gxe = _gxe * factor;
gye = _gye * factor;
gze = _gze * factor;

// restore throttle state.
_throttle = oldThrottle;
}

Expand Down
4 changes: 2 additions & 2 deletions GY521.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: GY521.h
// AUTHOR: Rob Tillaart
// VERSION: 0.5.3
// VERSION: 0.6.0
// PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor
// URL: https://github.com/RobTillaart/GY521

Expand All @@ -11,7 +11,7 @@
#include "Wire.h"


#define GY521_LIB_VERSION (F("0.5.3"))
#define GY521_LIB_VERSION (F("0.6.0"))

const float GRAVITY = 9.80655;

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ It needs to be tested a lot more.
See changelog.md for latest updates.


#### 0.6.0

Fixed a bug in calibration function, making previous versions obsolete.


#### 0.5.0 Breaking change

Version 0.5.0 introduced a breaking change.
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/GY521.git"
},
"version": "0.5.3",
"version": "0.6.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=GY521
version=0.5.3
version=0.6.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for GY521 angle measurement
Expand Down

0 comments on commit e23401c

Please sign in to comment.