Skip to content

Commit

Permalink
Fix #69, resetCumulativePosition() (#70)
Browse files Browse the repository at this point in the history
- fix #69, **resetCumulativePosition()**
- minor edits
  • Loading branch information
RobTillaart authored Oct 9, 2024
1 parent d5f90ad commit 9e0fc03
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
21 changes: 14 additions & 7 deletions AS5600.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions AS5600.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()**.
Expand All @@ -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).
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
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/AS5600.git"
},
"version": "0.6.2",
"version": "0.6.3",
"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=AS5600
version=0.6.2
version=0.6.3
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.
Expand Down

0 comments on commit 9e0fc03

Please sign in to comment.