R2R
Macros | Functions | Variables
Encoder.c File Reference

Encoder source code. More...

#include "r2r.h"
#include "Encoder.h"

Macros

#define NUM_SSI_DATA2   5
 

Functions

void encoderSPIInit (void)
 Initializes the SPI channels for the motor drivers, encoders, and RAM. More...
 
void encoderRead (void)
 Updates value in sensor array. More...
 
void zeroMotor1RawRelative (void)
 Reads value of motor 1 encoders and sets the relative angle to zero. More...
 
void zeroMotor2RawRelative (void)
 Reads value of motor 2 encoders and sets the relative angle to zero. More...
 
void resetMotor1RawRelative (void)
 Resets the relative counts on encoder 1. More...
 
void resetMotor2RawRelative (void)
 Resets the relative counts on encoder 2. More...
 
int readMotor1RawRelative (void)
 Reads value in encoderVal array for motor 1 and keeps track of multiturn counts. More...
 
int readMotor2RawRelative (void)
 Reads value in encoderVal array for motor 2 and keeps track of multiturn counts. More...
 
float readMotor2Speed (void)
 
float readMotor1Speed (void)
 
float readMotor1AngleRelative (void)
 Reads value in encoderVal array for motor 1 and keeps track of multiturn angles. More...
 
float readMotor2AngleRelative (void)
 Reads value in encoderVal array for motor 2 and keeps track of multiturn angles. More...
 
float readMotor1RadRelative (void)
 
float readMotor2RadRelative (void)
 
int readMotor2Raw (void)
 Reads value in encoderVal array for motor 2. More...
 
int readMotor1Raw (void)
 Reads value in encoderVal array for motor 1. More...
 
float readMotor1Angle (void)
 Reads value in encoderVal array for motor 1 and converts it to an angle. More...
 
float readMotor2Angle (void)
 Reads value in encoderVal array for motor 2 and converts it to an angle. More...
 
float readMotor1Rad (void)
 
float readMotor2Rad (void)
 

Variables

uint32_t pui32DataTx2 [NUM_SSI_DATA2]
 
uint32_t pui32DataRx2 [NUM_SSI_DATA2]
 
uint32_t ui32Index2
 
uint32_t encoderVal [4]
 
int modifier1 =0
 
int last_motor_1_angle = 0
 
int modifier2 =0
 
int last_motor_2_angle = 0
 
int zeroing1 = 0
 
int zeroing2 = 0
 

Detailed Description

Encoder source code.

This file contains functions for initializing and reading from encoders.

Author
Benjamen Lim
Huan Weng
Blake Strebel

Function Documentation

◆ encoderRead()

void encoderRead ( void  )

Updates value in sensor array.

This function reads both encoder counts and stores them in an array

Comes after: spiInit();

Writes to: encoderVal array

◆ encoderSPIInit()

void encoderSPIInit ( void  )

Initializes the SPI channels for the motor drivers, encoders, and RAM.

Initializes SSI1 ~ 4 and their corresponding GPIO pins

Parameters
Void
Returns
Void

◆ readMotor1Angle()

float readMotor1Angle ( void  )

Reads value in encoderVal array for motor 1 and converts it to an angle.

Parameters
Void
Returns
The angle as a float

◆ readMotor1AngleRelative()

float readMotor1AngleRelative ( void  )

Reads value in encoderVal array for motor 1 and keeps track of multiturn angles.

This function reads out the angle and keeps track of it for multiple turns.

Parameters
Void
Returns
The angle as an int

◆ readMotor1Raw()

int readMotor1Raw ( void  )

Reads value in encoderVal array for motor 1.

The range for the read angle is 0 to 16383

Parameters
Void
Returns
The angle as an int

◆ readMotor1RawRelative()

int readMotor1RawRelative ( void  )

Reads value in encoderVal array for motor 1 and keeps track of multiturn counts.

This function reads out the angle and keeps track of it for multiple turns. The value ranges from -2,147,483,648 to 2,147,483,648. Each turn is 16383 counts

Parameters
Void
Returns
The counts as an int

◆ readMotor2Angle()

float readMotor2Angle ( void  )

Reads value in encoderVal array for motor 2 and converts it to an angle.

Parameters
Void
Returns
The angle as a float

◆ readMotor2AngleRelative()

float readMotor2AngleRelative ( void  )

Reads value in encoderVal array for motor 2 and keeps track of multiturn angles.

This function reads out the angle and keeps track of it for multiple turns.

Parameters
Void
Returns
The angle as an int

◆ readMotor2Raw()

int readMotor2Raw ( void  )

Reads value in encoderVal array for motor 2.

The range for the read angle is 0 to 16383

Parameters
Void
Returns
The angle as an int

◆ readMotor2RawRelative()

int readMotor2RawRelative ( void  )

Reads value in encoderVal array for motor 2 and keeps track of multiturn counts.

This function reads out the angle and keeps track of it for multiple turns. The value ranges from -2,147,483,648 to 2,147,483,648

Parameters
Void
Returns
The counts as an int

◆ resetMotor1RawRelative()

void resetMotor1RawRelative ( void  )

Resets the relative counts on encoder 1.

Parameters
Void
Returns
Void

◆ resetMotor2RawRelative()

void resetMotor2RawRelative ( void  )

Resets the relative counts on encoder 2.

Parameters
Void
Returns
Void

◆ zeroMotor1RawRelative()

void zeroMotor1RawRelative ( void  )

Reads value of motor 1 encoders and sets the relative angle to zero.

Parameters
Void
Returns
Void

◆ zeroMotor2RawRelative()

void zeroMotor2RawRelative ( void  )

Reads value of motor 2 encoders and sets the relative angle to zero.

Parameters
Void
Returns
The angle as a float