uStepper S
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
uStepperEncoder Class Reference

Prototype of class for the AEAT8800-Q24 encoder. More...

#include <uStepperEncoder.h>

Collaboration diagram for uStepperEncoder:
Collaboration graph

Public Member Functions

 uStepperEncoder (void)
 Constructor of uStepperEncoder class. More...
 
void init (uStepperS *_pointer)
 Initiation of the encoder. More...
 
void setHome (float initialAngle=0)
 Define new reference(home) position. More...
 
float getAngle (void)
 Return the current shaft angle in degrees. More...
 
uint16_t getAngleRaw (void)
 Return the current shaft angle in raw encoder readings. More...
 
float getAngleMoved (bool filtered=true)
 Returns the angle moved from reference position in degrees. More...
 
int32_t getAngleMovedRaw (bool filtered=true)
 Returns the angle moved from reference position in raw encoder readings. More...
 
float getSpeed (void)
 Measure the current speed of the motor. More...
 
float getRPM (void)
 Measure the current speed of the motor. More...
 
uint16_t captureAngle (void)
 Capture the current shaft angle. More...
 
uint8_t getStatus (void)
 Get encoder status. More...
 
bool detectMagnet (void)
 detect magnet More...
 

Public Attributes

volatile int32_t smoothValue
 
volatile float speedSmoothValue
 
volatile uint16_t encoderOffset
 
volatile uint16_t angle
 
volatile int32_t angleMoved
 
volatile uint16_t oldAngle
 
volatile float curSpeed
 
volatile posFilter_t encoderFilter
 
volatile uint8_t Beta = 5
 

Private Member Functions

void chipSelect (bool state)
 Set the output level of the chip select pin. More...
 

Private Attributes

uStepperSpointer
 
uint8_t status
 
int32_t userAngleOffset = 0
 
volatile int32_t angleMovedRaw = 0
 

Detailed Description

Prototype of class for the AEAT8800-Q24 encoder.

        This class enables the user of the library to access the AEAT8800-Q24
        encoder on the uStepper S board.

Definition at line 49 of file uStepperEncoder.h.

Constructor & Destructor Documentation

◆ uStepperEncoder()

uStepperEncoder::uStepperEncoder ( void  )

Constructor of uStepperEncoder class.

Definition at line 34 of file uStepperEncoder.cpp.

Member Function Documentation

◆ captureAngle()

uint16_t uStepperEncoder::captureAngle ( void  )

Capture the current shaft angle.

        This function is used by the ISR to read the current angle of the motor shaft.
        The Angle is read by means of the SSI interface, using the hardware SPI port.
Returns
samples the encoder and returns the current angle reading

Definition at line 115 of file uStepperEncoder.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chipSelect()

void uStepperEncoder::chipSelect ( bool  state)
private

Set the output level of the chip select pin.

Parameters
[in]state- 1 = High, 0 = low

Definition at line 226 of file uStepperEncoder.cpp.

Here is the caller graph for this function:

◆ detectMagnet()

bool uStepperEncoder::detectMagnet ( void  )

detect magnet

        This function reads the current status of the encoder with regards to placement
        of the magnet.
Returns
checks if the magnet is placed in the correct distance from the encoder: 0: everything is OK 1: magnet is placed either too far away or too close to the encoder

Definition at line 99 of file uStepperEncoder.cpp.

Here is the call graph for this function:

◆ getAngle()

float uStepperEncoder::getAngle ( void  )

Return the current shaft angle in degrees.

        This function returns the last captured shaft angle.
        The resolution of the angle returned by this function is
        0.0054931640625 degrees (16 bits)
Returns
Floating point representation of the current motor shaft angle

Definition at line 171 of file uStepperEncoder.cpp.

◆ getAngleMoved()

float uStepperEncoder::getAngleMoved ( bool  filtered = true)

Returns the angle moved from reference position in degrees.

        This function returns the angle moved from the shaft
        reference position. When the uStepper S is first powered on,
        the reference position is reset to the current shaft
        position, meaning that this function will return the angle
        rotated with respect to the angle the motor initially had. It
        should be noted that this function is absolute to an
        arbitrary number of revolutions !

        The reference position can be reset at any point in time, by
        use of the setHome() function.
Parameters
[in]filtered- if true, the function returns the filtered angle. if false, the unfiltered angle is returned
Returns
The angle moved in degrees.

Definition at line 182 of file uStepperEncoder.cpp.

Here is the caller graph for this function:

◆ getAngleMovedRaw()

int32_t uStepperEncoder::getAngleMovedRaw ( bool  filtered = true)

Returns the angle moved from reference position in raw encoder readings.

        This function returns the angle moved from the shaft
        reference position. When the uStepper S is first powered on,
        the reference position is reset to the current shaft
        position, meaning that this function will return the angle
        rotated with respect to the angle the motor initially had. It
        should be noted that this function is absolute to an
        arbitrary number of revolutions !

        The reference position can be reset at any point in time, by
        use of the setHome() function.
Parameters
[in]filtered- if true, the function returns the filtered angle. if false, the unfiltered angle is returned
Returns
The angle moved in raw encoder readings.

Definition at line 196 of file uStepperEncoder.cpp.

◆ getAngleRaw()

uint16_t uStepperEncoder::getAngleRaw ( void  )

Return the current shaft angle in raw encoder readings.

            This function returns the last captured shaft angle, as 
        output directly from the encoder.
            The resolution of the angle returned by this function is
            16 bits
Returns
raw 16 bit encoder representation of the current motor shaft angle

Definition at line 176 of file uStepperEncoder.cpp.

◆ getRPM()

float uStepperEncoder::getRPM ( void  )

Measure the current speed of the motor.

        This function returns the current speed of the motor. The
        speed is not calculated in this function, it is merely
        returning a variable. The speed is calculated in the
        interrupt routine associated with timer1.
Returns
Current speed in RPM

Definition at line 221 of file uStepperEncoder.cpp.

◆ getSpeed()

float uStepperEncoder::getSpeed ( void  )

Measure the current speed of the motor.

        This function returns the current speed of the motor. The
        speed is not calculated in this function, it is merely
        returning a variable. The speed is calculated in the
        interrupt routine associated with timer1.
Returns
Current speed in 1/256th steps per second

Definition at line 216 of file uStepperEncoder.cpp.

◆ getStatus()

uint8_t uStepperEncoder::getStatus ( void  )

Get encoder status.

        This function reads the current status of the encoder 
Returns
Current status register content

Definition at line 211 of file uStepperEncoder.cpp.

Here is the caller graph for this function:

◆ init()

void uStepperEncoder::init ( uStepperS _pointer)

Initiation of the encoder.

        This function initiates all the registers of the encoder.
Parameters
[in]_pointer- reference to the uStepper S object

Definition at line 48 of file uStepperEncoder.cpp.

Here is the caller graph for this function:

◆ setHome()

void uStepperEncoder::setHome ( float  initialAngle = 0)

Define new reference(home) position.

        This function redefines the reference position to the current
        angle of the shaft

@param[in]  initialAngle - Home position offset from zero

Definition at line 80 of file uStepperEncoder.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ angle

volatile uint16_t uStepperEncoder::angle

This variable always contain the current rotor angle, relative to a single revolution

Definition at line 207 of file uStepperEncoder.h.

◆ angleMoved

volatile int32_t uStepperEncoder::angleMoved

Variable used to store that measured angle moved from the reference position

Definition at line 211 of file uStepperEncoder.h.

◆ angleMovedRaw

volatile int32_t uStepperEncoder::angleMovedRaw = 0
private

Definition at line 246 of file uStepperEncoder.h.

◆ Beta

volatile uint8_t uStepperEncoder::Beta = 5

Filter constant for encoder feedback

Definition at line 228 of file uStepperEncoder.h.

◆ curSpeed

volatile float uStepperEncoder::curSpeed

Variable used to store the last measured rotational speed of the motor shaft

Definition at line 222 of file uStepperEncoder.h.

◆ encoderFilter

volatile posFilter_t uStepperEncoder::encoderFilter

Object to hold speed filter

Definition at line 225 of file uStepperEncoder.h.

◆ encoderOffset

volatile uint16_t uStepperEncoder::encoderOffset

Angle of the shaft at the reference position.

Definition at line 203 of file uStepperEncoder.h.

◆ oldAngle

volatile uint16_t uStepperEncoder::oldAngle

Used to stored the previous measured angle for the speed measurement, and the calculation of angle moved from reference position

Definition at line 217 of file uStepperEncoder.h.

◆ pointer

uStepperS* uStepperEncoder::pointer
private

Reference to the main object

Definition at line 233 of file uStepperEncoder.h.

◆ smoothValue

volatile int32_t uStepperEncoder::smoothValue

variable used for filtering the encoder readings

Definition at line 197 of file uStepperEncoder.h.

◆ speedSmoothValue

volatile float uStepperEncoder::speedSmoothValue

variable used for filtering the encoder speed estimation

Definition at line 200 of file uStepperEncoder.h.

◆ status

uint8_t uStepperEncoder::status
private

Status bits from the encoder

Definition at line 243 of file uStepperEncoder.h.

◆ userAngleOffset

int32_t uStepperEncoder::userAngleOffset = 0
private

Definition at line 244 of file uStepperEncoder.h.


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