View Single Post
  #1   Spotlight this post!  
Unread 10-12-2007, 10:57
3DWolf's Avatar
3DWolf 3DWolf is offline
Boots - Head Programmer / 3D
AKA: Jake
FRC #1502 (Technical Difficulties)
Team Role: Programmer
 
Join Date: Dec 2006
Rookie Year: 2005
Location: Chelsea Michigan
Posts: 97
3DWolf is on a distinguished road
Send a message via AIM to 3DWolf Send a message via MSN to 3DWolf
PID vs Normal loops

One of my mentors assigned me a project for off season so we could get some better arm controllage going on, and he said to use a PID loop.

I'm still fairly new to C++ so bear with me.

While I know little to nothing on Integrals and Derivatives, this is confusing to me. I understand that PID loops are used to narrow things from point A to point B without overshooting or gyrating while going as fast as possible.

I found some old PID code for our drive system last year, but I can't really make heads or tails of it.

And all the while, I don't really see a need for all that math, couldn't you do something such as
Code:
#include <math.h>

#define p1 = pwm01; //Pot 1
#define p2 = pwm02; //Pot 2
#define dvr = pwm03; //Motor

int dist;
void Correct();
int Clamp(int var, int lBound, int mBound);

void Correct(){
	if (!p1 == p2){
		while (p1 > p2){
			dist = Abs(p1 - p2);
			dvr = 127 + Clamp(dist, 127, 255);
		}
		while (p1 < p2){
			dist = Abs(p1 - p2);
			dvr = 127 - Clamp(dist, 0, 127);
		}
	}
}

int Clamp(int var, int lBound, int mBound){
	if (var < lBound)
		return lBound;
	if (var > mBound)
		return mBound;
	else
		return var;
}
__________________
You can call it the programming teams fault, but we'll just force your arguments nil.

There are 10 kinds of people in the world -> Those who understand binary and those who don't.

WYSIWYG - In FIRST: Greatness