0.5.1 AS5600

This commit is contained in:
Rob Tillaart 2024-01-05 09:44:05 +01:00
parent 2c54a7207f
commit fc3bd1f9e9
9 changed files with 112 additions and 15 deletions

View File

@ -1,7 +1,7 @@
// //
// FILE: AS56000.cpp // FILE: AS56000.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.5.0 // VERSION: 0.5.1
// PURPOSE: Arduino library for AS5600 magnetic rotation meter // PURPOSE: Arduino library for AS5600 magnetic rotation meter
// DATE: 2022-05-28 // DATE: 2022-05-28
// URL: https://github.com/RobTillaart/AS5600 // URL: https://github.com/RobTillaart/AS5600
@ -350,6 +350,13 @@ float AS5600::getOffset()
} }
bool AS5600::increaseOffset(float degrees)
{
// add offset to existing offset in degrees.
return setOffset((_offset * AS5600_RAW_TO_DEGREES) + degrees);
}
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// //
// STATUS REGISTERS // STATUS REGISTERS

View File

@ -2,7 +2,7 @@
// //
// FILE: AS5600.h // FILE: AS5600.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.5.0 // VERSION: 0.5.1
// PURPOSE: Arduino library for AS5600 magnetic rotation meter // PURPOSE: Arduino library for AS5600 magnetic rotation meter
// DATE: 2022-05-28 // DATE: 2022-05-28
// URL: https://github.com/RobTillaart/AS5600 // URL: https://github.com/RobTillaart/AS5600
@ -12,7 +12,7 @@
#include "Wire.h" #include "Wire.h"
#define AS5600_LIB_VERSION (F("0.5.0")) #define AS5600_LIB_VERSION (F("0.5.1"))
// default addresses // default addresses
const uint8_t AS5600_DEFAULT_ADDRESS = 0x36; const uint8_t AS5600_DEFAULT_ADDRESS = 0x36;
@ -180,8 +180,9 @@ public:
// degrees = -359.99 .. 359.99 (preferred) // degrees = -359.99 .. 359.99 (preferred)
// returns false if abs(parameter) > 36000 // returns false if abs(parameter) > 36000
// => expect loss of precision // => expect loss of precision
bool setOffset(float degrees); bool setOffset(float degrees); // sets an absolute offset
float getOffset(); float getOffset();
bool increaseOffset(float degrees); // adds to existing offset.
// READ STATUS REGISTERS // READ STATUS REGISTERS

View File

@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.5.1] - 2023-12-31
- fix #51, add **increaseOffset(float degrees)**
- update keywords.txt
- update readme.md (several cleanups)
## [0.5.0] - 2023-12-07 ## [0.5.0] - 2023-12-07
- refactor API, begin() - refactor API, begin()
- update readme.md - update readme.md

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2022-2023 Rob Tillaart Copyright (c) 2022-2024 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -222,11 +222,6 @@ interface as parameter.
If the pin is set to AS5600_SW_DIRECTION_PIN, the default value, If the pin is set to AS5600_SW_DIRECTION_PIN, the default value,
there will be software direction control instead of hardware control. there will be software direction control instead of hardware control.
See below. See below.
- **bool begin(int dataPin, int clockPin, uint8_t directionPin = AS5600_SW_DIRECTION_PIN)** idem,
for the ESP32 where one can choose the I2C pins.
If the pin is set to AS5600_SW_DIRECTION_PIN, the default value, there will be software
direction control instead of hardware control.
See below.
- **bool isConnected()** checks if the address 0x36 (AS5600) is on the I2C bus. - **bool isConnected()** checks if the address 0x36 (AS5600) is on the I2C bus.
- **uint8_t getAddress()** returns the fixed device address 0x36 (AS5600). - **uint8_t getAddress()** returns the fixed device address 0x36 (AS5600).
@ -281,6 +276,7 @@ Returns false if parameter is out of range.
The library has functions to address these fields directly. The library has functions to address these fields directly.
The setters() returns false if parameter is out of range. The setters() returns false if parameter is out of range.
- **bool setPowerMode(uint8_t powerMode)** - **bool setPowerMode(uint8_t powerMode)**
@ -311,20 +307,43 @@ Conversion factor AS5600_RAW_TO_DEGREES = 360 / 4096 = 0.087890625
or use AS5600_RAW_TO_RADIANS if needed. or use AS5600_RAW_TO_RADIANS if needed.
The value of this register can be affected by the configuration bits above. The value of this register can be affected by the configuration bits above.
This is the one most used. This is the one most used.
- **void setOffset(float degrees)** sets an offset in degrees, - **bool setOffset(float degrees)** overwrites the **existing** offset.
e.g. to calibrate the sensor after mounting. It sets an offset in degrees, e.g. to calibrate the sensor after mounting.
Typical values are -359.99 - 359.99 probably smaller. Typical values are -359.99 - 359.99 probably smaller.
Larger values will be mapped back to this interval. Larger values will be mapped back to this interval.
Be aware that larger values will affect / decrease the precision of the Be aware that larger values will affect / decrease the precision of the
measurements as floats have only 7 significant digits. measurements as floats have only 7 significant digits.
Verify this for your application. Verify this for your application.
Returns false if **degrees** > 360000.
- **float getOffset()** returns offset in degrees. - **float getOffset()** returns offset in degrees.
- **bool increaseOffset(float degrees)** adds degrees to the **existing** offset.
If **setOffset(20)** is called first and **increaseOffset(-30)** thereafter the
new offset is -10 degrees.
Returns false if **degrees** > 360000.
In issue #14 there is a discussion about **setOffset()**. In issue #14 there is a discussion about **setOffset()**.
A possible implementation is to ignore all values outside the A possible implementation is to ignore all values outside the
-359.99 - 359.99 range. -359.99 - 359.99 range.
This would help to keep the precision high. User responsibility. This would help to keep the precision high. User responsibility.
In #51 increaseOffset is discussed.
```cpp
// offset == 0;
as.setOffset(20);
// offset == 20;
as.setOffset(-30);
// offset = -30;
// versus
// offset == 0;
as.setOffset(20);
// offset == 20;
as.increaseOffset(-30);
// offset = -10;
```
#### Angular Speed #### Angular Speed

