Sunday, December 5, 2010

PID Velocity Motor Controller Code Breakdown

In the previous PID Velocity Motor Controller post I discussed the project hardware and project goals. In this post I want to share some breakdown of the PID code as it stands today.

The following code examples are for Atmel AVR microprocessors using the gcc-avr compiler and tool chain.

Encoder Structure:
 typedef struct{    
   int direction;    // Encoder rotation direction.  
   int count;        // Encoder count.  
 } encoder, *pencoder;  
 encoder REncoder;  
 encoder LEncoder;  

Motor Structure:
typedef struct{  
   float kp;                // Proportional gain  
   float ki;                // Intigral gain  
   float kd;                // Dirivitive gain  
   float velocity_setpoint; // Motor velocity setpoint in encoder counts per control loop  
   float velocity;          // Motor velocity in encoder counts per control loop  
   float previous_error;    // Motor's previous proportional error  
   float integral_error;    // Motor's integral error  
 } motor, *pmotor;  
 motor RMotor;  
 motor LMotor;

Saturday, December 4, 2010

PID Velocity Motor Controller

Over the last few days I have been working on a simple PID velocity DC motor controller that will be my entry to the Trossen Robotics contest. While it is not a project that is new or novel I feel that documenting and sharing the creation of the full system from top to bottom better fits the contest's judging criteria.

This post will serve as an update on the progress I have made on the project thus far.

My setup for development consists of a MINI robocontroller from Vanadium Labs, DC Gearmotor from Pololu and wheels from BaneBots. The MINI robocontroller is simply being used as a convenience at the moment allowing me to focus on software rather then hardware. I will be replacing it with a custom PCB in the near future.

PID Controller Development Setup