Skip to content

Commit

Permalink
Fix #51, add increaseOffset() (#52)
Browse files Browse the repository at this point in the history
- fix #51, add **increaseOffset(float degrees)**
- update keywords.txt
- update readme.md (several cleanups)
  • Loading branch information
RobTillaart committed Jan 5, 2024
1 parent 4bc6a96 commit 5134633
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 15 deletions.
9 changes: 8 additions & 1 deletion AS5600.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: AS56000.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.5.0
// VERSION: 0.5.1
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
// DATE: 2022-05-28
// URL: https://github.com/RobTillaart/AS5600
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions AS5600.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: AS5600.h
// AUTHOR: Rob Tillaart
// VERSION: 0.5.0
// VERSION: 0.5.1
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
// DATE: 2022-05-28
// URL: https://github.com/RobTillaart/AS5600
Expand All @@ -12,7 +12,7 @@
#include "Wire.h"


#define AS5600_LIB_VERSION (F("0.5.0"))
#define AS5600_LIB_VERSION (F("0.5.1"))

// default addresses
const uint8_t AS5600_DEFAULT_ADDRESS = 0x36;
Expand Down Expand Up @@ -180,8 +180,9 @@ class AS5600
// degrees = -359.99 .. 359.99 (preferred)
// returns false if abs(parameter) > 36000
// => expect loss of precision
bool setOffset(float degrees);
bool setOffset(float degrees); // sets an absolute offset
float getOffset();
bool increaseOffset(float degrees); // adds to existing offset.


// READ STATUS REGISTERS
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).


## [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
- refactor API, begin()
- update readme.md
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
of this software and associated documentation files (the "Software"), to deal
Expand Down
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ interface as parameter.
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 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.
- **uint8_t getAddress()** returns the fixed device address 0x36 (AS5600).

Expand Down Expand Up @@ -281,6 +276,7 @@ Returns false if parameter is out of range.


The library has functions to address these fields directly.

The setters() returns false if parameter is out of range.

- **bool setPowerMode(uint8_t powerMode)**
Expand Down Expand Up @@ -311,20 +307,43 @@ Conversion factor AS5600_RAW_TO_DEGREES = 360 / 4096 = 0.087890625
or use AS5600_RAW_TO_RADIANS if needed.
The value of this register can be affected by the configuration bits above.
This is the one most used.
- **void setOffset(float degrees)** sets an offset in degrees,
e.g. to calibrate the sensor after mounting.
- **bool setOffset(float degrees)** overwrites the **existing** offset.
It sets an offset in degrees, e.g. to calibrate the sensor after mounting.
Typical values are -359.99 - 359.99 probably smaller.
Larger values will be mapped back to this interval.
Be aware that larger values will affect / decrease the precision of the
measurements as floats have only 7 significant digits.
Verify this for your application.
Returns false if **degrees** > 360000.
- **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()**.
A possible implementation is to ignore all values outside the
-359.99 - 359.99 range.
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

Expand Down
22 changes: 22 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,34 @@ getMaxAngle KEYWORD2
setConfigure 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
readAngle KEYWORD2
setOffset KEYWORD2
increaseOffset KEYWORD2
getOffset KEYWORD2

readStatus KEYWORD2
readAGC KEYWORD2
readMagnitude KEYWORD2

detectMagnet KEYWORD2
magnetTooStrong KEYWORD2
magnetTooWeak KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/AS5600.git"
},
"version": "0.5.0",
"version": "0.5.1",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AS5600
version=0.5.0
version=0.5.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.
Expand Down
44 changes: 43 additions & 1 deletion test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ unittest(test_software_direction)
}


unittest(test_offset)
unittest(test_offset_I)
{
AS5600 as5600;

Expand Down Expand Up @@ -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)
{
AS5600 as5600;
Expand Down

0 comments on commit 5134633

Please sign in to comment.