diff --git a/CHANGELOG.md b/CHANGELOG.md index e6133bf..e96af71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 @@ -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 diff --git a/GY521.cpp b/GY521.cpp index bf62c69..c64ff60 100644 --- a/GY521.cpp +++ b/GY521.cpp @@ -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 @@ -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; } diff --git a/GY521.h b/GY521.h index f2ea315..67f1351 100644 --- a/GY521.h +++ b/GY521.h @@ -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 @@ -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; diff --git a/README.md b/README.md index e4fc07c..25feedf 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/library.json b/library.json index 88c18e7..e2c351c 100644 --- a/library.json +++ b/library.json @@ -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": "*", diff --git a/library.properties b/library.properties index 71e844d..330761e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=GY521 -version=0.5.3 +version=0.6.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for GY521 angle measurement