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

reads a quadrature (incremental) encoder that is connected to a Byte Sized Encoder Decoder board connected over I2C to the main controller More...

#include <JEncoderBSED.h>

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

Public Member Functions

 JEncoderBSED (ByteSizedEncoderDecoder &_bsed, byte _encoderChannel, bool _reverse=false, float _distPerCountFactor=1.0, int16_t _slowestIntervalMicros=0, int16_t _encoderEnoughCounts=0)
 constructor, sets pins and settings
 
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)
 
- Public Member Functions inherited from JEncoder
virtual void setRev (bool _rev)
 empty function for directionless encoders to override
 

Protected Attributes

ByteSizedEncoderDecoder & bsed
 
byte encoderChannel
 
float distPerCountFactor
 
int8_t reverse
 
int32_t zeroVal
 

Detailed Description

reads a quadrature (incremental) encoder that is connected to a Byte Sized Encoder Decoder board connected over I2C to the main controller

Constructor & Destructor Documentation

◆ JEncoderBSED()

JEncoderBSED::JEncoderBSED ( ByteSizedEncoderDecoder &  _bsed,
byte  _encoderChannel,
bool  _reverse = false,
float  _distPerCountFactor = 1.0,
int16_t  _slowestIntervalMicros = 0,
int16_t  _encoderEnoughCounts = 0 
)
inline

constructor, sets pins and settings

Note
Parameters
_bsedinstance of BSED class
_encoderChannelchannel of encoder on BSED (1-8)
_reversefalse(default)
_distPerCountFactorconversion factor for getting distance in an actual unit
_slowestIntervalMicrosafter this many microseconds without an encoder tick velocity is set to zero.
_encoderEnoughCountsenough counts to calculate velocity from

Member Function Documentation

◆ getCounter()

long JEncoderBSED::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 JEncoderBSED::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 JEncoderBSED::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 JEncoderBSED::getVel ( )
inlinevirtual

calculates velocity in distance per second where distance was set by setdistPerCountFactor()

Return values
(float)velocity

Reimplemented from JEncoder.

◆ hasDirection()

bool JEncoderBSED::hasDirection ( )
inlinevirtual

can this encoder measure direction or just speed

Return values
(bool)true = can measure direction

Reimplemented from JEncoder.

◆ isVelNew()

bool JEncoderBSED::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 JEncoderBSED::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 JEncoderBSED::setDistPerCountFactor ( float  _factor)
inlinevirtual

set the conversion factor between encoder ticks and distance

Parameters
_factor(float)

Reimplemented from JEncoder.

◆ setReverse()

void JEncoderBSED::setReverse ( bool  _reverse)
inline

reverse readings of encoder

Parameters
_reversewhether to invert sign of readings
Return values
None

◆ zeroCounter()

long JEncoderBSED::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

◆ bsed

ByteSizedEncoderDecoder& JEncoderBSED::bsed
protected

◆ distPerCountFactor

float JEncoderBSED::distPerCountFactor
protected

◆ encoderChannel

byte JEncoderBSED::encoderChannel
protected

◆ reverse

int8_t JEncoderBSED::reverse
protected

◆ zeroVal

int32_t JEncoderBSED::zeroVal
protected

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