From d5f2bff53c2238c687fa1641243d618471c7ad5f Mon Sep 17 00:00:00 2001 From: Andru Liu <90433630+WallabyLester@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:21:19 -0700 Subject: [PATCH] Adding comments to implementation file. --- CPP_Implementation/apid_controller.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CPP_Implementation/apid_controller.cpp b/CPP_Implementation/apid_controller.cpp index a61ecb8..e520e79 100644 --- a/CPP_Implementation/apid_controller.cpp +++ b/CPP_Implementation/apid_controller.cpp @@ -1,10 +1,17 @@ #include "apid_controller.h" +/** + * @brief Constructor to initialize PID gains and time step. + */ aPIDController::aPIDController(double kp, double ki, double kd, double dt) : Kp(kp), Ki(ki), Kd(kd), dt(dt), integral(0.0), prev_err(0.0) {} +/** + * @brief Update the PID output based on the target and measured value. + */ double aPIDController::update(double target, double measured_value) { - double error = target - measured_value; + double error = target - measured_value; + integral += error * dt; double derivative = (error - prev_err) / dt; prev_err = error;