diff --git a/AS5600.cpp b/AS5600.cpp index 77efd7f..db914ed 100644 --- a/AS5600.cpp +++ b/AS5600.cpp @@ -1,7 +1,7 @@ // // FILE: AS56000.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.5.0 +// VERSION: 0.5.1 // PURPOSE: Arduino library for AS5600 magnetic rotation meter // DATE: 2022-05-28 // URL: https://github.com/RobTillaart/AS5600 @@ -350,6 +350,13 @@ float AS5600::getOffset() } +bool AS5600::increaseOffset(float degrees) +{ + // add offset to existing offset in degrees. + return setOffset((_offset * AS5600_RAW_TO_DEGREES) + degrees); +} + + ///////////////////////////////////////////////////////// // // STATUS REGISTERS diff --git a/AS5600.h b/AS5600.h index 5d9fbcb..34d1aa6 100644 --- a/AS5600.h +++ b/AS5600.h @@ -2,7 +2,7 @@ // // FILE: AS5600.h // AUTHOR: Rob Tillaart -// VERSION: 0.5.0 +// VERSION: 0.5.1 // PURPOSE: Arduino library for AS5600 magnetic rotation meter // DATE: 2022-05-28 // URL: https://github.com/RobTillaart/AS5600 @@ -12,7 +12,7 @@ #include "Wire.h" -#define AS5600_LIB_VERSION (F("0.5.0")) +#define AS5600_LIB_VERSION (F("0.5.1")) // default addresses const uint8_t AS5600_DEFAULT_ADDRESS = 0x36; @@ -180,8 +180,9 @@ class AS5600 // degrees = -359.99 .. 359.99 (preferred) // returns false if abs(parameter) > 36000 // => expect loss of precision - bool setOffset(float degrees); + bool setOffset(float degrees); // sets an absolute offset float getOffset(); + bool increaseOffset(float degrees); // adds to existing offset. // READ STATUS REGISTERS diff --git a/CHANGELOG.md b/CHANGELOG.md index a26d1d4..1669311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.5.1] - 2023-12-31 +- fix #51, add **increaseOffset(float degrees)** +- update keywords.txt +- update readme.md (several cleanups) + + ## [0.5.0] - 2023-12-07 - refactor API, begin() - update readme.md diff --git a/README.md b/README.md index 7349054..e5f36d9 100644 --- a/README.md +++ b/README.md @@ -222,11 +222,6 @@ interface as parameter. If the pin is set to AS5600_SW_DIRECTION_PIN, the default value, there will be software direction control instead of hardware control. See below. -- **bool begin(int dataPin, int clockPin, uint8_t directionPin = AS5600_SW_DIRECTION_PIN)** idem, -for the ESP32 where one can choose the I2C pins. -If the pin is set to AS5600_SW_DIRECTION_PIN, the default value, there will be software -direction control instead of hardware control. -See below. - **bool isConnected()** checks if the address 0x36 (AS5600) is on the I2C bus. - **uint8_t getAddress()** returns the fixed device address 0x36 (AS5600). @@ -281,6 +276,7 @@ Returns false if parameter is out of range. The library has functions to address these fields directly. + The setters() returns false if parameter is out of range. - **bool setPowerMode(uint8_t powerMode)** @@ -311,20 +307,43 @@ Conversion factor AS5600_RAW_TO_DEGREES = 360 / 4096 = 0.087890625 or use AS5600_RAW_TO_RADIANS if needed. The value of this register can be affected by the configuration bits above. This is the one most used. -- **void setOffset(float degrees)** sets an offset in degrees, -e.g. to calibrate the sensor after mounting. +- **bool setOffset(float degrees)** overwrites the **existing** offset. +It sets an offset in degrees, e.g. to calibrate the sensor after mounting. Typical values are -359.99 - 359.99 probably smaller. Larger values will be mapped back to this interval. Be aware that larger values will affect / decrease the precision of the measurements as floats have only 7 significant digits. Verify this for your application. +Returns false if **degrees** > 360000. - **float getOffset()** returns offset in degrees. +- **bool increaseOffset(float degrees)** adds degrees to the **existing** offset. +If **setOffset(20)** is called first and **increaseOffset(-30)** thereafter the +new offset is -10 degrees. +Returns false if **degrees** > 360000. In issue #14 there is a discussion about **setOffset()**. A possible implementation is to ignore all values outside the -359.99 - 359.99 range. This would help to keep the precision high. User responsibility. +In #51 increaseOffset is discussed. + +```cpp +// offset == 0; +as.setOffset(20); +// offset == 20; +as.setOffset(-30); +// offset = -30; + +// versus + +// offset == 0; +as.setOffset(20); +// offset == 20; +as.increaseOffset(-30); +// offset = -10; +``` + #### Angular Speed diff --git a/keywords.txt b/keywords.txt index 91df363..18ea117 100644 --- a/keywords.txt +++ b/keywords.txt @@ -27,12 +27,34 @@ getMaxAngle KEYWORD2 setConfigure KEYWORD2 getConfigure KEYWORD2 +setPowerMode KEYWORD2 +getPowerMode KEYWORD2 +setHysteresis KEYWORD2 +getHysteresis KEYWORD2 + +setOutputMode KEYWORD2 +getOutputMode KEYWORD2 +setPWMFrequency KEYWORD2 +getPWMFrequency KEYWORD2 + +setSlowFilter KEYWORD2 +getSlowFilter KEYWORD2 +setFastFilter KEYWORD2 +getFastFilter KEYWORD2 + +setWatchDog KEYWORD2 +getWatchDog KEYWORD2 + rawAngle KEYWORD2 readAngle KEYWORD2 +setOffset KEYWORD2 +increaseOffset KEYWORD2 +getOffset KEYWORD2 readStatus KEYWORD2 readAGC KEYWORD2 readMagnitude KEYWORD2 + detectMagnet KEYWORD2 magnetTooStrong KEYWORD2 magnetTooWeak KEYWORD2 diff --git a/library.json b/library.json index 8adefd4..43d8e18 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/AS5600.git" }, - "version": "0.5.0", + "version": "0.5.1", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 7328f24..fbbab74 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AS5600 -version=0.5.0 +version=0.5.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter. diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index 26bb999..e5f2c41 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -182,7 +182,7 @@ unittest(test_software_direction) } -unittest(test_offset) +unittest(test_offset_I) { AS5600 as5600; @@ -210,6 +210,47 @@ unittest(test_offset) } +unittest(test_offset_II) +{ + AS5600 as5600; + + Wire.begin(); + + as5600.begin(); + + as5600.setOffset(200); + assertEqualFloat(200, as5600.getOffset(), 0.05); + + as5600.setOffset(30); + assertEqualFloat(30, as5600.getOffset(), 0.05); + + as5600.setOffset(200); + assertEqualFloat(200, as5600.getOffset(), 0.05); + + as5600.setOffset(-30); + assertEqualFloat(330, as5600.getOffset(), 0.05); + + + as5600.setOffset(200); + assertEqualFloat(200, as5600.getOffset(), 0.05); + + as5600.increaseOffset(30); + assertEqualFloat(230, as5600.getOffset(), 0.05); + + as5600.setOffset(200); + assertEqualFloat(200, as5600.getOffset(), 0.05); + + as5600.increaseOffset(-30); + assertEqualFloat(170, as5600.getOffset(), 0.05); + + as5600.setOffset(200); + assertEqualFloat(200, as5600.getOffset(), 0.05); + + as5600.increaseOffset(-300); + assertEqualFloat(260, as5600.getOffset(), 0.05); +} + + unittest(test_failing_set_commands) { AS5600 as5600;