From f12599405a2988514627fcd1ef4df9f6eaddaf51 Mon Sep 17 00:00:00 2001 From: riggja Date: Wed, 14 Oct 2020 13:31:05 -0800 Subject: [PATCH 1/4] add arduino-ci support --- .arduino-ci.yml | 25 +++++++++++++++++++++++++ .bundle/config | 2 ++ .gitignore | 5 +++++ Gemfile | 2 ++ PID_v1.cpp => src/PID_v1.cpp | 0 PID_v1.h => src/PID_v1.h | 0 test/test.cpp | 6 ++++++ 7 files changed, 40 insertions(+) create mode 100644 .arduino-ci.yml create mode 100644 .bundle/config create mode 100644 .gitignore create mode 100644 Gemfile rename PID_v1.cpp => src/PID_v1.cpp (100%) rename PID_v1.h => src/PID_v1.h (100%) create mode 100644 test/test.cpp diff --git a/.arduino-ci.yml b/.arduino-ci.yml new file mode 100644 index 0000000..8a095a8 --- /dev/null +++ b/.arduino-ci.yml @@ -0,0 +1,25 @@ +# https://github.com/Arduino-CI/arduino_ci/issues/159 +# copied from vendor/bundle/ruby/2.6.0/gems/arduino_ci-0.3.0/misc/default.yml +platforms: + mega2560: + board: arduino:avr:mega:cpu=atmega2560 + package: arduino:avr + gcc: + features: + defines: + - __AVR_ATmega2560__ + # added this line + - ARDUINO_CI + warnings: + flags: + +unittest: + platforms: + - mega2560 + testfiles: + reject: + - "Common.cpp" + +compile: + platforms: + - mega2560 diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 0000000..2369228 --- /dev/null +++ b/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_PATH: "vendor/bundle" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd10d2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +Gemfile.lock +vendor +# C++ stuff +*.bin +*.bin.dSYM diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..fb422d1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'arduino_ci' diff --git a/PID_v1.cpp b/src/PID_v1.cpp similarity index 100% rename from PID_v1.cpp rename to src/PID_v1.cpp diff --git a/PID_v1.h b/src/PID_v1.h similarity index 100% rename from PID_v1.h rename to src/PID_v1.h diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..affab10 --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,6 @@ +#include "Arduino.h" +#include "ArduinoUnitTests.h" + +unittest(test) { assertTrue(true); } + +unittest_main() From 8aba508fcb11c426e0749ff2f817091ddbb717cc Mon Sep 17 00:00:00 2001 From: riggja Date: Wed, 14 Oct 2020 16:54:22 -0800 Subject: [PATCH 2/4] add tests for PID --- test/test.cpp | 148 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 1 deletion(-) diff --git a/test/test.cpp b/test/test.cpp index affab10..5ef18ac 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,6 +1,152 @@ #include "Arduino.h" #include "ArduinoUnitTests.h" +#include -unittest(test) { assertTrue(true); } +unittest(direct) { + + // Define Variables we'll be connecting to + double Setpoint, Input, Output; + + // Specify the links and initial tuning parameters + PID myPID(&Input, &Output, &Setpoint, 2, 5, 1, DIRECT); + + // initialize the variables we're linked to + Input = 50; + Setpoint = 100; + + // turn the PID on + myPID.SetMode(AUTOMATIC); + for (int i = 0; i < 1000; i++) { + delay(200); + if (myPID.Compute()) { + Input = Input + (Output - Input) / 25.6; + } + } + // std::cout << "Input = " << Input << "; Output = " << Output << std::endl; + assertEqual(Setpoint, round(Input)); +} + +unittest(reverse) { + + // Define Variables we'll be connecting to + double Setpoint, Input, Output; + + // Specify the links and initial tuning parameters + PID myPID(&Input, &Output, &Setpoint, 2, 5, 1, REVERSE); + + // initialize the variables we're linked to + Input = 50; + Setpoint = 100; + + // turn the PID on + myPID.SetMode(AUTOMATIC); + for (int i = 0; i < 1000; i++) { + delay(200); + if (myPID.Compute()) { + Input = Input + (Input - Output) / 25.6; + } + } + // std::cout << "Input = " << Input << "; Output = " << Output << std::endl; + assertEqual(Setpoint, round(Input)); +} + +unittest(mode) { + + // Define Variables we'll be connecting to + double Setpoint, Input, Output; + + // Specify the links and initial tuning parameters + PID myPID(&Input, &Output, &Setpoint, 2, 5, 1, REVERSE); + + // initialize the variables we're linked to + Input = 50; + Setpoint = 100; + + // turn the PID on + myPID.SetMode(MANUAL); + for (int i = 0; i < 1000; i++) { + delay(200); + if (myPID.Compute()) { + Input = Input + (Input - Output) / 25.6; + } + } + // std::cout << "Input = " << Input << "; Output = " << Output << std::endl; + assertEqual(50, round(Input)); +} + +unittest(getFunctions) { + + // Define Variables we'll be connecting to + double Setpoint, Input, Output; + + // Specify the links and initial tuning parameters + PID myPID(&Input, &Output, &Setpoint, 2, 5, 1, REVERSE); + + // initialize the variables we're linked to + Input = 50; + Setpoint = 100; + + // turn the PID on + myPID.SetMode(AUTOMATIC); + + // std::cout << "Input = " << Input << "; Output = " << Output << std::endl; + assertEqual(2, myPID.GetKp()); + assertEqual(5, myPID.GetKi()); + assertEqual(1, myPID.GetKd()); + assertEqual(REVERSE, myPID.GetDirection()); + assertEqual(AUTOMATIC, myPID.GetMode()); +} + +unittest(sampleTimeWorks) { + + // Define Variables we'll be connecting to + double Setpoint, Input, Output; + + // Specify the links and initial tuning parameters + PID myPID(&Input, &Output, &Setpoint, 2, 5, 1, REVERSE); + + // initialize the variables we're linked to + Input = 50; + Setpoint = 100; + + bool flag = false; + // turn the PID on + myPID.SetMode(AUTOMATIC); + for (int i = 0; i < 1000; i++) { + delay(200); + if (myPID.Compute()) { + flag = true; + Input = Input + (Input - Output) / 25.6; + } + } + // std::cout << "Input = " << Input << "; Output = " << Output << std::endl; + assertTrue(flag); +} + +unittest(sampleTimeNotWorks) { + + // Define Variables we'll be connecting to + double Setpoint, Input, Output; + + // Specify the links and initial tuning parameters + PID myPID(&Input, &Output, &Setpoint, 2, 5, 1, REVERSE); + + // initialize the variables we're linked to + Input = 50; + Setpoint = 100; + + bool flag = false; + // turn the PID on + myPID.SetMode(MANUAL); + for (int i = 0; i < 1000; i++) { + delay(199); + if (myPID.Compute()) { + flag = true; + Input = Input + (Input - Output) / 25.6; + } + } + // std::cout << "Input = " << Input << "; Output = " << Output << std::endl; + assertFalse(flag); +} unittest_main() From f6534670ad9b27af5b5285eaa9c2e37f9e3d3332 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 18 Oct 2020 17:54:11 -0700 Subject: [PATCH 3/4] Update .gitignore to add .bundle --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bd10d2f..db7e8b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.bundle Gemfile.lock vendor # C++ stuff From 59e5fb22a9384b99140b04aff1fe023e235758ad Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 18 Oct 2020 17:54:42 -0700 Subject: [PATCH 4/4] Delete .bundle/config This should have been ignored. --- .bundle/config | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .bundle/config diff --git a/.bundle/config b/.bundle/config deleted file mode 100644 index 2369228..0000000 --- a/.bundle/config +++ /dev/null @@ -1,2 +0,0 @@ ---- -BUNDLE_PATH: "vendor/bundle"