ClearCore Library
Loading...
Searching...
No Matches
List of all members | Public Member Functions
ClearCore::EncoderInput Class Reference

Detailed Description

ClearCore Position Sensor Decoder.

Provides position and velocity information from external quadrature and index signals. Use the Encoder Input Adapter Board (PN: CL-ENCDR-DFIN) to wire an external encoder to ClearCore.

Note
When using the Encoder Input Adapter Board, ClearCore's DI-6/DI-7/DI-8 inputs will be unavailable. Refer to the ClearCore User Manual for specs and wiring information.

ClearCore Position Sensor Decoder. More...

#include <EncoderInput.h>

Public Member Functions

int32_t Position ()
 Read the current position of the encoder.
 
int32_t Position (int32_t newPosn)
 Set the current position of the encoder.
 
void AddToPosition (int32_t posnAdjust)
 Adjust the current position of the encoder.
 
int32_t IndexPosition ()
 Read the last index position of the encoder.
 
void Enable (bool isEnabled)
 Set whether the encoder input should be active or not.
 
void SwapDirection (bool isSwapped)
 Swap the sense of positive and negative encoder directions.
 
volatile const int32_t & Velocity ()
 Read the velocity of the encoder input (counts per second)
 
volatile const bool & IndexDetected ()
 Check if there was an index pulse in the last sample time.
 
void IndexInverted (bool invert)
 Invert the edge that the index detection triggers on.
 
bool QuadratureError ()
 Query for a quadrature error.
 
void ClearQuadratureError ()
 Clear a quadrature error.
 
volatile const int16_t & StepsLastSample ()
 Get the number of encoder steps received in the last sample time.
 

Member Function Documentation

◆ AddToPosition()

void ClearCore::EncoderInput::AddToPosition ( int32_t  posnAdjust)

Adjust the current position of the encoder.

// Shift the encoder numberspace upwards by 500 counts
void AddToPosition(int32_t posnAdjust)
Adjust the current position of the encoder.
EncoderInput EncoderIn
Position Decoder.

◆ ClearQuadratureError()

void ClearCore::EncoderInput::ClearQuadratureError ( )

Clear a quadrature error.

// Clear a quadrature error if there is one
}
bool QuadratureError()
Query for a quadrature error.
void ClearQuadratureError()
Clear a quadrature error.

◆ Enable()

void ClearCore::EncoderInput::Enable ( bool  isEnabled)

Set whether the encoder input should be active or not.

// Before using the Encoder Input, it has to be enabled.
void Enable(bool isEnabled)
Set whether the encoder input should be active or not.
Examples
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp, and FollowEncoder.cpp.

◆ IndexDetected()

volatile const bool & ClearCore::EncoderInput::IndexDetected ( )
inline

Check if there was an index pulse in the last sample time.

// Check for an index pulse
bool hadIndex = EncoderIn.IndexDetected();
volatile const bool & IndexDetected()
Check if there was an index pulse in the last sample time.
Definition EncoderInput.h:188
Returns
True if the index transitioned from deasserted to asserted in the last sample time.

◆ IndexInverted()

void ClearCore::EncoderInput::IndexInverted ( bool  invert)

Invert the edge that the index detection triggers on.

The index nominally triggers when the digital input value rises. This setting allows the index to trigger on the falling edge.

// Set the index pulse to trigger on the falling input edge.
bool hadIndex = EncoderIn.IndexInverted(true);
void IndexInverted(bool invert)
Invert the edge that the index detection triggers on.
Examples
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp, and FollowEncoder.cpp.

◆ IndexPosition()

int32_t ClearCore::EncoderInput::IndexPosition ( )

Read the last index position of the encoder.

static int32_t lastIndex = 0;
if (EncoderIn.IndexPosition() != lastIndex) {
// A new index pulse was seen, do something.
// Update the position of the last index pulse seen
lastIndex = EncoderIn.IndexPosition();
}
int32_t IndexPosition()
Read the last index position of the encoder.
Returns
The position count of the last Encoder index pulse.
Examples
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp, and FollowEncoder.cpp.

◆ Position() [1/2]

int32_t ClearCore::EncoderInput::Position ( )

Read the current position of the encoder.

if (EncoderIn.Position() > 1000) {
// Position passed 1000, do something.
}
int32_t Position()
Read the current position of the encoder.
Returns
The position count of the Encoder Input module.
Examples
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp, and FollowEncoder.cpp.

◆ Position() [2/2]

int32_t ClearCore::EncoderInput::Position ( int32_t  newPosn)

Set the current position of the encoder.

// Zero the encoder position
Returns
The number of counts that the encoder position was shifted.

◆ QuadratureError()

bool ClearCore::EncoderInput::QuadratureError ( )

Query for a quadrature error.

// Check for a quadrature error
bool quadratureError = EncoderIn.QuadratureError();
Returns
The current state of the quadrature error flag in the position decoder module.
Examples
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp, and FollowEncoder.cpp.

◆ StepsLastSample()

volatile const int16_t & ClearCore::EncoderInput::StepsLastSample ( )
inline

Get the number of encoder steps received in the last sample time.

// Do something in the case that we haven't received steps
}
volatile const int16_t & StepsLastSample()
Get the number of encoder steps received in the last sample time.
Definition EncoderInput.h:241
Returns
The number of steps received in the last sample time.

◆ SwapDirection()

void ClearCore::EncoderInput::SwapDirection ( bool  isSwapped)

Swap the sense of positive and negative encoder directions.

// Set the encoder counting direction to match the wiring and code.
void SwapDirection(bool isSwapped)
Swap the sense of positive and negative encoder directions.
Examples
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp, and FollowEncoder.cpp.

◆ Velocity()

volatile const int32_t & ClearCore::EncoderInput::Velocity ( )
inline

Read the velocity of the encoder input (counts per second)

// Read the current encoder velocity
int32_t encoderSpeed = EncoderIn.Velocity();
volatile const int32_t & Velocity()
Read the velocity of the encoder input (counts per second)
Definition EncoderInput.h:173
Returns
The encoder input velocity in counts per second.
Examples
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp, and FollowEncoder.cpp.

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