Adding comments to implementation file.

This commit is contained in:
Andru Liu
2024-10-08 20:21:19 -07:00
parent e8ad309831
commit d5f2bff53c
+8 -1
View File
@@ -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;