reads a type of absolute encoder https://ams.com/en/as5600 (uses I2C)
More...
#include <JEncoderAS5600I2C.h>
|
void | writeRegister8 (uint8_t reg, uint8_t value) |
|
void | writeRegister12 (uint8_t reg, uint16_t value) |
|
uint16_t | readRegister12 (uint8_t reg) |
|
uint8_t | readRegister8 (uint8_t reg) |
|
| JEncoderAS5600I2C (bool _reverse=false, float _distPerCountFactor=1.0, uint16_t _zeroAngle=0, unsigned long _velEnoughTime=0, unsigned long _velEnoughTicks=0, bool _recognizeOutOfRange=true) |
| sets pins and settings for reading the encoder, remember to use Wire.begin()
|
|
uint8_t | getAutoGain () |
|
uint16_t | readAngle () |
| angle in raw units, but adjusted for custom zero
|
|
void | useCustomWire (TwoWire &_wire) |
| Set what Wire (I2C) bus to use (for microcontrollers with more than one)
|
|
void | run () |
| communication is done over I2C and requires constant polling instead of being able to use interrupts
|
|
void | setEncoderZero (int _zeroAngle) |
| A custom (repeatable) angle can be set for what the sensor calls zero relative to default zero.
|
|
void | setEncoderZero () |
| set current angle as zero
|
|
int | rawReading () |
|
bool | isMagnetInRange () |
| is the magnet in the optimal position Unlike other functions, this function does not rely on run()
|
|
long | intTurns () |
| how many full turns the encoder has made.
|
|
long | zeroCounter () |
| reset the counter of how far the encoder has turned
|
|
long | zeroCounter (bool _resetAngle) |
| reset the counter of how far the encoder has turned
|
|
float | getVel () |
| calculates velocity in distance per second where distance was set by setdistPerCountFactor()
|
|
long | getCounter () |
| returns how far the encoder has turned from the zero position
|
|
float | getPos () |
| returns how far the encoder has turned from the zero position converted to distance
|
|
float | getDistPerCountFactor () |
| returns a conversion factor between encoder ticks and distance that can be set for the encoder
|
|
void | setDistPerCountFactor (float _factor) |
|
bool | hasDirection () |
| can this encoder measure direction or just speed
|
|
bool | isVelNew () |
| could be useful for only recalculating a control loop if there's new velocity data
|
|
void | setVelEnoughTime (unsigned long _velEnoughTime) |
|
void | setVelEnoughTicks (unsigned long _velEnoughTicks) |
|
void | setRecognizeOutOfRange (bool _recognizeOutOfRange) |
|
virtual void | setRev (bool _rev) |
| empty function for directionless encoders to override
|
|
reads a type of absolute encoder https://ams.com/en/as5600 (uses I2C)
- Note
- remember to add pull up resistors on I2C lines (~4.7k for 5v, ~2.4k for 3.3v microcontrollers).
◆ JEncoderAS5600I2C()
JEncoderAS5600I2C::JEncoderAS5600I2C |
( |
bool |
_reverse = false , |
|
|
float |
_distPerCountFactor = 1.0 , |
|
|
uint16_t |
_zeroAngle = 0 , |
|
|
unsigned long |
_velEnoughTime = 0 , |
|
|
unsigned long |
_velEnoughTicks = 0 , |
|
|
bool |
_recognizeOutOfRange = true |
|
) |
| |
|
inline |
sets pins and settings for reading the encoder, remember to use Wire.begin()
- Note
- remember to use Wire.begin()
- Parameters
-
_reverse | (bool) reverse positive direction, default=false |
_distPerCountFactor | (float) for the purposes of setting this factor a "count" is considered a full revolution of the absolute encoder |
_zeroAngle | (int) [0, STEPS_PER_TURN) custom zero angle for absolute encoder |
_velEnoughTime | (default=0, no limit) shortest interval in microseconds between velocity calculations, if run() is called faster the calculation will wait to run |
_velEnoughTicks | (default=0, no limit) if the encoder turns more than this number of steps velocity calculations will be done even if velEnoughTime hasn't been reached |
_recognizeOutOfRange | (boolean, default=true) set velocity to zero and stop updating position if encoder reports that it's out of range |
◆ getAutoGain()
uint8_t JEncoderAS5600I2C::getAutoGain |
( |
| ) |
|
|
inline |
- Note
- bad if 255 (magnet too far) or 0 (magnet too close)
◆ getCounter()
long JEncoderAS5600I2C::getCounter |
( |
| ) |
|
|
inlinevirtual |
returns how far the encoder has turned from the zero position
- Note
- remember that variables overflow
- Return values
-
Reimplemented from JEncoder.
◆ getDistPerCountFactor()
float JEncoderAS5600I2C::getDistPerCountFactor |
( |
| ) |
|
|
inlinevirtual |
returns a conversion factor between encoder ticks and distance that can be set for the encoder
- Note
- default is 1.0
- Return values
-
(float) | distPerCountFactor |
Reimplemented from JEncoder.
◆ getPos()
float JEncoderAS5600I2C::getPos |
( |
| ) |
|
|
inlinevirtual |
returns how far the encoder has turned from the zero position converted to distance
- Note
- remember that variables overflow (counter) and that floats have limited precision
- Return values
-
(float) | encoder ticks converted to distance |
Reimplemented from JEncoder.
◆ getVel()
float JEncoderAS5600I2C::getVel |
( |
| ) |
|
|
inlinevirtual |
calculates velocity in distance per second where distance was set by setdistPerCountFactor()
- Return values
-
Reimplemented from JEncoder.
◆ hasDirection()
bool JEncoderAS5600I2C::hasDirection |
( |
| ) |
|
|
inlinevirtual |
can this encoder measure direction or just speed
- Return values
-
(bool) | true = can measure direction |
Reimplemented from JEncoder.
◆ intTurns()
long JEncoderAS5600I2C::intTurns |
( |
| ) |
|
|
inline |
how many full turns the encoder has made.
- Note
- this and rawReading can be used as an alternative to getPos if the limited precision of a float is a concern
- Return values
-
(long) | how far the encoder has turned |
◆ isMagnetInRange()
bool JEncoderAS5600I2C::isMagnetInRange |
( |
| ) |
|
|
inline |
is the magnet in the optimal position Unlike other functions, this function does not rely on run()
- Note
- if this is false, the encoder may still be providing angle information
- Return values
-
◆ isVelNew()
bool JEncoderAS5600I2C::isVelNew |
( |
| ) |
|
|
inlinevirtual |
could be useful for only recalculating a control loop if there's new velocity data
- Return values
-
(bool) | true if velocity has changed since this function was last called |
Reimplemented from JEncoder.
◆ rawReading()
int JEncoderAS5600I2C::rawReading |
( |
| ) |
|
|
inline |
- Note
- divide by STEPS_PER_TURN to get fraction of full turn
- Return values
-
the | raw angle reading from the sensor (0 to 4095) |
◆ readAngle()
uint16_t JEncoderAS5600I2C::readAngle |
( |
| ) |
|
|
inline |
angle in raw units, but adjusted for custom zero
◆ readRegister12()
uint16_t JEncoderAS5600I2C::readRegister12 |
( |
uint8_t |
reg | ) |
|
|
inline |
◆ readRegister8()
uint8_t JEncoderAS5600I2C::readRegister8 |
( |
uint8_t |
reg | ) |
|
|
inline |
◆ run()
void JEncoderAS5600I2C::run |
( |
| ) |
|
|
inlinevirtual |
communication is done over I2C and requires constant polling instead of being able to use interrupts
- Note
- call this function as frequently as possible or this code can't keep track of how many times the encoder has turned
Reimplemented from JEncoder.
◆ setDistPerCountFactor()
void JEncoderAS5600I2C::setDistPerCountFactor |
( |
float |
_factor | ) |
|
|
inlinevirtual |
- Note
- for the purposes of setting this factor a "count" is considered a full revolution of the absolute encoder it is converted to actual counts within this function
Reimplemented from JEncoder.
◆ setEncoderZero() [1/2]
void JEncoderAS5600I2C::setEncoderZero |
( |
| ) |
|
|
inline |
set current angle as zero
- Return values
-
◆ setEncoderZero() [2/2]
void JEncoderAS5600I2C::setEncoderZero |
( |
int |
_zeroAngle | ) |
|
|
inline |
A custom (repeatable) angle can be set for what the sensor calls zero relative to default zero.
- Parameters
-
zeroAngle | (int) [0, STEPS_PER_TURN) |
◆ setRecognizeOutOfRange()
void JEncoderAS5600I2C::setRecognizeOutOfRange |
( |
bool |
_recognizeOutOfRange | ) |
|
|
inline |
- Parameters
-
_recognizeOutOfRange | (boolean, default=true) set velocity to zero and stop updating position if encoder reports that it's out of range |
◆ setVelEnoughTicks()
void JEncoderAS5600I2C::setVelEnoughTicks |
( |
unsigned long |
_velEnoughTicks | ) |
|
|
inline |
◆ setVelEnoughTime()
void JEncoderAS5600I2C::setVelEnoughTime |
( |
unsigned long |
_velEnoughTime | ) |
|
|
inline |
◆ useCustomWire()
void JEncoderAS5600I2C::useCustomWire |
( |
TwoWire & |
_wire | ) |
|
|
inline |
Set what Wire (I2C) bus to use (for microcontrollers with more than one)
- Parameters
-
◆ writeRegister12()
void JEncoderAS5600I2C::writeRegister12 |
( |
uint8_t |
reg, |
|
|
uint16_t |
value |
|
) |
| |
|
inline |
◆ writeRegister8()
void JEncoderAS5600I2C::writeRegister8 |
( |
uint8_t |
reg, |
|
|
uint8_t |
value |
|
) |
| |
|
inline |
◆ zeroCounter() [1/2]
long JEncoderAS5600I2C::zeroCounter |
( |
| ) |
|
|
inlinevirtual |
reset the counter of how far the encoder has turned
- Return values
-
(long) | returns value of counter before it is reset |
Reimplemented from JEncoder.
◆ zeroCounter() [2/2]
long JEncoderAS5600I2C::zeroCounter |
( |
bool |
_resetAngle | ) |
|
|
inline |
reset the counter of how far the encoder has turned
- Parameters
-
_resetAngle | (bool) default: true=zero absolute angle measurement and set current position to zero. false= zero out number of turns, but angle stays relative to absolute encoder's zero point |
- Return values
-
(long) | returns value of counter before it is reset |
◆ AGC_REG
const byte JEncoderAS5600I2C::AGC_REG = 0x1A |
◆ ANGLEMSB_REG
const byte JEncoderAS5600I2C::ANGLEMSB_REG = 0x0E |
◆ AS5048B_DEFAULT_ADDRESS
const byte JEncoderAS5600I2C::AS5048B_DEFAULT_ADDRESS = 0x36 |
|
static |
◆ BURN_REG
const byte JEncoderAS5600I2C::BURN_REG = 0xFF |
◆ CONF_REG
const byte JEncoderAS5600I2C::CONF_REG = 0x07 |
◆ MAGNITUDE_REG
const byte JEncoderAS5600I2C::MAGNITUDE_REG = 0x1B |
◆ MANG_REG
const byte JEncoderAS5600I2C::MANG_REG = 0x05 |
◆ MPOSMSB_REG
const byte JEncoderAS5600I2C::MPOSMSB_REG = 0X03 |
◆ RAWANGLEMSB_REG
const byte JEncoderAS5600I2C::RAWANGLEMSB_REG = 0x0C |
◆ STATUS_REG
const byte JEncoderAS5600I2C::STATUS_REG = 0x0B |
◆ STEPS_PER_TURN
const unsigned int JEncoderAS5600I2C::STEPS_PER_TURN = 4096 |
◆ ZMCO_REG
const byte JEncoderAS5600I2C::ZMCO_REG = 0x00 |
◆ ZPOSMSB_REG
const byte JEncoderAS5600I2C::ZPOSMSB_REG = 0x01 |
The documentation for this class was generated from the following file: