JMotor
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
JEncoderQuadrature Class Reference

reads a quadrature (incremental) encoder More...

#include <JEncoderQuadrature.h>

Inheritance diagram for JEncoderQuadrature:
Inheritance graph
[legend]
Collaboration diagram for JEncoderQuadrature:
Collaboration graph
[legend]

Public Member Functions

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)
 
- Public Member Functions inherited from JEncoder
virtual void setRev (bool _rev)
 empty function for directionless encoders to override
 

Protected Member Functions

 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
 

Protected Attributes

byte encoderAPin
 
byte encoderBPin
 

Detailed Description

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

Constructor & Destructor Documentation

◆ 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
_encoderAPinone channel of quadrature encoder
_encoderBPinother channel of quadrature encoder
_distPerCountFactorconversion factor for getting distance in an actual unit
_reversefalse(default)
_slowestIntervalMicrosafter this many microseconds without an encoder tick velocity is set to zero.

Member Function Documentation

◆ getCounter()

long JEncoderQuadrature::getCounter ( )
inlinevirtual

returns how far the encoder has turned from the zero position

Note
remember that variables overflow
Return values
(long)encoder ticks

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
(float)velocity

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
_factor(float)

Reimplemented from JEncoder.

◆ setReverse()

void JEncoderQuadrature::setReverse ( bool  _reverse)
inline

reverse readings of encoder

Parameters
_reversewhether to invert sign of readings
Return values
None

◆ setUpInterrupts()

virtual void JEncoderQuadrature::setUpInterrupts ( void(*)(void)  _isrAPointer,
void(*)(void)  _isrBPointer 
)
protectedvirtual

set up pins and interrupts

Parameters
_isrAPointerglobal function that calls internal ISRA, to use with enableInterrupt
_isrBPointerglobal function that calls internal ISRB, to use with enableInterrupt

Reimplemented in JEncoderQuadratureAttachInterrupt, and JEncoderQuadraturePinChange.

◆ turnOffInterrupts()

virtual void JEncoderQuadrature::turnOffInterrupts ( )
protectedvirtual

disable interrupts and stop monitoring encoder

Note
use setUpInterrupts to start encoder again

Reimplemented in JEncoderQuadratureAttachInterrupt, and JEncoderQuadraturePinChange.

◆ 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.

Member Data Documentation

◆ encoderAPin

byte JEncoderQuadrature::encoderAPin
protected

◆ encoderBPin

byte JEncoderQuadrature::encoderBPin
protected

The documentation for this class was generated from the following file: