diff --git a/pid_from_msl.cpp b/pid_from_msl.cpp index f294f0a..adb8a81 100644 --- a/pid_from_msl.cpp +++ b/pid_from_msl.cpp @@ -59,6 +59,10 @@ public: } curIdx++; } else if (j == outputIdx) { + /*const float alpha = 0.5f; + float fv = alpha * prevV + (1.0f - alpha) * (float)v; + prevV = v; + data.push_back(fv);*/ data.push_back((float)v); } } @@ -69,9 +73,10 @@ public: std::vector data; double minValue = 0, maxValue = 0, stepPoint = -1.0, maxPoint = 0; int curIdx = -1; + float prevV = 0; }; -#if 0 +#if 1 int main(int argc, char **argv) { if (argc < 6) { printf("Usage: PID_FROM_MSL file.msl start_time end_time input_column output_column...\r\n"); @@ -85,7 +90,8 @@ int main(int argc, char **argv) { return -2; } - printf("PID_FROM_MSL: Calculating...\r\n"); + printf("PID_FROM_MSL: minValue=%g maxValue=%g stepPoint=%g maxPoint=%g Calculating...\r\n", + data.minValue, data.maxValue, data.stepPoint, data.maxPoint); PidAutoTuneChrSopdt chr; double params0[4]; @@ -100,8 +106,6 @@ int main(int argc, char **argv) { chr.addData(data.data[i]); } - double stepPoint = 178; // todo: adjust for the buffer scale - double maxPoint = 460; chr.findPid(PID_TUNE_CHR2, data.minValue, data.maxValue, data.stepPoint, data.maxPoint, params0); printf("Done!\r\n"); @@ -111,6 +115,10 @@ int main(int argc, char **argv) { const pid_s & pid = chr.getPid(); printf("PID: P=%f I=%f D=%f offset=%f\r\n", pid.pFactor, pid.iFactor, pid.dFactor, pid.offset); + // todo: is it correct? + double dTime = 1; + PidAccuracyMetric metric = PidAutoTuneChrSopdt::simulatePid<2048>(chr.getAvgMeasuredMin(), chr.getAvgMeasuredMax(), dTime, pid, p); + printf("Metric result: ITAE=%g ISE=%g Overshoot=%g%%\r\n", metric.getItae(), metric.getIse(), metric.getMaxOvershoot() * 100.0); return 0; } diff --git a/pid_functions.h b/pid_functions.h index ec55655..a1c6391 100644 --- a/pid_functions.h +++ b/pid_functions.h @@ -28,7 +28,7 @@ enum { }; -static const double minParamValue = 0.01; +static const double minParamValue = 0.0001; class InputFunction { public: diff --git a/pid_open_loop_models.h b/pid_open_loop_models.h index f59c853..b20e22a 100644 Binary files a/pid_open_loop_models.h and b/pid_open_loop_models.h differ diff --git a/test_chs_pid.cpp b/test_chs_pid.cpp index ab4e938..561b6cb 100644 --- a/test_chs_pid.cpp +++ b/test_chs_pid.cpp @@ -122,9 +122,9 @@ TEST(pidAutoTune, testPidCoefs) { params[PARAM_L] = 1.52685; // todo: is it correct? - double dTime = 2; + double dTime = 1; for (int idx = 0; idx <= 4; idx++) { - PidAccuracyMetric metric = PidAutoTuneChrSopdt::simulatePid<1024>(13.0, 16.0, dTime, pidParams[idx], params); + PidAccuracyMetric metric = PidAutoTuneChrSopdt::simulatePid<2048>(13.0, 14.0, dTime, pidParams[idx], params); #ifdef PID_DEBUG printf("Metric result: ITAE=%g ISE=%g Overshoot=%g%%\r\n", metric.getItae(), metric.getIse(), metric.getMaxOvershoot() * 100.0); #endif @@ -133,7 +133,7 @@ TEST(pidAutoTune, testPidCoefs) { // todo: check results } -#if 1 +#if 0 GTEST_API_ int main(int argc, char **argv) { //testPidCoefs(); @@ -148,7 +148,7 @@ GTEST_API_ int main(int argc, char **argv) { testSOPDTOverdamped(); testChsSopdtPid(); #endif - //::testing::GTEST_FLAG(filter) = "*testPidCoefs*"; + ::testing::GTEST_FLAG(filter) = "*testPidCoefs*"; int result = RUN_ALL_TESTS(); // windows ERRORLEVEL in Jenkins batch file seems to want negative value to detect failure return result == 0 ? 0 : -1;