Skip to content

Instantly share code, notes, and snippets.

@alex81632
Last active September 22, 2018 20:32
Show Gist options
  • Save alex81632/0747877fb4a7c2cc6f65820f134d632f to your computer and use it in GitHub Desktop.
Save alex81632/0747877fb4a7c2cc6f65820f134d632f to your computer and use it in GitHub Desktop.
void PID_SegueLinha(){
int error = Estado_Atual() - setPoint;
I+=error;
int motorSpeed = KP * error + KD * (error - lastError) + KI*I;
lastError=error;
int m1Speed = M1 + motorSpeed;
int m2Speed = M2 - motorSpeed;
if (m1Speed < 0) m1Speed = 0; // Determina o limite inferior
if (m2Speed < 0) m2Speed = 0; // Determina o limite inferior
if (m1Speed > MMAX) m1Speed = MMAX; // Determina o limite superior
if (m2Speed > MMAX) m2Speed = MMAX; // Determina o limite superior
Motor1(m1Speed);
Motor2(m2Speed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment