uStepper S
|
Prototype of class for the AEAT8800-Q24 encoder. More...
#include <uStepperEncoder.h>
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 | |
uStepperS * | pointer |
uint8_t | status |
int32_t | userAngleOffset = 0 |
volatile int32_t | angleMovedRaw = 0 |
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.
uStepperEncoder::uStepperEncoder | ( | void | ) |
Constructor of uStepperEncoder class.
Definition at line 34 of file uStepperEncoder.cpp.
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.
Definition at line 115 of file uStepperEncoder.cpp.
|
private |
Set the output level of the chip select pin.
[in] | state | - 1 = High, 0 = low |
Definition at line 226 of file uStepperEncoder.cpp.
bool uStepperEncoder::detectMagnet | ( | void | ) |
detect magnet
This function reads the current status of the encoder with regards to placement of the magnet.
Definition at line 99 of file uStepperEncoder.cpp.
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)
Definition at line 171 of file uStepperEncoder.cpp.
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.
[in] | filtered | - if true, the function returns the filtered angle. if false, the unfiltered angle is returned |
Definition at line 182 of file uStepperEncoder.cpp.
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.
[in] | filtered | - if true, the function returns the filtered angle. if false, the unfiltered angle is returned |
Definition at line 196 of file uStepperEncoder.cpp.
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
Definition at line 176 of file uStepperEncoder.cpp.
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.
Definition at line 221 of file uStepperEncoder.cpp.
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.
Definition at line 216 of file uStepperEncoder.cpp.
uint8_t uStepperEncoder::getStatus | ( | void | ) |
Get encoder status.
This function reads the current status of the encoder
Definition at line 211 of file uStepperEncoder.cpp.
void uStepperEncoder::init | ( | uStepperS * | _pointer | ) |
Initiation of the encoder.
This function initiates all the registers of the encoder.
[in] | _pointer | - reference to the uStepper S object |
Definition at line 48 of file uStepperEncoder.cpp.
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.
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.
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.
|
private |
Definition at line 246 of file uStepperEncoder.h.
volatile uint8_t uStepperEncoder::Beta = 5 |
Filter constant for encoder feedback
Definition at line 228 of file uStepperEncoder.h.
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.
volatile posFilter_t uStepperEncoder::encoderFilter |
Object to hold speed filter
Definition at line 225 of file uStepperEncoder.h.
volatile uint16_t uStepperEncoder::encoderOffset |
Angle of the shaft at the reference position.
Definition at line 203 of file uStepperEncoder.h.
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.
|
private |
Reference to the main object
Definition at line 233 of file uStepperEncoder.h.
volatile int32_t uStepperEncoder::smoothValue |
variable used for filtering the encoder readings
Definition at line 197 of file uStepperEncoder.h.
volatile float uStepperEncoder::speedSmoothValue |
variable used for filtering the encoder speed estimation
Definition at line 200 of file uStepperEncoder.h.
|
private |
Status bits from the encoder
Definition at line 243 of file uStepperEncoder.h.
|
private |
Definition at line 244 of file uStepperEncoder.h.