diff --git a/andino_firmware/src/app.cpp b/andino_firmware/src/app.cpp index 33a26b4b..042a32c7 100644 --- a/andino_firmware/src/app.cpp +++ b/andino_firmware/src/app.cpp @@ -103,9 +103,9 @@ InterruptInArduino App::right_encoder_channel_b_interrupt_in_(Hw::kRightEncoderC Encoder App::right_encoder_(&right_encoder_channel_a_interrupt_in_, &right_encoder_channel_b_interrupt_in_); -PID App::left_pid_controller_(Constants::kPidKp, Constants::kPidKd, Constants::kPidKi, +Pid App::left_pid_controller_(Constants::kPidKp, Constants::kPidKd, Constants::kPidKi, Constants::kPidKo, -Constants::kPwmMax, Constants::kPwmMax); -PID App::right_pid_controller_(Constants::kPidKp, Constants::kPidKd, Constants::kPidKi, +Pid App::right_pid_controller_(Constants::kPidKp, Constants::kPidKd, Constants::kPidKi, Constants::kPidKo, -Constants::kPwmMax, Constants::kPwmMax); unsigned long App::last_pid_computation_{0}; diff --git a/andino_firmware/src/app.h b/andino_firmware/src/app.h index 062b9872..91633dc1 100644 --- a/andino_firmware/src/app.h +++ b/andino_firmware/src/app.h @@ -108,8 +108,8 @@ class App { static Encoder right_encoder_; /// PID controllers (one per wheel). - static PID left_pid_controller_; - static PID right_pid_controller_; + static Pid left_pid_controller_; + static Pid right_pid_controller_; /// Tracks the last time the PID computation was made. static unsigned long last_pid_computation_; diff --git a/andino_firmware/src/pid.cpp b/andino_firmware/src/pid.cpp index c89e1a3d..476b8f40 100644 --- a/andino_firmware/src/pid.cpp +++ b/andino_firmware/src/pid.cpp @@ -71,7 +71,7 @@ namespace andino { // - http://brettbeauregard.com/blog/2011/04/improving-the-beginner%E2%80%99s-pid-derivative-kick/ // - http://brettbeauregard.com/blog/2011/04/improving-the-beginner%E2%80%99s-pid-tuning-changes/ -void PID::reset(int encoder_count) { +void Pid::reset(int encoder_count) { // Since we can assume that the PID is only turned on when going from stop to moving, we can init // everything on zero. setpoint_ = 0; @@ -82,15 +82,15 @@ void PID::reset(int encoder_count) { } /// @brief Enable PID -void PID::enable() { enabled_ = true; } +void Pid::enable() { enabled_ = true; } /// @brief Is the PID controller enabled? -bool PID::enabled() { return enabled_; } +bool Pid::enabled() { return enabled_; } /// @brief Disable PID -void PID::disable() { enabled_ = false; } +void Pid::disable() { enabled_ = false; } -void PID::compute(int encoder_count, int& computed_output) { +void Pid::compute(int encoder_count, int& computed_output) { if (!enabled_) { // Reset PID once to prevent startup spikes. if (last_input_ != 0) { @@ -123,9 +123,9 @@ void PID::compute(int encoder_count, int& computed_output) { last_output_ = output; } -void PID::set_setpoint(int setpoint) { setpoint_ = setpoint; } +void Pid::set_setpoint(int setpoint) { setpoint_ = setpoint; } -void PID::set_tunings(int kp, int kd, int ki, int ko) { +void Pid::set_tunings(int kp, int kd, int ki, int ko) { kp_ = kp; kd_ = kd; ki_ = ki; diff --git a/andino_firmware/src/pid.h b/andino_firmware/src/pid.h index 71ab4999..1bc4ca5a 100644 --- a/andino_firmware/src/pid.h +++ b/andino_firmware/src/pid.h @@ -32,7 +32,7 @@ namespace andino { /// @brief This class provides a simple PID controller implementation. -class PID { +class Pid { public: /// @brief Constructs a new PID object. /// @@ -42,13 +42,8 @@ class PID { /// @param ko Tuning output gain. /// @param output_min Output minimum limit. /// @param output_max Output maximum limit. - PID(int kp, int kd, int ki, int ko, int output_min, int output_max) - : kp_(kp), - kd_(kd), - ki_(ki), - ko_(ko), - output_min_(output_min), - output_max_(output_max) {} + Pid(int kp, int kd, int ki, int ko, int output_min, int output_max) + : kp_(kp), kd_(kd), ki_(ki), ko_(ko), output_min_(output_min), output_max_(output_max) {} /// @brief Resets the PID controller. /// diff --git a/andino_firmware/test/desktop/test_pid/pid_test.cpp b/andino_firmware/test/desktop/test_pid/pid_test.cpp index d2bd7c7f..1cc4ca3d 100644 --- a/andino_firmware/test/desktop/test_pid/pid_test.cpp +++ b/andino_firmware/test/desktop/test_pid/pid_test.cpp @@ -36,7 +36,7 @@ namespace test { namespace { TEST(PidTest, Initialize) { - andino::PID pid_controller(1, 0, 0, 1, -100, 100); + andino::Pid pid_controller(1, 0, 0, 1, -100, 100); int output = 0; // Controller is disabled by default, so output variable should remain unchanged. @@ -45,7 +45,7 @@ TEST(PidTest, Initialize) { } TEST(PidTest, ComputeOutputProportionalGain) { - andino::PID pid_controller(3, 0, 0, 1, -100, 100); + andino::Pid pid_controller(3, 0, 0, 1, -100, 100); int output = 0; pid_controller.set_setpoint(15); pid_controller.enable(); @@ -58,7 +58,7 @@ TEST(PidTest, ComputeOutputProportionalGain) { } TEST(PidTest, ComputeOutputProportionalAndDerivativeGain) { - andino::PID pid_controller(3, 2, 0, 1, -100, 100); + andino::Pid pid_controller(3, 2, 0, 1, -100, 100); int output = 0; pid_controller.set_setpoint(15); pid_controller.enable(); @@ -71,7 +71,7 @@ TEST(PidTest, ComputeOutputProportionalAndDerivativeGain) { } TEST(PidTest, ComputeOutputProportionalAndIntegralGain) { - andino::PID pid_controller(3, 0, 1, 1, -100, 100); + andino::Pid pid_controller(3, 0, 1, 1, -100, 100); int output = 0; pid_controller.set_setpoint(15); pid_controller.enable(); @@ -84,7 +84,7 @@ TEST(PidTest, ComputeOutputProportionalAndIntegralGain) { } TEST(PidTest, ComputeOutputProportionalDerivativeAndIntegralGain) { - andino::PID pid_controller(3, 2, 1, 1, -100, 100); + andino::Pid pid_controller(3, 2, 1, 1, -100, 100); int output = 0; pid_controller.set_setpoint(15); pid_controller.enable(); @@ -97,7 +97,7 @@ TEST(PidTest, ComputeOutputProportionalDerivativeAndIntegralGain) { } TEST(PidTest, Reset) { - andino::PID pid_controller(3, 0, 0, 1, -100, 100); + andino::Pid pid_controller(3, 0, 0, 1, -100, 100); int output = 0; pid_controller.set_setpoint(15); pid_controller.enable(); @@ -113,7 +113,7 @@ TEST(PidTest, Reset) { } TEST(PidTest, SetTunings) { - andino::PID pid_controller(3, 0, 0, 1, -100, 100); + andino::Pid pid_controller(3, 0, 0, 1, -100, 100); int output = 0; pid_controller.set_setpoint(15); pid_controller.enable();