Autonomous Racing  1
f1tenth Project Group of Technical University Dortmund, Germany
pid_controller.cpp
Go to the documentation of this file.
1 #include "pid_controller.h"
2 
3 PIDController::PIDController(float p, float i, float d)
4  : m_p{ p }
5  , m_i{ i }
6  , m_d{ d }
7  , m_previous_error{ 0 }
8  , m_integral{ 0 }
9 {
10 }
11 
12 float PIDController::updateAndGetCorrection(float error, float deltaTime)
13 {
14  this->m_integral += error * deltaTime;
15  float derivative = (error - this->m_previous_error) / deltaTime;
16  this->m_previous_error = error;
17 
18  return this->m_p * error + this->m_i * this->m_integral + this->m_d * derivative;
19 }
float updateAndGetCorrection(float error, float deltaTime)
PIDController(float p, float i, float d)