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

defines common interface for JEncoder More...

#include <JEncoder.h>

Inheritance diagram for JEncoder:
Inheritance graph
[legend]

Public Member Functions

virtual void setRev (bool _rev)
 empty function for directionless encoders to override
 
virtual long zeroCounter ()
 reset the counter of how far the encoder has turned
 
virtual float getVel ()
 calculates velocity in distance per second where distance was set by setdistPerCountFactor()
 
virtual long getCounter ()
 returns how far the encoder has turned from the zero position
 
virtual float getPos ()
 returns how far the encoder has turned from the zero position converted to distance
 
virtual float getDistPerCountFactor ()
 returns a conversion factor between encoder ticks and distance that can be set for the encoder
 
virtual void setDistPerCountFactor (float _factor)
 set the conversion factor between encoder ticks and distance
 
virtual bool hasDirection ()
 can this encoder measure direction or just speed
 
virtual bool isVelNew ()
 could be useful for only recalculating a control loop if there's new velocity data
 
virtual void run ()
 if an encoder needs to have some code called each loop (like absolute encoder polling encoder and calculating amount turned)
 

Detailed Description

defines common interface for JEncoder

Note
JEcoder's functions are virtual, it can not be used directly

Member Function Documentation

◆ getCounter()

virtual long JEncoder::getCounter ( )
virtual

returns how far the encoder has turned from the zero position

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

Reimplemented in JEncoderAS5048bI2C, JEncoderAS5600I2C, JEncoderBSED, JEncoderPWMAbsolute, JEncoderQuadrature, and JEncoderSingle.

◆ getDistPerCountFactor()

virtual float JEncoder::getDistPerCountFactor ( )
virtual

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 in JEncoderAS5048bI2C, JEncoderAS5600I2C, JEncoderBSED, JEncoderPWMAbsolute, JEncoderQuadrature, and JEncoderSingle.

◆ getPos()

virtual float JEncoder::getPos ( )
virtual

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 in JEncoderAS5048bI2C, JEncoderAS5600I2C, JEncoderBSED, JEncoderPWMAbsolute, JEncoderQuadrature, and JEncoderSingle.

◆ getVel()

virtual float JEncoder::getVel ( )
virtual

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

Return values
(float)velocity

Reimplemented in JEncoderAS5048bI2C, JEncoderAS5600I2C, JEncoderBSED, JEncoderPWMAbsolute, JEncoderQuadrature, and JEncoderSingle.

◆ hasDirection()

virtual bool JEncoder::hasDirection ( )
virtual

can this encoder measure direction or just speed

Return values
(bool)true = can measure direction

Reimplemented in JEncoderAS5048bI2C, JEncoderAS5600I2C, JEncoderBSED, JEncoderPWMAbsolute, JEncoderQuadrature, and JEncoderSingle.

◆ isVelNew()

virtual bool JEncoder::isVelNew ( )
virtual

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 in JEncoderAS5048bI2C, JEncoderAS5600I2C, JEncoderBSED, JEncoderPWMAbsolute, JEncoderQuadrature, and JEncoderSingle.

◆ run()

virtual void JEncoder::run ( )
virtual

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 in JEncoderAS5048bI2C, JEncoderAS5600I2C, JEncoderBSED, JEncoderPWMAbsolute, JEncoderQuadrature, and JEncoderSingle.

◆ setDistPerCountFactor()

virtual void JEncoder::setDistPerCountFactor ( float  _factor)
virtual

set the conversion factor between encoder ticks and distance

Parameters
_factor(float)

Reimplemented in JEncoderAS5048bI2C, JEncoderAS5600I2C, JEncoderBSED, JEncoderPWMAbsolute, JEncoderQuadrature, and JEncoderSingle.

◆ setRev()

virtual void JEncoder::setRev ( bool  _rev)
inlinevirtual

empty function for directionless encoders to override

Reimplemented in JEncoderSingle.

◆ zeroCounter()

virtual long JEncoder::zeroCounter ( )
virtual

reset the counter of how far the encoder has turned

Return values
(long)returns value of counter before it is reset

Reimplemented in JEncoderAS5048bI2C, JEncoderAS5600I2C, JEncoderBSED, JEncoderPWMAbsolute, JEncoderQuadrature, and JEncoderSingle.


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