QPIDfirmware  v0.1
Object oriented firmware for autonomous motor drivers with encoder based PID controller and flexible interface
QPID_Encoder Class Reference

Mostly abstract class for any kind of rotary encoder with optional filtering for jittery or error prone inputs. More...

Inheritance diagram for QPID_Encoder:

Public Member Functions

virtual double getCount ()
 (abstract) Get current incremental position count
 
virtual void setCount (double count)
 (abstract) Set current position count
 
virtual void clearCount ()
 (abstract) Set current position count to 0
 
virtual void pauseCount ()
 (abstract) Stop counting until told otherwise. Meant for interrupt or constant polling type encoders which otherwise would go on counting by themselves. More...
 
virtual void resumeCount ()
 (abstract) Resume counting. More...
 
void setFilter (double value)
 Set filter to smoothen faulty or jittery absolute readings. More...
 
double getFilteredCount ()
 Returns current position count with filter setting applied. More...
 
- Public Member Functions inherited from QPID_Object
virtual void update ()
 (abstract) Can be overridden by QPID subsystems which need to do their own polling. Will be called by QPID_Unit::update() for subsystems, and by firmware/client for QPID_Unit itself.
 
void throwError (const char *invokedBy, const char *errorMessage)
 Writes error message and error invoking class to Serial. More...
 
void log (const char *logEntry)
 Puts timestamped string into the system log (atm: writes it out to Serial). More...
 

Public Attributes

double ticksPerRevolution
 

Protected Attributes

double filter = 0
 
double lastCount = 0
 

Additional Inherited Members

- Protected Member Functions inherited from QPID_Object
 QPID_Object ()
 Constructor. Begins Serial with 115200 baud for logging and error reporting, if not done previously.
 
virtual bool processMessage (uint8_t *message)
 (abstract) Interprets message handed down from QPID_Unit locally. Must be overridden in derived classes
 

Detailed Description

Mostly abstract class for any kind of rotary encoder with optional filtering for jittery or error prone inputs.

) This base class assumes an incremental type encoders (e.g. quadrature encoder), which keeps counting up or down forever. Derived classes for angular type encoders (e.g. potentiometer, agular hall sensor), which start counting at 0 after a full turn, have to keep count of full turns internally, so that they, too, can provide an incremental total count.

Todo:
Add derived base class for angular type encoders which takes care of the full turn wraparound/overflow problem.

Member Function Documentation

◆ pauseCount()

virtual void QPID_Encoder::pauseCount ( )
inlinevirtual

(abstract) Stop counting until told otherwise. Meant for interrupt or constant polling type encoders which otherwise would go on counting by themselves.

See also
resumeCount()

Reimplemented in QPID_Encoder_QuadratureStateMachine, and QPID_Encoder_ESP32.

◆ resumeCount()

virtual void QPID_Encoder::resumeCount ( )
inlinevirtual

(abstract) Resume counting.

See also
pauseCount()

Reimplemented in QPID_Encoder_QuadratureStateMachine, and QPID_Encoder_ESP32.

◆ setFilter()

void QPID_Encoder::setFilter ( double  value)

Set filter to smoothen faulty or jittery absolute readings.

Filtering is designed particularly with angular type encoders in mind, e.g. potentiometers connected to a noisy analog input. Use getFilteredCount() to actually receive filtered count positions, getCount() will always be unfiltered. The filter works by taking the currently measured sensor count and factoring in, weighted by the filter value, the count taken in the previous measurement. The formula is newCount = ((lastCount * filter) + getCount()) / (filter + 1). So, filtering comes at the cost of a lag in sensor reading, and the more filtering, the more lagging.

Parameters
valueFilter value. The bigger the value, the bigger the influence of the last measurement on the current one. A value of 1 gives last count and current count equal weights. Setting the filter value to 0 will deactivate the filter, so that getFilteredCount() and getCount() will return the same results.
See also
getFilteredCount()

◆ getFilteredCount()

double QPID_Encoder::getFilteredCount ( )

Returns current position count with filter setting applied.

See also
setFilter()

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