View File

@ -27,12 +27,34 @@ getMaxAngle KEYWORD2
setConfigure KEYWORD2 setConfigure KEYWORD2
getConfigure KEYWORD2 getConfigure KEYWORD2
setPowerMode KEYWORD2
getPowerMode KEYWORD2
setHysteresis KEYWORD2
getHysteresis KEYWORD2
setOutputMode KEYWORD2
getOutputMode KEYWORD2
setPWMFrequency KEYWORD2
getPWMFrequency KEYWORD2
setSlowFilter KEYWORD2
getSlowFilter KEYWORD2
setFastFilter KEYWORD2
getFastFilter KEYWORD2
setWatchDog KEYWORD2
getWatchDog KEYWORD2
rawAngle KEYWORD2 rawAngle KEYWORD2
readAngle KEYWORD2 readAngle KEYWORD2
setOffset KEYWORD2
increaseOffset KEYWORD2
getOffset KEYWORD2
readStatus KEYWORD2 readStatus KEYWORD2
readAGC KEYWORD2 readAGC KEYWORD2
readMagnitude KEYWORD2 readMagnitude KEYWORD2
detectMagnet KEYWORD2 detectMagnet KEYWORD2
magnetTooStrong KEYWORD2 magnetTooStrong KEYWORD2
magnetTooWeak KEYWORD2 magnetTooWeak KEYWORD2

View File

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

View File

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

View File

@ -182,7 +182,7 @@ unittest(test_software_direction)
} }
unittest(test_offset) unittest(test_offset_I)
{ {
AS5600 as5600; AS5600 as5600;
@ -210,6 +210,48 @@ unittest(test_offset)
} }
unittest(test_offset_II)
{
AS5600 as5600;
Wire.begin();
as5600.begin();
as5600.setOffset(200);
assertEqualFloat(200, as5600.getOffset(), 0.05);
as5600.setOffset(30);
assertEqualFloat(30, as5600.getOffset(), 0.05);
as5600.setOffset(200);
assertEqualFloat(200, as5600.getOffset(), 0.05);
as5600.setOffset(-30);
assertEqualFloat(330, as5600.getOffset(), 0.05);
// as cummulative error can be larger ==> 0.1
as5600.setOffset(200);
assertEqualFloat(200, as5600.getOffset(), 0.1);
as5600.increaseOffset(30);
assertEqualFloat(230, as5600.getOffset(), 0.1);
as5600.setOffset(200);
assertEqualFloat(200, as5600.getOffset(), 0.1);
as5600.increaseOffset(-30);
assertEqualFloat(170, as5600.getOffset(), 0.1);
as5600.setOffset(200);
assertEqualFloat(200, as5600.getOffset(), 0.1);
as5600.increaseOffset(-300);
assertEqualFloat(260, as5600.getOffset(), 0.1);
}
unittest(test_failing_set_commands) unittest(test_failing_set_commands)
{ {
AS5600 as5600; AS5600 as5600;