Skip to content

Commit

Permalink
Fix #69
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Oct 9, 2024
1 parent f55e473 commit bdd740f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
16 changes: 3 additions & 13 deletions AS5600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,8 @@ bool AS5600::magnetTooWeak()
// }


float AS5600::getAngularSpeed(uint8_t mode, bool update)
float AS5600::getAngularSpeed(uint8_t mode)
{
static float speed = 0;

if (update == false)
{
return speed;
}
// default behaviour
uint32_t now = micros();
int angle = readAngle();
Expand All @@ -445,7 +439,7 @@ float AS5600::getAngularSpeed(uint8_t mode, bool update)
// => at least two measurements per rotation (preferred 4).
if (deltaA > 2048) deltaA -= 4096;
else if (deltaA < -2048) deltaA += 4096;
speed = (deltaA * 1e6) / deltaT;
float speed = (deltaA * 1e6) / deltaT;

// remember last time & angle
_lastMeasurement = now;
Expand All @@ -469,12 +463,8 @@ float AS5600::getAngularSpeed(uint8_t mode, bool update)
//
// POSITION cumulative
//
int32_t AS5600::getCumulativePosition(bool update)
int32_t AS5600::getCumulativePosition()
{
if (update == false)
{
return _position;
}
int16_t value = readAngle();
if (_error != AS5600_OK)
{
Expand Down
4 changes: 2 additions & 2 deletions AS5600.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ class AS5600
// approximation of the angular speed in rotations per second.
// mode == 1: radians /second
// mode == 0: degrees /second (default)
float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES, bool update = true);
float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES);

// EXPERIMENTAL CUMULATIVE POSITION
// reads sensor and updates cumulative position
int32_t getCumulativePosition(bool update = true);
int32_t getCumulativePosition();
// converts last position to whole revolutions.
int32_t getRevolutions();
// resets position only (not the i)
Expand Down
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.6.3] - 2024-10-04
- fix #67, add update flag for speed and cumulative position
- fix #69, **resetCumulativePosition()**
- minor edits

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,9 @@ as.increaseOffset(-30);

### Angular Speed

- **float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES, bool update = true)**
- **float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES)**
is an experimental function that returns
an approximation of the angular speed in rotations per second.
If the update flag is set to false, it returns the last calculated speed.

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 @@ -421,7 +420,7 @@ should be within 180° = half a rotation.
Since 0.3.3 an experimental cumulative position can be requested from the library.
The sensor does not provide interrupts to indicate a movement or revolution
Therefore one has to poll the sensor at a frequency at least **three** times
per revolution with **getCumulativePosition(bool update = true)**
per revolution with **getCumulativePosition()**

The cumulative position (32 bits) consists of 3 parts

Expand All @@ -434,9 +433,8 @@ The cumulative position (32 bits) consists of 3 parts

Functions are:

- **int32_t getCumulativePosition(bool update = true)** reads sensor and updates cumulative position.
- **int32_t getCumulativePosition()** reads sensor and updates cumulative position.
Updated in 0.6.2 to follow the setting of the **directionPin**.
If update == false, it returns the last calculated position.
- **int32_t getRevolutions()** converts last position to whole revolutions.
Convenience function.
Updated in 0.6.2 to return **zero** for the first negative revolution as this
Expand Down

0 comments on commit bdd740f

Please sign in to comment.