From 4398f661a7807431b3b86ba43832b4f41717302f Mon Sep 17 00:00:00 2001 From: Till Klocke Date: Thu, 27 May 2021 14:26:17 +0200 Subject: [PATCH 1/4] Added cmake component config for esp idf --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4e276ee --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "AutoPID.cpp" + INCLUDE_DIRS "." + REQUIRES esp_common) From 49bb717556573cc978a983713656e3df592ed0e1 Mon Sep 17 00:00:00 2001 From: Till Klocke Date: Thu, 27 May 2021 14:26:37 +0200 Subject: [PATCH 2/4] Replaced arduino specifc functions with esp idf functions --- AutoPID.cpp | 13 +++++++++++-- AutoPID.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/AutoPID.cpp b/AutoPID.cpp index 64a5f49..52d3738 100644 --- a/AutoPID.cpp +++ b/AutoPID.cpp @@ -1,4 +1,15 @@ +#ifndef ESP_PLATFORM #include "AutoPID.h" +#else +#include +#include "esp_timer.h" +#endif + +#ifdef ESP_PLATFORM +unsigned long millis() { + return (unsigned long)esp_timer_get_time()/1000; +} +#endif AutoPID::AutoPID(double *input, double *setpoint, double *output, double outputMin, double outputMax, double Kp, double Ki, double Kd) { @@ -100,5 +111,3 @@ void AutoPIDRelay::run() { double AutoPIDRelay::getPulseValue(){ return (isStopped()?0:_pulseValue); } - - diff --git a/AutoPID.h b/AutoPID.h index efe85f2..13b0d86 100644 --- a/AutoPID.h +++ b/AutoPID.h @@ -1,6 +1,8 @@ #ifndef AUTOPID_H #define AUTOPID_H +#ifndef ESP_PLATFORM #include +#endif class AutoPID { From 55436946e651a32f847f929c14167fdd34b9d565 Mon Sep 17 00:00:00 2001 From: Till Klocke Date: Thu, 27 May 2021 14:29:51 +0200 Subject: [PATCH 3/4] Accidentally excluded header file, fixed now --- AutoPID.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AutoPID.cpp b/AutoPID.cpp index 52d3738..cd68ec1 100644 --- a/AutoPID.cpp +++ b/AutoPID.cpp @@ -1,6 +1,5 @@ -#ifndef ESP_PLATFORM #include "AutoPID.h" -#else +#ifdef ESP_PLATFORM #include #include "esp_timer.h" #endif From d00adfaf43d0101770fb200aa3c57e7459b08f42 Mon Sep 17 00:00:00 2001 From: Till Klocke Date: Thu, 27 May 2021 14:33:38 +0200 Subject: [PATCH 4/4] Added replacement for constrain function --- AutoPID.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/AutoPID.cpp b/AutoPID.cpp index cd68ec1..94e2d87 100644 --- a/AutoPID.cpp +++ b/AutoPID.cpp @@ -8,6 +8,18 @@ unsigned long millis() { return (unsigned long)esp_timer_get_time()/1000; } + +template +const T& constrain(const T& x, const T& a, const T& b) { + if(x < a) { + return a; + } + else if(b < x) { + return b; + } + else + return x; +} #endif AutoPID::AutoPID(double *input, double *setpoint, double *output, double outputMin, double outputMax,