myWRIO
C++ framework for NationalInstruments myRIO
|
Embedded encoder. More...
#include <Encoder.h>
Public Member Functions | |
Encoder (uint8_t channel) | |
Create an Encoder Enable channel A or B encoder. More... | |
void | read (uint32_t &enc) |
Read encoder Reads the value of the encoder. More... | |
void | direction (bool &dir) |
Return the direction of the motor (CCW -> 0, CW -> 1) More... | |
void | startThread (std::function< void(long enc, bool dir)> func, unsigned int threshold) |
Start a thread that will monitor the encoder register. More... | |
void | stopThread () |
Stop the encoder thread. More... | |
~Encoder () | |
Destructeur Stop the encoder and disable it. More... | |
Private Attributes | |
std::thread * | th |
bool * | run |
uint32_t | regCnfg |
uint32_t | regCntr |
uint32_t | regStat |
Encoder::Encoder | ( | uint8_t | channel | ) |
Create an Encoder Enable channel A or B encoder.
There is also an Encoder on channel C which can be added.
channel | one of ENCA, ENCB |
Definition at line 12 of file Encoder.cpp.
Encoder::~Encoder | ( | ) |
Destructeur Stop the encoder and disable it.
Definition at line 92 of file Encoder.cpp.
void Encoder::direction | ( | bool & | dir | ) |
Return the direction of the motor (CCW -> 0, CW -> 1)
Definition at line 51 of file Encoder.cpp.
void Encoder::read | ( | uint32_t & | enc | ) |
Read encoder Reads the value of the encoder.
enc | the encoder address |
Definition at line 44 of file Encoder.cpp.
void Encoder::startThread | ( | std::function< void(long enc, bool dir)> | func, |
unsigned int | threshold | ||
) |
Start a thread that will monitor the encoder register.
It will alert the user if a given threshold is reached, executing the given function. The threshold is a variation since the last threshold reach (or 0 if none have been reached) 1 increment ~ 0.58°,
func | a function to execute when threshold is reached |
threshold | the number of increments before executing the function |
Definition at line 65 of file Encoder.cpp.
void Encoder::stopThread | ( | ) |
Stop the encoder thread.
Definition at line 85 of file Encoder.cpp.