View Single Post
  #1   Spotlight this post!  
Unread 13-03-2016, 15:42
teslalab2's Avatar
teslalab2 teslalab2 is offline
RogueBotix LLC
VRC #8091
Team Role: Mentor
 
Join Date: Feb 2015
Rookie Year: 2014
Location: Austin MN
Posts: 109
teslalab2 will become famous soon enoughteslalab2 will become famous soon enough
Re: Custom PI Loop not working

there really is no reason for an if statement in a PID! PID's in of their own aren't really that complicated, and if you start adding if statements and things like that it can only have the potential to cause problems. if you don't want to use the D component just don't give it a constant, If you want negative feedback,make the constant negative. here is the class I wrote last year in c++. Simplicity is king!

Code:
class myPID{
private:
double Kp,Ki,Kd;
double error, error1 = 0;
double integral;
float value;
public:
void Update(double,double);
float GetValue(void);
void SetConstants(double,double,double);
};

void myPID::Update(double target,double actual){
	error = target - actual;
	integral += error*.01; //todo add actualy eleapsed time
	value = (error*Kp) + (integral*Ki) + ((error-error1)/(.01)*Kd);
	error1 = error;
}
float myPID::GetValue(){
	return value;
}

void myPID::SetConstants(double Kp,double Ki,double Kd){
        this->Kp=Kp;
        this->Ki=Ki;
        this->Kd=Kd;
}
__________________
I need a jaguar development board for reprogramming a jaguars bootloader. if you have one that you want to sell, pm me. thanks

Run you CanJaguars on arduino with ArduRIO, you can also easily control Talons, Victors,Jaguars and Sparks on PWM. https://sourceforge.net/projects/ardurio/
Reply With Quote