R2R
Functions
PositionControl.c File Reference

control source code More...

#include "r2r.h"
#include "PositionControl.h"
#include "CurrentControl.h"
#include "Utilities.h"
#include "Encoder.h"
#include "Motor.h"
#include <math.h>

Functions

void MotorTimerInit (void)
 This function sets up the timer interrupt for position control. More...
 
void get_position_gains (void)
 Gets position gains on the Tiva microcontroller by reading to UART. More...
 
void set_position_gains (void)
 Sets position gains on the Tiva microcontroller by reading from UART. More...
 
void set_desired_angle (int angle, int motor)
 Sets desired angle for a given motor. More...
 
int get_desired_angle (int motor)
 Gets desired angle for a given motor. More...
 
void load_position_trajectory (int motor)
 Loads position trajectory for a given motor over UART. More...
 
void Timer1IntHandler (void)
 The interrupt handler for position control. More...
 
void PID_Controller (int reference, int actual, int motor)
 Calculates pwm to send to the motor drivr. More...
 
void reset_controller_error (void)
 Resets controller error on both controllers to be zero. More...
 
int decog_motor (int x, int motor)
 Motor decogging to smooth output of motor. More...
 
void setDecogging (void)
 Turn on/off decogging by setting global variable. More...
 

Detailed Description

control source code

This file contains the pwm functions

Author
Benjamen Lim
Huan Weng
Blake Strebel

Function Documentation

◆ decog_motor()

int decog_motor ( int  x,
int  motor 
)

Motor decogging to smooth output of motor.

Motor decogging function that smoothes out the output from the motor by adding a term to the control signal to compensate for the cogging in the BLDC motor. Equations are fit using PositionDataAnalyze.m MATLAB script.

Example:

u = u + decog_motor(current_Angle_Radians, MOTOR_1);
Parameters
xcurrent angle in counts
motorthe motor to decog
Returns
control signal modifier based on position

◆ get_desired_angle()

int get_desired_angle ( int  motor)

Gets desired angle for a given motor.

Parameters
motorreads the desired angle for the given motor
Returns
Void

◆ get_position_gains()

void get_position_gains ( void  )

Gets position gains on the Tiva microcontroller by reading to UART.

Parameters
Void
Returns
Void

◆ load_position_trajectory()

void load_position_trajectory ( int  motor)

Loads position trajectory for a given motor over UART.

Parameters
motorspecifies the trajectory that is being assigned from UART
Returns
Void

◆ MotorTimerInit()

void MotorTimerInit ( void  )

This function sets up the timer interrupt for position control.

Parameters
Void
Returns
Void

◆ PID_Controller()

void PID_Controller ( int  reference,
int  actual,
int  motor 
)

Calculates pwm to send to the motor drivr.

Parameters
referencethe reference angle
actualthe commanded angle
motorthe specified motor
Returns
Void

◆ reset_controller_error()

void reset_controller_error ( void  )

Resets controller error on both controllers to be zero.

Parameters
Void
Returns
Void

◆ set_desired_angle()

void set_desired_angle ( int  angle,
int  motor 
)

Sets desired angle for a given motor.

Parameters
motorspecifies the desired angle for the given motor
Returns
Void

◆ set_position_gains()

void set_position_gains ( void  )

Sets position gains on the Tiva microcontroller by reading from UART.

Parameters
Void
Returns
Void

◆ setDecogging()

void setDecogging ( void  )

Turn on/off decogging by setting global variable.

Parameters
void
Returns
Void

◆ Timer1IntHandler()

void Timer1IntHandler ( void  )

The interrupt handler for position control.

Parameters
Void
Returns
Void