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;
}