From ad560e7d16d84049d7bdd9a73973851a8f723eba Mon Sep 17 00:00:00 2001 From: Alexander Klein Date: Sun, 10 Sep 2023 13:00:12 +0200 Subject: [PATCH] more sensorData menu --- doc/TODO allgemein.txt | 1 - lib/CalcAzimuth/calcAzimuth.cpp | 22 +++ lib/CalcAzimuth/calcAzimuth.h | 2 + lib/Sensors/sensorData.cpp | 6 + lib/Sensors/sensorData.h | 1 + src/SpecialMenus/GPS/menuGPS.cpp | 159 ------------------ src/SpecialMenus/GPS/menuGPS.h | 42 ----- .../SensorData/menuSensorData.cpp | 86 +++++++++- src/main.cpp | 12 +- 9 files changed, 119 insertions(+), 212 deletions(-) delete mode 100644 src/SpecialMenus/GPS/menuGPS.cpp delete mode 100644 src/SpecialMenus/GPS/menuGPS.h diff --git a/doc/TODO allgemein.txt b/doc/TODO allgemein.txt index cfe6422..070ef63 100644 --- a/doc/TODO allgemein.txt +++ b/doc/TODO allgemein.txt @@ -40,7 +40,6 @@ Do later: Do now: Code: Doxygen Kommentare aktualisieren - Add Gyroskop Sensor Latex: Genaue Beschreibung von PulseCounter HardwareUnit wenn möglich diff --git a/lib/CalcAzimuth/calcAzimuth.cpp b/lib/CalcAzimuth/calcAzimuth.cpp index 8db7a5d..889155c 100644 --- a/lib/CalcAzimuth/calcAzimuth.cpp +++ b/lib/CalcAzimuth/calcAzimuth.cpp @@ -30,6 +30,28 @@ void CalcAzimuth::updateCurrentPosition(Point point) { this->positionChanged = true; } +String CalcAzimuth::stateToString(State state) { + switch (state) { + case State::Invalid: + return "Invalid"; + + case State::Bad: + return "Bad"; + + case State::Ok: + return "Ok"; + + case State::Good: + return "Good"; + + case State::Super: + return "Super"; + + default: + return "UNKOWN"; + } +} + void CalcAzimuth::run() { if (!this->positionChanged) return; diff --git a/lib/CalcAzimuth/calcAzimuth.h b/lib/CalcAzimuth/calcAzimuth.h index b44cf8f..03a9a21 100644 --- a/lib/CalcAzimuth/calcAzimuth.h +++ b/lib/CalcAzimuth/calcAzimuth.h @@ -34,6 +34,8 @@ class CalcAzimuth : public Component { int16_t getAzimuth() const { return this->calcAzimuth; } State getState() const { return this->state; } + static String stateToString(State state); + private: void run() override; void updateAzimuth(); diff --git a/lib/Sensors/sensorData.cpp b/lib/Sensors/sensorData.cpp index e7d4159..5e7a4d7 100644 --- a/lib/Sensors/sensorData.cpp +++ b/lib/Sensors/sensorData.cpp @@ -105,6 +105,12 @@ CalcAzimuth::State SensorData::getCalcAzimuthState() const { return CalcAzimuth::State::Invalid; } +NTRIPClientStates SensorData::getNtripState() const { + if (this->ntripClient) + return this->ntripClient->getClientState(); + return NTRIPClientStates::notAvailable; +} + void SensorData::printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct) { if (!SensorData::outputStatusPrintPVTdata) return; diff --git a/lib/Sensors/sensorData.h b/lib/Sensors/sensorData.h index 15add06..71fcf54 100644 --- a/lib/Sensors/sensorData.h +++ b/lib/Sensors/sensorData.h @@ -47,6 +47,7 @@ class SensorData : public Component { Point getCurrentPos() const { return this->currentPosition; } const UBX_NAV_PVT_data_t* getGnssData() const { return this->gnssData; }; + NTRIPClientStates getNtripState() const; const float* getGyroData() const { return this->yawPitchRoll; } CalcAzimuth* getCalcCompass() const { return this->calcCompass; } diff --git a/src/SpecialMenus/GPS/menuGPS.cpp b/src/SpecialMenus/GPS/menuGPS.cpp deleted file mode 100644 index 878fd13..0000000 --- a/src/SpecialMenus/GPS/menuGPS.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/** - * @file menuGPS.cpp - * @author Alexander Klein (alex@kleiax.de) - * @brief Contains an implementation of the class MenuGPS - * @version 0.1 - * @date 2022-01-29 - * - * @copyright Copyright (c) 2022 - * - */ - -#include "menuGPS.h" - -MenuGPS::MenuGPS(SensorData* sensorData) : - MenuInformationSites(10) { - this->sensorData = sensorData; - // this->ntripClient = this->navigation->getNTRIPClient(); -} - -void MenuGPS::printPage() const { - const UBX_NAV_PVT_data_t* gpsData = this->sensorData->getGnssData(); - uint8_t fixType = 0; - if (gpsData) - fixType = gpsData->fixType; - - String lineOne = "Data isn't valid"; - String lineTwo = "or no GPS signal"; - - switch (this->getCurrentPage()) { - case 0: - if (fixType) { - lineOne = "Sats: "; - lineOne.concat(gpsData->numSV); - lineTwo = "PDOP: "; - lineTwo.concat(gpsData->pDOP); - } - break; - - case 1: - if (fixType) { - lineOne = "Lat: "; - lineOne.concat(gpsData->lat); - lineTwo = "Lon: "; - lineTwo.concat(gpsData->lon); - } - break; - - case 2: - lineOne = "Time: "; - lineTwo = ""; - if (fixType) { - if (gpsData->hour < 10) - lineTwo.concat("0"); - lineTwo.concat(gpsData->hour); - lineTwo.concat(":"); - if (gpsData->min < 10) - lineTwo.concat("0"); - lineTwo.concat(gpsData->min); - lineTwo.concat(":"); - if (gpsData->sec < 10) - lineTwo.concat("0"); - lineTwo.concat(gpsData->sec); - } else - lineTwo = "00:00:00"; - - break; - - case 3: { - // NTRIPClientStates status = this->ntripClient->getClientState(); - // lineOne = "NTRIP Client is"; - - // if (status == NTRIPClientStates::pushData) - // lineTwo = "enabled"; - // else if (status == NTRIPClientStates::notAvailable) - // lineTwo = "not available"; - // else - // lineTwo = "disabled"; - } - break; - - case 4: - lineOne = "Fix type:"; - if (fixType == 0) - lineTwo = "None"; - else if (fixType == 1) - lineTwo = "Dead Reckoning"; - else if (fixType == 2) - lineTwo = "2D"; - else if (fixType == 3) - lineTwo = "3D"; - else if (fixType == 3) - lineTwo = "GNSS + Dead Reck"; - else if (fixType == 5) - lineTwo = "Time Only"; - else - lineTwo = "UNKNOWN"; - break; - - case 5: { - lineOne = "Carrier Solution"; - uint8_t carrSoln = gpsData->flags.bits.carrSoln; - if (carrSoln == 0) - lineTwo = "None"; - else if (carrSoln == 1) - lineTwo = "Floating"; - else if (carrSoln == 2) - lineTwo = "Fixed"; - else - lineTwo = "UNKNOWN"; - } - break; - - case 6: - lineOne = "Hrizntl Accuracy"; - if (fixType) { - lineTwo = ""; - lineTwo.concat(gpsData->hAcc); - } else - lineTwo = "0"; - break; - - case 7: - lineOne = "magDec: "; - lineTwo = "magAcc: "; - if (fixType) { - lineOne.concat(gpsData->magDec); - lineTwo.concat(gpsData->magAcc); - } else { - lineOne.concat("---"); - lineTwo.concat("---"); - } - break; - - case 8: - lineOne = "Azimuth: "; - lineTwo = ""; - lineTwo.concat(this->sensorData->getRealAzimuth()); - break; - - default: - this->printDefault(); - return; - } - - this->print(lineOne, lineTwo); -} - -void MenuGPS::runCommand() const { - switch (this->getCurrentPage()) { - case 3: { - // // std::cout << "MenuGPS::runCommand " << this->ntripClient->getClientState() << std::endl; - // if (this->ntripClient->getClientState() == NTRIPClientStates::pushData) - // this->ntripClient->setActivated(false); - // else if (this->ntripClient->getClientState() != NTRIPClientStates::notAvailable) - // this->ntripClient->setActivated(true); - } - break; - } -} diff --git a/src/SpecialMenus/GPS/menuGPS.h b/src/SpecialMenus/GPS/menuGPS.h deleted file mode 100644 index e88f6fe..0000000 --- a/src/SpecialMenus/GPS/menuGPS.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @file menuGPS.h - * @author Alexander Klein (alex@kleiax.de) - * @brief Contains a class to print informations about the GPS object - * @version 0.1 - * @date 2022-01-29 - * - * @copyright Copyright (c) 2022 - * - */ - -#ifndef MENU_GPS_H -#define MENU_GPS_H - -#include - -#include "menuInformationSites.h" -#include "sensorData.h" -#include "ntripClient.h" - -/** - * @brief A class to print informations about the GPS object - * - */ -class MenuGPS : public MenuInformationSites { - public: - /** - * @brief Construct a new Menu GPS object - * - * @param gps - */ - MenuGPS(SensorData* sensorData); - - private: - void printPage() const override; - void runCommand() const override; - - // NTRIPClient* ntripClient; - SensorData* sensorData; -}; - -#endif // MENU_GPS_H diff --git a/src/SpecialMenus/SensorData/menuSensorData.cpp b/src/SpecialMenus/SensorData/menuSensorData.cpp index 8198e4c..56b9545 100644 --- a/src/SpecialMenus/SensorData/menuSensorData.cpp +++ b/src/SpecialMenus/SensorData/menuSensorData.cpp @@ -12,28 +12,102 @@ #include "menuSensorData.h" MenuSensorData::MenuSensorData(SensorData* sensorData) : - MenuInformationSites(4) { + MenuInformationSites(7) { this->sensorData = sensorData; } void MenuSensorData::printPage() const { + const UBX_NAV_PVT_data_t* gpsData = this->sensorData->getGnssData(); + uint8_t fixType = 0; + if (gpsData) + fixType = gpsData->fixType; + String lineOne = ""; String lineTwo = ""; switch (this->getCurrentPage()) { case 0: - lineOne = "Yaw:"; + lineOne = " Y P R :"; lineTwo.concat(this->sensorData->getGyroData()[0]); + lineTwo.concat(" "); + lineTwo.concat(this->sensorData->getGyroData()[1]); + lineTwo.concat(" "); + lineTwo.concat(this->sensorData->getGyroData()[2]); break; case 1: - lineOne = "Pitch:"; - lineTwo.concat(this->sensorData->getGyroData()[1]); + lineOne = "Real Azimuth:"; + lineTwo.concat(this->sensorData->getRealAzimuth()); break; case 2: - lineOne = "Roll:"; - lineTwo.concat(this->sensorData->getGyroData()[2]); + lineOne = "Calc Azimuth:"; + lineTwo.concat(this->sensorData->getCalcAzimuth()); + lineTwo.concat(" "); + lineTwo.concat(CalcAzimuth::stateToString(this->sensorData->getCalcAzimuthState)); + break; + + case 3: { + lineOne = "Lat:"; + lineTwo = "Lon:"; + Point pos = this->sensorData->getCurrentPos(); + lineOne.concat(pos.getLatitude()); + lineTwo.concat(pos.getLongitude()); + } + break; + + case 4: + lineOne = "Time: "; + lineTwo = ""; + if (fixType) { + if (gpsData->hour < 10) + lineTwo.concat("0"); + lineTwo.concat(gpsData->hour); + lineTwo.concat(":"); + if (gpsData->min < 10) + lineTwo.concat("0"); + lineTwo.concat(gpsData->min); + lineTwo.concat(":"); + if (gpsData->sec < 10) + lineTwo.concat("0"); + lineTwo.concat(gpsData->sec); + } else + lineTwo = "00:00:00"; + + break; + + case 5: { + lineOne = "CarSol: "; + lineTwo = "Ntrip: "; + uint8_t carrSoln = gpsData->flags.bits.carrSoln; + if (carrSoln == 0) + lineOne = "None"; + else if (carrSoln == 1) + lineOne = "Floating"; + else if (carrSoln == 2) + lineOne = "Fixed"; + else + lineOne = "UNKNOWN"; + NTRIPClientStates status = this->sensorData->getNtripState(); + if (status == NTRIPClientStates::pushData) + lineTwo = "enabled"; + else if (status == NTRIPClientStates::notAvailable) + lineTwo = " N/A"; + else + lineTwo = "disabled"; + } + break; + + case 6: + lineOne = "HAcc: "; + lineTwo = "Sats: "; + if (fixType) { + lineOne.concat(gpsData->hAcc); + lineTwo.concat(gpsData->numSV); + } else { + lineOne = "-/-"; + lineTwo = "-/-"; + } break; default: diff --git a/src/main.cpp b/src/main.cpp index 6f9b80a..97bbcd4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -217,6 +217,7 @@ void makeMenu() { main_m = new Menu(); main_m->setLcd(lcdWrapper); Menu* mode_m = new Menu(); + Menu* set_m = new Menu(); Menu* pid_m = new Menu(); MenuIntInput* pidl_m = new MenuIntInput(3, new MenuPidSettings(moveController.getPID(0))); MenuIntInput* pidr_m = new MenuIntInput(3, new MenuPidSettings(moveController.getPID(1))); @@ -225,23 +226,20 @@ void makeMenu() { MenuAutopilot* auto_m = new MenuAutopilot(driveManager); MenuTestMode* testM_m = new MenuTestMode(driveManager); MenuCalibrateCompass* comp_m = new MenuCalibrateCompass(driveManager); - MenuGPS* gps_m = new MenuGPS(sensorData); MenuSysteminformation* sys_m = new MenuSysteminformation(mainBattery); MenuSensorData* sen_m = new MenuSensorData(sensorData); //TODO: Wie bekommt jeder die dumme Route? MenuRoute* rout_m = new MenuRoute(new Route()); auto_m->setUpdateDelay(1000); - gps_m->setUpdateDelay(1000); sys_m->setUpdateDelay(1500); sen_m->setUpdateDelay(500); // Entry for the main menu main_m->addEntry(new MenuAction("Mode", mode_m)); main_m->addEntry(new MenuAction("Sensor", sen_m)); - main_m->addEntry(new MenuAction("GPS", gps_m)); main_m->addEntry(new MenuAction("Route", rout_m)); - main_m->addEntry(new MenuAction("PID", pid_m)); + main_m->addEntry(new MenuAction("Settings", set_m)); main_m->addEntry(new MenuAction("Systeminfo", sys_m)); main_m->addEntry(new MenuAction("Restart", restart)); @@ -253,6 +251,12 @@ void makeMenu() { mode_m->addEntry(new MenuAction("Test Mode", testM_m)); mode_m->addEntry(new MenuAction("Consol Control", dummy)); + // Entry for the setting menu + set_m->addEntry(new MenuAction("PID", pid_m)); + set_m->addEntry(new MenuAction("Speed", dummy)); + set_m->addEntry(new MenuAction("Distance", dummy)); + set_m->addEntry(new MenuAction("WiFi", dummy)); + // Entry for the PID Menu pid_m->addEntry(new MenuAction("Left", pidl_m)); pid_m->addEntry(new MenuAction("Right", pidr_m));