diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fa3c2b..89dae27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) # Declare a C++ library add_library(${PROJECT_NAME} - src/controllers/pid_controller.cpp src/controllers/pi_controller.cpp src/math/functions.cpp src/math/foc.cpp @@ -28,10 +27,6 @@ add_executable(pi_test tests/pi_test.cpp) target_link_libraries(pi_test ${PROJECT_NAME}) add_test(NAME pi_test COMMAND "${CMAKE_SOURCE_DIR}/bin/pi_test") -add_executable(pid_test tests/pid_test.cpp) -target_link_libraries(pid_test ${PROJECT_NAME}) -add_test(NAME pid_test COMMAND "${CMAKE_SOURCE_DIR}/bin/pid_test") - add_executable(bemf_observer_test tests/bemf_observer_test.cpp) target_link_libraries(bemf_observer_test ${PROJECT_NAME}) add_test(NAME bemf_observer_test COMMAND "${CMAKE_SOURCE_DIR}/bin/bemf_observer_test") diff --git a/include/controllers/pid_controller.hpp b/include/controllers/pid_controller.hpp deleted file mode 100644 index ae8620c..0000000 --- a/include/controllers/pid_controller.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -namespace controllers -{ - -struct pid_config -{ - float Kp, Ki, Kd, Ts, upper_limit, lower_limit; -}; - -class pid_controller -{ - float error_sum, output, error_prev; - float reset(float input, float output, float upper_limit, float lower_limit); - float clamp(float input, float upper_limit, float lower_limit); - -public: - pid_controller(); - float loop(float error, const pid_config& config, float external_integral = 0, bool reset_integral = false); -}; -} // namespace controllers diff --git a/src/controllers/pid_controller.cpp b/src/controllers/pid_controller.cpp deleted file mode 100644 index d45d366..0000000 --- a/src/controllers/pid_controller.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include - -controllers::pid_controller::pid_controller() : error_sum(0), output(0), error_prev(0) -{ -} - -float controllers::pid_controller::clamp(float input, float upper_limit, float lower_limit) -{ - if (input < lower_limit) - return lower_limit; - else if (input > upper_limit) - return upper_limit; - else - return input; -} - -float controllers::pid_controller::reset(float input, float output, float upper_limit, float lower_limit) -{ - if (input > 0 && output >= upper_limit) - return 0; - else if (input < 0 && output <= lower_limit) - return 0; - else - return input; -} - -float controllers::pid_controller::loop(float error, const pid_config& config, float external_integral, bool reset_integral) -{ - if (error > 0 && output >= config.upper_limit) - error = 0; - else if (error < 0 && output <= config.lower_limit) - error = 0; - - error_sum += config.Ki * config.Ts * (error + error_prev) / 2; - if (reset_integral) - error_sum = external_integral; - error_sum = clamp(error_sum, config.upper_limit, config.lower_limit); - float derror = (error - error_prev) / config.Ts; - output = - clamp(config.Kp * error + config.Ki * error_sum + config.Kd * derror, config.upper_limit, config.lower_limit); - - error_prev = error; - - return output; -} diff --git a/tests/pid_test.cpp b/tests/pid_test.cpp deleted file mode 100644 index a760f2d..0000000 --- a/tests/pid_test.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#define Ts 0.01 - -using namespace controllers; - -int main() -{ - float x_meas = 0, x_ref = 10; - pid_config config = { 2, 1, 0.01, Ts, 10, -10 }; - pid_controller controller; - std::cout << " Starting loop" << std::endl; - for (float t = 0; t < 10; t += Ts) - { - float error = x_ref - x_meas; - if(math::abs(error) < 0.1 && t>5) - break; - x_meas += Ts * controller.loop(error, config); - std::cout << "t = " << t << " x = " << x_meas << std::endl; - } -}