From 2ec448283444d3cdda693e2e1784cc02b170581c Mon Sep 17 00:00:00 2001 From: Ta180m Date: Thu, 5 Mar 2020 15:44:00 -0600 Subject: Updated some stuff --- Detector_Building_v2/Detector_Building_v2.ino | 30 ++++++++++++---------- .../detectorBuilding/src/detectorBuilding.cpp | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Detector_Building_v2/Detector_Building_v2.ino b/Detector_Building_v2/Detector_Building_v2.ino index 05f148b..b63f792 100644 --- a/Detector_Building_v2/Detector_Building_v2.ino +++ b/Detector_Building_v2/Detector_Building_v2.ino @@ -15,14 +15,13 @@ const bool CALIB = false; // Calibration mode const int n = 17; // Number of data points const int m = 1; // Number of segments -const int deg = 2; // Regression degree -ld V[n] = { // Voltage measurements - 2.70, 3.39, 2.40, 2.31, 2.19, 1.94, 4.09, 4.11, 3.98, 3.92, 3.77, 3.53, 3.18, 3.07, 2.30, 2.53, 2.49 -}; -ld T[n] = { // Temperature measurements - 24.0, 44.4, 18.4, 13.9, 11.2, 8.6, 60.8, 62.0, 58.3, 53.9, 49.3, 44.9, 41.0, 37.3, 13.4, 19.1, 18.2 +const int deg = 3; // Regression degree +ld data[2 * n] = { +// V T + 2.70, 24.0 + }; -ld coeff[m][deg + 1]; +ld coeff[m][deg + 1], V[n], T[n]; void setup() { @@ -31,23 +30,28 @@ void setup() { pinMode(LED_G, OUTPUT); pinMode(LED_B, OUTPUT); + for (int i = 0; i < n; i++) { + V[i] = data[2 * i]; + T[i] = data[2 * i + 1]; + } + sort(V, n); sort(T, n); ld x[n], y[n]; for (int i = 0; i < n; i++) x[i] = log(v2r(V[i])) - 7; for (int i = 0; i < n; i++) y[i] = 1000 / c2k(T[i]); - for (int i = 0; i < n; i++) { - Serial.print("("); + /*for (int i = 0; i < n; i++) { + Serial.print("{"); Serial.print((double)x[i], 12); Serial.print(", "); Serial.print((double)y[i], 12); - Serial.print(")"); + Serial.print("},"); Serial.println(); - } + }*/ for (int i = 0; i < m; i++) { int ret = fitCurve(deg, n / m, x + i * n / m, y + i * n / m, deg + 1, coeff[i]); - if (ret == 0){ //Returned value is 0 if no error + /*if (ret == 0) { // Returned value is 0 if no error char c = 'A'; Serial.println("Coefficients are:"); for (int j = 0; j <= deg; j++){ @@ -56,7 +60,7 @@ void setup() { Serial.print((double)coeff[i][j], 12); Serial.println(); } - } + }*/ } } diff --git a/libraries/detectorBuilding/src/detectorBuilding.cpp b/libraries/detectorBuilding/src/detectorBuilding.cpp index c9367e1..0c31c28 100644 --- a/libraries/detectorBuilding/src/detectorBuilding.cpp +++ b/libraries/detectorBuilding/src/detectorBuilding.cpp @@ -34,7 +34,7 @@ void sort(ld a[], int n) { // Too lazy to implement a fast sort for (int i = 0; i < n; i++) { for (int j = 0; j < n - 1; j++) { - if (a[j] > a[j + 1]) { + if (a[j] < a[j + 1]) { ld tmp = a[j]; a[j] = a[j + 1]; a[j + 1] = tmp; -- cgit v1.2.3-70-g09d2