reads a quadrature (incremental) encoder
More...
#include <JEncoderQuadrature.h>
|
long | zeroCounter () |
| 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) |
| set the conversion factor between encoder ticks and distance
|
|
void | setReverse (bool _reverse) |
| reverse readings of encoder
|
|
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 | run () |
| if an encoder needs to have some code called each loop (like absolute encoder polling encoder and calculating amount turned)
|
|
void | ISRA (void) |
|
void | ISRB (void) |
|
virtual void | setRev (bool _rev) |
| empty function for directionless encoders to override
|
|
|
| JEncoderQuadrature (byte _encoderAPin, byte _encoderBPin, float _distPerCountFactor=1.0, bool _reverse=false, unsigned long _slowestIntervalMicros=100000UL) |
| constructor, sets pins and settings
|
|
virtual void | setUpInterrupts (void(*_isrAPointer)(void), void(*_isrBPointer)(void)) |
| set up pins and interrupts
|
|
virtual void | turnOffInterrupts () |
| disable interrupts and stop monitoring encoder
|
|
reads a quadrature (incremental) encoder
speed calulation is done by measuring time between 4 encoder ticks (not between every tick since encoders may not have evenly spaced ticks) velocity is set to zero if the encoder has not turned in slowestIntervalMicros
- Note
- don't use this class directly, use a subclass
◆ JEncoderQuadrature()
JEncoderQuadrature::JEncoderQuadrature |
( |
byte |
_encoderAPin, |
|
|
byte |
_encoderBPin, |
|
|
float |
_distPerCountFactor = 1.0 , |
|
|
bool |
_reverse = false , |
|
|
unsigned long |
_slowestIntervalMicros = 100000UL |
|
) |
| |
|
inlineprotected |
constructor, sets pins and settings
- Note
- Parameters
-
_encoderAPin | one channel of quadrature encoder |
_encoderBPin | other channel of quadrature encoder |
_distPerCountFactor | conversion factor for getting distance in an actual unit |
_reverse | false(default) |
_slowestIntervalMicros | after this many microseconds without an encoder tick velocity is set to zero. |
◆ getCounter()
long JEncoderQuadrature::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 JEncoderQuadrature::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 JEncoderQuadrature::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 JEncoderQuadrature::getVel |
( |
| ) |
|
|
inlinevirtual |
calculates velocity in distance per second where distance was set by setdistPerCountFactor()
- Return values
-
Reimplemented from JEncoder.
◆ hasDirection()
bool JEncoderQuadrature::hasDirection |
( |
| ) |
|
|
inlinevirtual |
can this encoder measure direction or just speed
- Return values
-
(bool) | true = can measure direction |
Reimplemented from JEncoder.
◆ ISRA()
void JEncoderQuadrature::ISRA |
( |
void |
| ) |
|
|
inline |
◆ ISRB()
void JEncoderQuadrature::ISRB |
( |
void |
| ) |
|
|
inline |
◆ isVelNew()
bool JEncoderQuadrature::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.
◆ run()
void JEncoderQuadrature::run |
( |
| ) |
|
|
inlinevirtual |
if an encoder needs to have some code called each loop (like absolute encoder polling encoder and calculating amount turned)
- Note
- interrupt based encoders don't need this to do anything and can define an empty function
Reimplemented from JEncoder.
◆ setDistPerCountFactor()
void JEncoderQuadrature::setDistPerCountFactor |
( |
float |
_factor | ) |
|
|
inlinevirtual |
set the conversion factor between encoder ticks and distance
- Parameters
-
Reimplemented from JEncoder.
◆ setReverse()
void JEncoderQuadrature::setReverse |
( |
bool |
_reverse | ) |
|
|
inline |
reverse readings of encoder
- Parameters
-
_reverse | whether to invert sign of readings |
- Return values
-
◆ setUpInterrupts()
virtual void JEncoderQuadrature::setUpInterrupts |
( |
void(*)(void) |
_isrAPointer, |
|
|
void(*)(void) |
_isrBPointer |
|
) |
| |
|
protectedvirtual |
◆ turnOffInterrupts()
virtual void JEncoderQuadrature::turnOffInterrupts |
( |
| ) |
|
|
protectedvirtual |
◆ zeroCounter()
long JEncoderQuadrature::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.
◆ encoderAPin
byte JEncoderQuadrature::encoderAPin |
|
protected |
◆ encoderBPin
byte JEncoderQuadrature::encoderBPin |
|
protected |
The documentation for this class was generated from the following file: