0.3.4 AS5600

This commit is contained in:
rob tillaart 2022-12-22 14:03:01 +01:00
parent 03916115dd
commit a6e2af6b80
7 changed files with 73 additions and 37 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: AS56000.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.3
// VERSION: 0.3.4
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
// DATE: 2022-05-28
// URL: https://github.com/RobTillaart/AS5600
@ -311,27 +311,12 @@ uint8_t AS5600::getWatchDog()
uint16_t AS5600::rawAngle()
{
int16_t value = readReg2(AS5600_RAW_ANGLE) & 0x0FFF;
// whole rotation CW?
if ((_lastPosition > 2500) && ( value < 1500))
{
_position = _position + 4096 - _lastPosition + value;
}
// whole rotation CCW?
else if ((value > 2500) && ( _lastPosition < 1500))
{
_position = _position - 4096 - _lastPosition + value;
}
else _position = _position - _lastPosition + value;
_lastPosition = value;
if (_offset > 0) value = (value + _offset) & 0x0FFF;
if ((_directionPin == 255) && (_direction == AS5600_COUNTERCLOCK_WISE))
{
value = (4096 - value) & 0x0FFF;
}
return value;
}
@ -466,8 +451,24 @@ float AS5600::getAngularSpeed(uint8_t mode)
//
// POSITION cumulative
//
int32_t AS5600::getCumulativePosition()
{
int16_t value = readReg2(AS5600_RAW_ANGLE) & 0x0FFF;
// whole rotation CW?
if ((_lastPosition > 2048) && ( value < (_lastPosition - 2048))) // less than half a circle
{
_position = _position + 4096 - _lastPosition + value;
}
// whole rotation CCW?
else if ((value > 2048) && ( _lastPosition < (value - 2048))) // less than half a circle
{
_position = _position - 4096 - _lastPosition + value;
}
else _position = _position - _lastPosition + value;
_lastPosition = value;
return _position;
}

View File

@ -2,7 +2,7 @@
//
// FILE: AS5600.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.3
// VERSION: 0.3.4
// 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.3.3"))
#define AS5600_LIB_VERSION (F("0.3.4"))
// default addresses
const uint8_t AS5600_DEFAULT_ADDRESS = 0x36;
@ -210,9 +210,12 @@ public:
float getAngularSpeed(uint8_t mode = AS5600_MODE_DEGREES);
// EXPERIMENTAL CUMULATIVE POSITION
// reads sensor and updates cumulative position
int32_t getCumulativePosition();
// converts last position to whole revolutions.
int32_t getRevolutions();
int32_t resetPosition(); // resets counter returns last value.
// resets position, returns last position.
int32_t resetPosition();
protected:

View File

@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.4] - 2022-12-22
- fix #26 edges problem of the experimental cumulative position (CP).
- decoupled CP from **rawAngle()**
- now one needs to call **getCumulativePosition()** to update the CP.
- updated the readme.md section about CP.
## [0.3.3] - 2022-12-19
- add experimental continuous position.
- add **getCumulativePosition()**
@ -18,7 +25,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- add AS5600L_DEFAULT_ADDRESS
- update readme.md
## [0.3.2] - 2022-10-16
- add CHANGELOG.md
- update readme.md

View File

@ -301,21 +301,39 @@ with a short interval. The only limitation then is that both measurements
should be within 180° = half a rotation.
### Cumulative position
### Cumulative position (experimental)
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 3 times per revolution with **getCumulativePosition()**
The cumulative position consists of 3 parts
| bit | meaning | notes |
|:-------:|:--------------|:--------|
| 31 | sign | typical + == CW, - == CCW
| 30-12 | revolutions |
| 11-00 | raw angle | call getCumulativePosition()
Functions are:
- **int32_t getCumulativePosition()** reads sensor and updates cumulative position.
- **int32_t getRevolutions()** converts last position to whole revolutions.
Convenience function.
- **int32_t resetPosition()** resets **revolutions**, returns last position.
The cumulative position does not reset to 0 but to the last known raw angle.
This way the cumulative position always indicate the (absolute) angle too.
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
// EXPERIMENTAL CUMULATIVE POSITION
int32_t getCumulativePosition();
int32_t getRevolutions();
int32_t resetPosition(); // resets position returns last value.
int32_t updateRevolutions() replaces getCumulativePosition()
int32_t getRevolutions()
int32_t resetRevolutions() replaces resetPosition()
```
to elaborate
- call rawAngle() often enough == at least 4x per rotation
- example
- only the revolutions are reset
### Status registers

View File

@ -39,9 +39,12 @@ void setup()
void loop()
{
static uint32_t lastTime = 0;
// Serial.print("\ta = ");
// Serial.print(as5600.readAngle());
as5600.rawAngle();
// set initial position
as5600.getCumulativePosition();
// update every 100 ms
// should be enough up to ~200 RPM
if (millis() - lastTime >= 100)
{
lastTime = millis();
@ -49,7 +52,12 @@ void loop()
Serial.print("\t");
Serial.println(as5600.getRevolutions());
}
if (as5600.getRevolutions() >= 10) as5600.resetPosition();
// just to show how reset can be used
if (as5600.getRevolutions() >= 10)
{
as5600.resetPosition();
}
}

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/AS5600.git"
},
"version": "0.3.3",
"version": "0.3.4",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=AS5600
version=0.3.3
version=0.3.4
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.