Smart Knob Controller

Class to interface with a 14-bit SPI-based rotary encoder. More...

#include <encoder.h>

Public Member Functions

 Encoder (SPI_HandleTypeDef *hspi, TIM_HandleTypeDef *htim, GPIO &CSn)
 Constructs an Encoder object.
void update ()
 Updates angle, position, and velocity.
int32_t getCommutationAngle ()
 Returns angle adjusted for motor commutation.
float getAngle ()
 Returns current angle in radians [0, 2π).
float getPosition ()
 Returns accumulated position in radians.
float getVelocity ()
 Returns estimated angular velocity in rad/s.
void zero ()
 Sets current angle as new zero reference.
void resetPosition ()
 Resets the multi-turn position to zero.
uint16_t readRawAngle ()
 Performs an SPI read to get raw encoder angle.

Public Attributes

uint16_t rawAngle

Detailed Description

Class to interface with a 14-bit SPI-based rotary encoder.

Constructor & Destructor Documentation

◆ Encoder()

Encoder::Encoder ( SPI_HandleTypeDef * hspi,
TIM_HandleTypeDef * htim,
GPIO & CSn )

Constructs an Encoder object.

Parameters
hspiPointer to the SPI interface.
htimPointer to the timer for timing velocity.
CSnGPIO object for chip select.

Member Function Documentation

◆ getAngle()

float Encoder::getAngle ( )

Returns current angle in radians [0, 2π).

Returns
Absolute angle in radians within one revolution.

◆ getCommutationAngle()

int32_t Encoder::getCommutationAngle ( )

Returns angle adjusted for motor commutation.

Returns
Angle in encoder ticks relative to commutation zero.

◆ getPosition()

float Encoder::getPosition ( )

Returns accumulated position in radians.

Returns
Multi-turn position in radians.

◆ getVelocity()

float Encoder::getVelocity ( )

Returns estimated angular velocity in rad/s.

Returns
Angular velocity in rad/s.

◆ readRawAngle()

uint16_t Encoder::readRawAngle ( )

Performs an SPI read to get raw encoder angle.

Returns
Raw 14-bit encoder angle.

The documentation for this class was generated from the following files:
  • C:/Users/nickl/OneDrive - Cal Poly/POLY4TH/SPRING'25/507/LAB WORKSPACE/SmartKnobController_REV2/Core/DoxCommd/encoder.h
  • C:/Users/nickl/OneDrive - Cal Poly/POLY4TH/SPRING'25/507/LAB WORKSPACE/SmartKnobController_REV2/Core/DoxCommd/encoder.cpp