Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. static long last_time; //Guardo valor tiempo entre llamadas
  2. static double last_error_p; //Guardo error de iteración anterior
  3. double error_p,error_d,error_i;
  4. unsigned long now=millis();
  5. double dt=now-last_time;
  6. error_p=referencia-contador; //Error proporcional
  7. error_d=(error_p-last_error_p)/dt; //Error derivativo
  8. error_i=error_i+error_p*dt; //Error integral
  9. salida=Kp*error_p+Ki*error_i+Kd*error_d; // Calculo salida
  10. last_error_p=error_p;
  11. last_time=now;
  12. // Saturación a máxima velocidad
  13. if (salida >max_vel) salida =maxvel
  14. else if(salida<-max_vel) salida=-maxvel;
  15. return(salida);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement