hi everyone..... i have a problem with my Quadcopter. PID problem to be exact....swings and tilts .... uff
I tell you what i did.... The codes below are to Compute the PID_Roll and to PID_Pitch....
double Compute_Pitch()
{
Pitch_Roll (); // Ottengo Pitch e Roll
unsigned long now = millis(); // comincia a contare
double timeChange = (double)(now - lastTime); // Delta t calcolato
double error_Pitch = SETPOINT - pitch; // Calcolo l'errore: Vorrei rimanere a 0.00°
if (abs(error_Pitch) < threshold){ // windup control
errSum += (error_Pitch * timeChange);} // Sommo l'errore attuale con i precedenti : sistema integrale
else {
errSum = 0;
}
double dErr = (error_Pitch - lastErr)/timeChange; // Rapporto incrementale del sistema derivativo
Output_Pitch = kpPitch * error_Pitch + kiPitch * errSum + kdPitch * dErr; // Calcolo il PID, dovrà essere in ingresso ai motori
if (Output_Pitch > VAL_MAX) Output_Pitch = VAL_MAX;
if (Output_Pitch < VAL_MIN) Output_Pitch= VAL_MIN;
lastErr = error_Pitch; // registro l'errore
lastTime = now; // registro il tempo
return Output_Pitch;
}
double Compute_Roll()
{
Pitch_Roll ();
unsigned long now = millis(); // comincia a contare
double timeChange = (double)(now - lastTime); // Delta t calcolato
double error_Roll = SETPOINT - roll; // Calcolo l'errore: Vorrei rimanere a 0.00°
if (abs(error_Roll) < threshold){ // windup control
errSum += (error_Roll * timeChange);} // Sommo l'errore attuale con i precedenti : sistema integrale
else {
errSum = 0;
}
double dErr = (error_Roll - lastErr)/timeChange; // Rapporto incrementale del sistema derivativo
Output_Roll = kp * error_Roll + ki *errSum + kd * dErr; // Calcolo il PID, dovrà essere in ingresso ai motori
if (Output_Roll > VAL_MAX) Output_Roll = VAL_MAX;
if (Output_Roll < VAL_MIN) Output_Roll = VAL_MIN;
lastErr = error_Roll; // registro l'errore
lastTime = now; // registro il tempo
return Output_Roll;
}
I tried any coefficent but nothing....the Quadcopter most of the time tilts or swings.This is the code to the motors:
v0 = (throttle - AccX + AccY - AccZ - PID_Pitch );
v1 = (throttle - AccX - AccY + AccZ - PID_Roll);
v2 = (throttle + AccX - AccY - AccZ + PID_Pitch );
v3 = (throttle + AccX + AccY + AccZ + PID_Roll );
motore0.write(v0);
motore1.write(v1);
motore2.write(v2);
motore3.write(v3);
exluding the Accx,Accy,Accz that are used to turn the QuadCopter......when i pull the throttle stick my drone swings very high ..... and many times it is overturned... The range of PWM (throttle range) is 90-120 and the limt value for PID is (-10, 10)...
Help me pls
thx in advance