Skip to content

Commit 9e0fc03

Browse files
authored
Fix #69, resetCumulativePosition() (#70)
- fix #69, **resetCumulativePosition()** - minor edits
1 parent d5f90ad commit 9e0fc03

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

AS5600.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: AS56000.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.6.2
4+
// VERSION: 0.6.3
55
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
66
// DATE: 2022-05-28
77
// URL: https://github.com/RobTillaart/AS5600
@@ -428,6 +428,7 @@ bool AS5600::magnetTooWeak()
428428

429429
float AS5600::getAngularSpeed(uint8_t mode)
430430
{
431+
// default behaviour
431432
uint32_t now = micros();
432433
int angle = readAngle();
433434
uint32_t deltaT = now - _lastMeasurement;
@@ -436,9 +437,9 @@ float AS5600::getAngularSpeed(uint8_t mode)
436437
// assumption is that there is no more than 180° rotation
437438
// between two consecutive measurements.
438439
// => at least two measurements per rotation (preferred 4).
439-
if (deltaA > 2048) deltaA -= 4096;
440-
if (deltaA < -2048) deltaA += 4096;
441-
float speed = (deltaA * 1e6) / deltaT;
440+
if (deltaA > 2048) deltaA -= 4096;
441+
else if (deltaA < -2048) deltaA += 4096;
442+
float speed = (deltaA * 1e6) / deltaT;
442443

443444
// remember last time & angle
444445
_lastMeasurement = now;
@@ -465,7 +466,10 @@ float AS5600::getAngularSpeed(uint8_t mode)
465466
int32_t AS5600::getCumulativePosition()
466467
{
467468
int16_t value = readAngle();
468-
if (_error != AS5600_OK) return _position;
469+
if (_error != AS5600_OK)
470+
{
471+
return _position;
472+
}
469473

470474
// whole rotation CW?
471475
// less than half a circle
@@ -479,7 +483,10 @@ int32_t AS5600::getCumulativePosition()
479483
{
480484
_position = _position - 4096 - _lastPosition + value;
481485
}
482-
else _position = _position - _lastPosition + value;
486+
else
487+
{
488+
_position = _position - _lastPosition + value;
489+
}
483490
_lastPosition = value;
484491

485492
return _position;
@@ -504,7 +511,7 @@ int32_t AS5600::resetPosition(int32_t position)
504511

505512
int32_t AS5600::resetCumulativePosition(int32_t position)
506513
{
507-
_lastPosition = readReg2(AS5600_RAW_ANGLE) & 0x0FFF;
514+
_lastPosition = readAngle();
508515
int32_t old = _position;
509516
_position = position;
510517
return old;

AS5600.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: AS5600.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.6.2
5+
// VERSION: 0.6.3
66
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
77
// DATE: 2022-05-28
88
// URL: https://github.com/RobTillaart/AS5600
@@ -12,7 +12,7 @@
1212
#include "Wire.h"
1313

1414

15-
#define AS5600_LIB_VERSION (F("0.6.2"))
15+
#define AS5600_LIB_VERSION (F("0.6.3"))
1616

1717

1818
// default addresses

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77

8+
## [0.6.3] - 2024-10-04
9+
- fix #69, **resetCumulativePosition()**
10+
- minor edits
11+
812
## [0.6.2] - 2024-10-04
913
- fix #65, make **getCumulativePosition()** direction aware.
1014
- optimize **readAngle()** and **rawAngle()**.
@@ -15,7 +19,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1519
- add **AS5600_output_speedtest.ino**, thanks to Pollyscracker.
1620
- update readme.md.
1721

18-
1922
## [0.6.1] - 2024-03-31
2023
- improve **getCumulativePosition()**, catch I2C error, see #62
2124
- update readme.md (incl reorder future work).

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,10 @@ as.increaseOffset(-30);
385385

386386
### Angular Speed
387387

388-
- **float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES)** is an experimental function that returns
388+
- **float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES)**
389+
is an experimental function that returns
389390
an approximation of the angular speed in rotations per second.
391+
390392
The function needs to be called at least **four** times per rotation
391393
or once per second to get a reasonably precision.
392394

@@ -445,7 +447,7 @@ Returns last position (before reset).
445447
This includes the delta (rotation) since last call to **getCumulativePosition()**.
446448
Returns last position (before reset).
447449

448-
As this code is experimental, names might change in the future (0.4.0)?
450+
As this code is experimental, names might change in the future.
449451
As the function are mostly about counting revolutions the current thoughts for new names are:
450452

451453
```cpp

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/AS5600.git"
1717
},
18-
"version": "0.6.2",
18+
"version": "0.6.3",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AS5600
2-
version=0.6.2
2+
version=0.6.3
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.

0 commit comments

Comments
 (0)