reads a single channel (incremental) encoder
More...
#include <JEncoderSingle.h>
|
bool | getRev () |
| get whether the encoder is told it's going backwards currently
|
|
void | setRev (bool _rev) |
| set which direction the encoder is moving (if you have external information about direction (like motor power) and want getVel and getDist to go the right direction even with this directionless encoder)
|
|
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 | encoderISR (void) |
|
|
| JEncoderSingle (byte _encoderPin, float _distPerCountFactor, bool _reverse, unsigned long _slowestIntervalMicros, unsigned long _switchBounceIntervalMicros, byte _interruptType) |
| constructor, sets pins and settings
|
|
virtual void | setUpInterrupts (void(*_isrPointer)(void)) |
| set up pins and interrupts
|
|
virtual void | turnOffInterrupts () |
| disable interrupts and stop monitoring encoder
|
|
reads a single channel (incremental) encoder
direction can't be calculated with a single channel encoder, only speed can be.
speed calculation is done by measuring time between 2 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
◆ JEncoderSingle()
JEncoderSingle::JEncoderSingle |
( |
byte |
_encoderPin, |
|
|
float |
_distPerCountFactor, |
|
|
bool |
_reverse, |
|
|
unsigned long |
_slowestIntervalMicros, |
|
|
unsigned long |
_switchBounceIntervalMicros, |
|
|
byte |
_interruptType |
|
) |
| |
|
inlineprotected |
constructor, sets pins and settings
- Parameters
-
_encoderPin | encoder input pin |
_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. |
_switchBounceIntervalMicros | ignore additional pulses for this many microseconds after each pulse |
_interruptType | CHANGE, RISING, FALLING |
◆ encoderISR()
void JEncoderSingle::encoderISR |
( |
void |
| ) |
|
|
inline |
◆ getCounter()
long JEncoderSingle::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 JEncoderSingle::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 JEncoderSingle::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.
◆ getRev()
bool JEncoderSingle::getRev |
( |
| ) |
|
|
inline |
get whether the encoder is told it's going backwards currently
- Return values
-
◆ getVel()
float JEncoderSingle::getVel |
( |
| ) |
|
|
inlinevirtual |
calculates velocity in distance per second where distance was set by setdistPerCountFactor()
- Return values
-
Reimplemented from JEncoder.
◆ hasDirection()
bool JEncoderSingle::hasDirection |
( |
| ) |
|
|
inlinevirtual |
can this encoder measure direction or just speed
- Return values
-
(bool) | true = can measure direction |
Reimplemented from JEncoder.
◆ isVelNew()
bool JEncoderSingle::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 JEncoderSingle::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 JEncoderSingle::setDistPerCountFactor |
( |
float |
_factor | ) |
|
|
inlinevirtual |
set the conversion factor between encoder ticks and distance
- Parameters
-
Reimplemented from JEncoder.
◆ setRev()
void JEncoderSingle::setRev |
( |
bool |
_rev | ) |
|
|
inlinevirtual |
set which direction the encoder is moving (if you have external information about direction (like motor power) and want getVel and getDist to go the right direction even with this directionless encoder)
- Parameters
-
_rev | (bool) false=forwards true=backwards |
Reimplemented from JEncoder.
◆ setReverse()
void JEncoderSingle::setReverse |
( |
bool |
_reverse | ) |
|
|
inline |
reverse readings of encoder
- Parameters
-
_reverse | whether to invert sign of readings |
- Return values
-
◆ setUpInterrupts()
virtual void JEncoderSingle::setUpInterrupts |
( |
void(*)(void) |
_isrPointer | ) |
|
|
protectedvirtual |
◆ turnOffInterrupts()
virtual void JEncoderSingle::turnOffInterrupts |
( |
| ) |
|
|
protectedvirtual |
◆ zeroCounter()
long JEncoderSingle::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.
◆ encoderPin
unsigned char JEncoderSingle::encoderPin |
|
protected |
◆ interruptType
byte JEncoderSingle::interruptType |
|
protected |
The documentation for this class was generated from the following file: