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

Member Function Documentation

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

Adjust the current position of the encoder.

// Shift the encoder numberspace upwards by 500 counts
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
void ClearCore::EncoderInput::ClearQuadratureError ( )

Clear a quadrature error.

// Clear a quadrature error if there is one
}
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
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.
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
Examples:
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp.
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();
Returns
True if the index transitioned from deasserted to asserted in the last sample time.
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
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);
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
Examples:
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp.
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();
}
Returns
The position count of the last Encoder index pulse.
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
Examples:
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp.
int32_t ClearCore::EncoderInput::Position ( )

Read the current position of the encoder.

if (EncoderIn.Position() > 1000) {
// Position passed 1000, do something.
}
Returns
The position count of the Encoder Input module.
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
Examples:
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp.
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.
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
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.
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
Examples:
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp.
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
}
Returns
The number of steps received in the last sample time.
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
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.
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
Examples:
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp.
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();
Returns
The encoder input velocity in counts per second.
Note
Available with software version 1.1 or greater. See Installation and Update Instructions for information on updating library versions.
Examples:
EncoderInputExamples/FollowEncoder/FollowEncoder.cpp.

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