mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.6 AS5600
This commit is contained in:
parent
5a2709562c
commit
df0b0dce12
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: AS56000.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.5
|
||||
// VERSION: 0.3.6
|
||||
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
|
||||
// DATE: 2022-05-28
|
||||
// URL: https://github.com/RobTillaart/AS5600
|
||||
@ -451,18 +451,19 @@ 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
|
||||
// less than half a circle
|
||||
if ((_lastPosition > 2048) && ( value < (_lastPosition - 2048)))
|
||||
{
|
||||
_position = _position + 4096 - _lastPosition + value;
|
||||
}
|
||||
// whole rotation CCW?
|
||||
else if ((value > 2048) && ( _lastPosition < (value - 2048))) // less than half a circle
|
||||
// less than half a circle
|
||||
else if ((value > 2048) && ( _lastPosition < (value - 2048)))
|
||||
{
|
||||
_position = _position - 4096 - _lastPosition + value;
|
||||
}
|
||||
@ -475,17 +476,26 @@ int32_t AS5600::getCumulativePosition()
|
||||
|
||||
int32_t AS5600::getRevolutions()
|
||||
{
|
||||
int32_t p = _position >> 12;
|
||||
int32_t p = _position >> 12; // divide by 4096
|
||||
return p;
|
||||
// if (p < 0) p++;
|
||||
// return p;
|
||||
}
|
||||
|
||||
|
||||
int32_t AS5600::resetPosition()
|
||||
int32_t AS5600::resetPosition(int32_t position)
|
||||
{
|
||||
int32_t old = _position;
|
||||
_position = 0;
|
||||
_position = position;
|
||||
return old;
|
||||
}
|
||||
|
||||
|
||||
int32_t AS5600::resetCumulativePosition(int32_t position)
|
||||
{
|
||||
_lastPosition = readReg2(AS5600_RAW_ANGLE) & 0x0FFF;
|
||||
int32_t old = _position;
|
||||
_position = position;
|
||||
return old;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: AS5600.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.5
|
||||
// VERSION: 0.3.6
|
||||
// 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.5"))
|
||||
#define AS5600_LIB_VERSION (F("0.3.6"))
|
||||
|
||||
// default addresses
|
||||
const uint8_t AS5600_DEFAULT_ADDRESS = 0x36;
|
||||
@ -214,8 +214,12 @@ public:
|
||||
int32_t getCumulativePosition();
|
||||
// converts last position to whole revolutions.
|
||||
int32_t getRevolutions();
|
||||
// resets position, returns last position.
|
||||
int32_t resetPosition();
|
||||
// resets position only (not the i)
|
||||
// returns last position but not internal lastPosition.
|
||||
int32_t resetPosition(int32_t position = 0);
|
||||
// resets position and internal lastPosition
|
||||
// returns last position.
|
||||
int32_t resetCumulativePosition(int32_t position = 0);
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -5,12 +5,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.6] - 2023-02-20
|
||||
- add **resetCumulativePosition(int32_t position)** to completely reset the cumulative counter.
|
||||
This includes the delta since last call to **getCumulativePosition()**.
|
||||
- add parameter position to **resetPosition(int32_t position)** so a new position can be set.
|
||||
This does not reset the delta since last call to **getCumulativePosition()**.
|
||||
- update readme.md
|
||||
|
||||
|
||||
## [0.3.5] - 2023-02-01
|
||||
- update GitHub actions
|
||||
- update license 2023
|
||||
- update readme.md
|
||||
|
||||
|
||||
## [0.3.4] - 2022-12-22
|
||||
- fix #26 edges problem of the experimental cumulative position (CP).
|
||||
- decoupled CP from **rawAngle()**
|
||||
|
@ -16,7 +16,7 @@ Arduino library for AS5600 and AS5600L magnetic rotation meter.
|
||||
#### AS5600
|
||||
|
||||
**AS5600** is a library for an AS5600 / AS5600L based magnetic **rotation** meter.
|
||||
More exact, it measures the angle (rotation wrt reference) and not RPM.
|
||||
More exact, it measures the angle (rotation w.r.t. reference) and not RPM.
|
||||
Multiple angle measurements allows one to calculate / estimate the RPM.
|
||||
|
||||
The AS5600 and AS5600L sensors are pin compatible (always check datasheet).
|
||||
@ -345,11 +345,14 @@ 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.
|
||||
- **int32_t resetPosition(int32_t position = 0)** resets the "revolutions" to position (default 0).
|
||||
It does not reset the delta (rotation) since last call to **getCumulativePosition()**.
|
||||
Returns last position (before reset).
|
||||
- **int32_t resetCumulativePosition(int32_t position = 0)** completely resets the cumulative counter.
|
||||
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 (0.4.0)?
|
||||
As the function are mostly about counting revolutions the current thoughts for new names are:
|
||||
|
||||
```cpp
|
||||
@ -649,6 +652,8 @@ priority is relative.
|
||||
|
||||
- add error handling
|
||||
- investigate PGO programming pin.
|
||||
- check for compatible devices
|
||||
- AS5200 ?
|
||||
|
||||
|
||||
#### Wont
|
||||
|
@ -0,0 +1,28 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
# - uno
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
# - m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
# - rpipico
|
||||
|
@ -0,0 +1,42 @@
|
||||
//
|
||||
// FILE: AS5600_resetCumulativeCounter.ino
|
||||
// AUTHOR: Daniel-Frenkel, (slightly by Rob Tillaart)
|
||||
// PURPOSE: demo - see issue #30
|
||||
|
||||
|
||||
#include "AS5600.h"
|
||||
#include "Wire.h"
|
||||
|
||||
AS5600L as5600; // use default Wire
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
as5600.begin(14, 15); // ESP32
|
||||
as5600.setAddress(0x40); // AS5600L has address
|
||||
|
||||
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
|
||||
delay(1000);
|
||||
as5600.resetCumulativePosition(777);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
static uint32_t lastTime = 0;
|
||||
|
||||
// set initial position
|
||||
as5600.getCumulativePosition();
|
||||
|
||||
// update every 100 ms
|
||||
if (millis() - lastTime >= 100)
|
||||
{
|
||||
lastTime = millis();
|
||||
Serial.println(as5600.getCumulativePosition());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -45,6 +45,7 @@ getAngularSpeed KEYWORD2
|
||||
getCumulativePosition KEYWORD2
|
||||
getRevolutions KEYWORD2
|
||||
resetPosition KEYWORD2
|
||||
resetCumulativePosition KEYWORD2
|
||||
|
||||
|
||||
# CONFIGURATION FIELDS
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/AS5600.git"
|
||||
},
|
||||
"version": "0.3.5",
|
||||
"version": "0.3.6",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AS5600
|
||||
version=0.3.5
|
||||
version=0.3.6
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.
|
||||
|
Loading…
Reference in New Issue
Block a user