myWRIO
C++ framework for NationalInstruments myRIO
myRIO::Encoder Class Reference

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
 

Detailed Description

Embedded encoder.

Definition at line 20 of file Encoder.h.

Constructor & Destructor Documentation

◆ Encoder()

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.

Parameters
channelone of ENCA, ENCB

Definition at line 12 of file Encoder.cpp.

◆ ~Encoder()

Encoder::~Encoder ( )

Destructeur Stop the encoder and disable it.

Definition at line 92 of file Encoder.cpp.

Member Function Documentation

◆ direction()

void Encoder::direction ( bool &  dir)

Return the direction of the motor (CCW -> 0, CW -> 1)

Definition at line 51 of file Encoder.cpp.

◆ read()

void Encoder::read ( uint32_t &  enc)

Read encoder Reads the value of the encoder.

Parameters
encthe encoder address

Definition at line 44 of file Encoder.cpp.

◆ startThread()

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°,

See also
MotorPID::toAngularSpeed
Parameters
funca function to execute when threshold is reached
thresholdthe number of increments before executing the function

Definition at line 65 of file Encoder.cpp.

◆ stopThread()

void Encoder::stopThread ( )

Stop the encoder thread.

Definition at line 85 of file Encoder.cpp.

Member Data Documentation

◆ regCnfg

uint32_t myRIO::Encoder::regCnfg
private

Definition at line 32 of file Encoder.h.

◆ regCntr

uint32_t myRIO::Encoder::regCntr
private

Definition at line 33 of file Encoder.h.

◆ regStat

uint32_t myRIO::Encoder::regStat
private

Definition at line 34 of file Encoder.h.

◆ run

bool* myRIO::Encoder::run
private

Definition at line 31 of file Encoder.h.

◆ th

std::thread* myRIO::Encoder::th
private

Definition at line 30 of file Encoder.h.


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