From 9e0fc03752e6e99856001c55b17dd1f9f02ea555 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Wed, 9 Oct 2024 15:55:15 +0200 Subject: [PATCH] Fix #69, resetCumulativePosition() (#70) - fix #69, **resetCumulativePosition()** - minor edits --- AS5600.cpp | 21 ++++++++++++++------- AS5600.h | 4 ++-- CHANGELOG.md | 5 ++++- README.md | 6 ++++-- library.json | 2 +- library.properties | 2 +- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/AS5600.cpp b/AS5600.cpp index 49b79b2..d94f91b 100644 --- a/AS5600.cpp +++ b/AS5600.cpp @@ -1,7 +1,7 @@ // // FILE: AS56000.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.6.2 +// VERSION: 0.6.3 // PURPOSE: Arduino library for AS5600 magnetic rotation meter // DATE: 2022-05-28 // URL: https://github.com/RobTillaart/AS5600 @@ -428,6 +428,7 @@ bool AS5600::magnetTooWeak() float AS5600::getAngularSpeed(uint8_t mode) { + // default behaviour uint32_t now = micros(); int angle = readAngle(); uint32_t deltaT = now - _lastMeasurement; @@ -436,9 +437,9 @@ float AS5600::getAngularSpeed(uint8_t mode) // assumption is that there is no more than 180° rotation // between two consecutive measurements. // => at least two measurements per rotation (preferred 4). - if (deltaA > 2048) deltaA -= 4096; - if (deltaA < -2048) deltaA += 4096; - float speed = (deltaA * 1e6) / deltaT; + if (deltaA > 2048) deltaA -= 4096; + else if (deltaA < -2048) deltaA += 4096; + float speed = (deltaA * 1e6) / deltaT; // remember last time & angle _lastMeasurement = now; @@ -465,7 +466,10 @@ float AS5600::getAngularSpeed(uint8_t mode) int32_t AS5600::getCumulativePosition() { int16_t value = readAngle(); - if (_error != AS5600_OK) return _position; + if (_error != AS5600_OK) + { + return _position; + } // whole rotation CW? // less than half a circle @@ -479,7 +483,10 @@ int32_t AS5600::getCumulativePosition() { _position = _position - 4096 - _lastPosition + value; } - else _position = _position - _lastPosition + value; + else + { + _position = _position - _lastPosition + value; + } _lastPosition = value; return _position; @@ -504,7 +511,7 @@ int32_t AS5600::resetPosition(int32_t position) int32_t AS5600::resetCumulativePosition(int32_t position) { - _lastPosition = readReg2(AS5600_RAW_ANGLE) & 0x0FFF; + _lastPosition = readAngle(); int32_t old = _position; _position = position; return old; diff --git a/AS5600.h b/AS5600.h index d2a3f7a..1339957 100644 --- a/AS5600.h +++ b/AS5600.h @@ -2,7 +2,7 @@ // // FILE: AS5600.h // AUTHOR: Rob Tillaart -// VERSION: 0.6.2 +// VERSION: 0.6.3 // 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.6.2")) +#define AS5600_LIB_VERSION (F("0.6.3")) // default addresses diff --git a/CHANGELOG.md b/CHANGELOG.md index 9603fe3..ed64957 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.6.3] - 2024-10-04 +- fix #69, **resetCumulativePosition()** +- minor edits + ## [0.6.2] - 2024-10-04 - fix #65, make **getCumulativePosition()** direction aware. - optimize **readAngle()** and **rawAngle()**. @@ -15,7 +19,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - add **AS5600_output_speedtest.ino**, thanks to Pollyscracker. - update readme.md. - ## [0.6.1] - 2024-03-31 - improve **getCumulativePosition()**, catch I2C error, see #62 - update readme.md (incl reorder future work). diff --git a/README.md b/README.md index 07e1a7a..2938e64 100644 --- a/README.md +++ b/README.md @@ -385,8 +385,10 @@ as.increaseOffset(-30); ### Angular Speed -- **float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES)** is an experimental function that returns +- **float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES)** +is an experimental function that returns an approximation of the angular speed in rotations per second. + The function needs to be called at least **four** times per rotation or once per second to get a reasonably precision. @@ -445,7 +447,7 @@ Returns last position (before reset). This includes the delta (rotation) since last call to **getCumulativePosition()**. Returns last position (before reset). -As this code is experimental, names might change in the future (0.4.0)? +As this code is experimental, names might change in the future. As the function are mostly about counting revolutions the current thoughts for new names are: ```cpp diff --git a/library.json b/library.json index ff24b3f..8ff2724 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/AS5600.git" }, - "version": "0.6.2", + "version": "0.6.3", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index ea3cc7f..6cfcbc1 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AS5600 -version=0.6.2 +version=0.6.3 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.