Skip to content

Instantly share code, notes, and snippets.

@evgeniyp
Created January 22, 2016 19:35
Show Gist options
  • Save evgeniyp/7fced36573932723443d to your computer and use it in GitHub Desktop.
Save evgeniyp/7fced36573932723443d to your computer and use it in GitHub Desktop.
float KP = 300, KI = 15, KD = 600;
float pTerm = 0, iTerm = 0, dTerm = 0;
float last_pitch = 0;
void loop()
{
float pitch = get_pitch(); // угол отклонения от вертикальной оси
pTerm = KP * pitch;
iTerm = KI * pitch + iTerm;
dTerm = KD * (pitch - last_pitch);
last_pitch = pitch;
float spd = pTerm + iTerm + dTerm;
set_motors(-spd, -spd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment