diff --git a/.vscode/settings.json b/.vscode/settings.json index fa5cb03..d055b55 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -152,6 +152,7 @@ "Rtcm", "Schalke", "Soln", + "Systeminformation", "TPMOBIL", "UBLOX", "wheelspeed", diff --git a/doc/TODO allgemein.txt b/doc/TODO allgemein.txt index 6d6bbdb..98bf03d 100644 --- a/doc/TODO allgemein.txt +++ b/doc/TODO allgemein.txt @@ -30,12 +30,14 @@ Do later: -> ESP und Sensoren in den DeepSleep für Auschalten oder Akkuschutz -> Doxygen comments - navigation + - autopilot Do now: Code: Doxygen Kommentare aktualisieren Fernbedienung! + Compass calibration überprüfen Latex: Anhang: Liste mit allen Komponenten und Kurzbeschreibung diff --git a/lib/ControllPad/controlPad.cpp b/lib/ControlPad/controlPad.cpp similarity index 100% rename from lib/ControllPad/controlPad.cpp rename to lib/ControlPad/controlPad.cpp diff --git a/lib/ControllPad/controlPad.h b/lib/ControlPad/controlPad.h similarity index 100% rename from lib/ControllPad/controlPad.h rename to lib/ControlPad/controlPad.h diff --git a/lib/ControllPad/controlPadInput.h b/lib/ControlPad/controlPadInput.h similarity index 100% rename from lib/ControllPad/controlPadInput.h rename to lib/ControlPad/controlPadInput.h diff --git a/src/OutputBuf/outputBuf.h b/src/OutputBuf/outputBuf.h index fa6abb3..f75cfe2 100644 --- a/src/OutputBuf/outputBuf.h +++ b/src/OutputBuf/outputBuf.h @@ -2,15 +2,15 @@ * @file outputBuf.h * @author Alexander Klein (alex@kleiax.de) * @brief Contains a small class that provide a streambuf - * + * * The streambuf is used to double the std::cout to consol * and MQTT. - * + * * @version 0.1 * @date 2022-02-14 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef OUTPUT_STREAM_MQTT_H @@ -26,61 +26,61 @@ #include /** - * @brief A alternativ streambuf for std::cout - * + * @brief A alternative streambuf for std::cout + * * The streambuf is used to double the std::cout to consol * and MQTT. - * + * */ -class OutputBuf : public std::streambuf { - public: - /** - * @brief Construct a new Output Buf Mqtt object - * - * @param debugMqtt - * @param serialBT - */ - OutputBuf(DebugMqtt* debugMqtt = nullptr, BluetoothSerial* serialBT = nullptr); +class OutputBuf : public std::streambuf +{ +public: + /** + * @brief Construct a new Output Buf Mqtt object + * + * @param debugMqtt + * @param serialBT + */ + OutputBuf(DebugMqtt *debugMqtt = nullptr, BluetoothSerial *serialBT = nullptr); - /** - * @brief Activate the mqtt output - * - * This only works if the DebugMqtt is set by - * setDebugMqtt. - * - * @param status - */ - void activateMqtt(bool status); + /** + * @brief Activate the mqtt output + * + * This only works if the DebugMqtt is set by + * setDebugMqtt(). + * + * @param status + */ + void activateMqtt(bool status); - /** - * @brief Active the output over the bluetooth serial consol - * - * This only works if BluetoothSerial is set by - * setSerialBT. - * - * @param status - */ - void activateSerialBT(bool status); + /** + * @brief Active the output over the bluetooth serial consol + * + * This only works if BluetoothSerial is set by + * setSerialBT(). + * + * @param status + */ + void activateSerialBT(bool status); - void setDebugMqtt(DebugMqtt* debugMqtt); - void setSerialBT(BluetoothSerial* serialBT); + void setDebugMqtt(DebugMqtt *debugMqtt); + void setSerialBT(BluetoothSerial *serialBT); +protected: + /** + * @brief + * + * @param c + * @return std::streambuf::int_type + */ + virtual std::streambuf::int_type overflow(std::streambuf::int_type c); - protected: - /** - * @brief - * - * @param c - * @return std::streambuf::int_type - */ - virtual std::streambuf::int_type overflow(std::streambuf::int_type c); +private: + bool isMqttActive = false; + bool isSerialBTActive = false; - private: - bool isMqttActive = false; - bool isSerialBTActive = false; - - DebugMqtt* debugMqtt; - BluetoothSerial* serialBT; + DebugMqtt *debugMqtt; + BluetoothSerial *serialBT; }; #endif // OUTPUT_STREAM_MQTT_H diff --git a/src/SpecialMenus/CalibrateBattery/menuCalibrateBattery.h b/src/SpecialMenus/CalibrateBattery/menuCalibrateBattery.h index 28ca45d..50b45eb 100644 --- a/src/SpecialMenus/CalibrateBattery/menuCalibrateBattery.h +++ b/src/SpecialMenus/CalibrateBattery/menuCalibrateBattery.h @@ -1,7 +1,7 @@ /** * @file menuCalibrateBattery.h * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains a Menu class to calibrate the Battery class * @version 0.1 * @date 2023-09-26 * @@ -15,13 +15,27 @@ #include "menuControl.h" #include "battery.h" +/** + * @brief A Menu class to calibrate the Battery class + */ class MenuCalibrateBattery : public MenuControl { public: + /** + * @brief Construct a new MenuCalibrateBattery object + * + * Prepare the calibration. + * + * @param battery + */ MenuCalibrateBattery(Battery *battery); + /** + * @brief Prints the instructions for the calibration + */ void printMenu() override; + // User Inputs void left() override; void no() override { this->left(); } void right() override; diff --git a/src/SpecialMenus/PID/menuPidSettings.h b/src/SpecialMenus/PID/menuPidSettings.h index b8fbb44..cc9f877 100644 --- a/src/SpecialMenus/PID/menuPidSettings.h +++ b/src/SpecialMenus/PID/menuPidSettings.h @@ -4,9 +4,9 @@ * @brief Contains a class to tune the PID settings * @version 0.1 * @date 2022-01-19 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef PID_SETTINGS_H @@ -18,22 +18,22 @@ /** * @brief A class to tune the PID settings - * + * */ -class MenuPidSettings : public MenuIntInputWrapper { - public: - /** - * @brief Construct a new Menu Pid Settings object - * - * @param pid - */ - MenuPidSettings(PID* pid); +class MenuPidSettings : public MenuIntInputWrapper +{ +public: + /** + * @brief Construct a new Menu Pid Settings object + * + * @param pid + */ + MenuPidSettings(PID *pid); - void action(int16_t* values, uint8_t length) override; - - private: - PID* pid; + void action(int16_t *values, uint8_t length) override; +private: + PID *pid; }; #endif // PID_SETTINGS_H diff --git a/src/SpecialMenus/Route/menuRoute.h b/src/SpecialMenus/Route/menuRoute.h index 7d6072f..b65ee37 100644 --- a/src/SpecialMenus/Route/menuRoute.h +++ b/src/SpecialMenus/Route/menuRoute.h @@ -111,6 +111,13 @@ public: */ void exportRoute(uint8_t routeNumber); + /** + * @brief Delete a Route + * + * The functions tries to delete the current route from the RoverApi. + * + * @param routeNumber + */ void deleteRoute(uint8_t routeNumber); /** diff --git a/src/SpecialMenus/Route/menuRoutePoints.h b/src/SpecialMenus/Route/menuRoutePoints.h index 58b60c7..382dbce 100644 --- a/src/SpecialMenus/Route/menuRoutePoints.h +++ b/src/SpecialMenus/Route/menuRoutePoints.h @@ -4,9 +4,9 @@ * @brief Contains a class to print the coordinates of a Route. * @version 0.1 * @date 2022-12-28 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef MENU_ROUTE_POINTS_H @@ -18,33 +18,33 @@ /** * @brief Prints coordinates of Route side by side. - * + * */ -class MenuRoutePoints : public MenuInformationSites { - public: - /** - * @brief Construct a new Menu Route Points object - * - * @param route - */ - MenuRoutePoints(Route *route); +class MenuRoutePoints : public MenuInformationSites +{ +public: + /** + * @brief Construct a new Menu Route Points object + * + * @param route + */ + MenuRoutePoints(Route *route); - /** - * @brief Configure the base class MenuInformationSites - * - * Set the amount of pages. - */ - void init () override; + /** + * @brief Configure the base class MenuInformationSites + * + * Set the amount of pages. + */ + void init() override; - /** - * @brief Prints the the coordinates of the current Point. - */ - void printPage() const override; - - private: - Route* route; - bool error = false; + /** + * @brief Prints the the coordinates of the current Point. + */ + void printPage() const override; +private: + Route *route; + bool error = false; }; #endif // MENU_ROUTE_POINTS_H diff --git a/src/SpecialMenus/SensorData/menuSensorData.h b/src/SpecialMenus/SensorData/menuSensorData.h index 9f0883b..83d820b 100644 --- a/src/SpecialMenus/SensorData/menuSensorData.h +++ b/src/SpecialMenus/SensorData/menuSensorData.h @@ -1,12 +1,12 @@ /** * @file menuSensorData.h * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains a MenuInformationClass to print the SensorData * @version 0.1 * @date 2023-09-04 - * + * * @copyright Copyright (c) 2023 - * + * */ #ifndef MENU_SENSOR_DATA_H @@ -15,14 +15,23 @@ #include "menuInformationSites.h" #include "sensorData.h" -class MenuSensorData : public MenuInformationSites { - public: - MenuSensorData(SensorData* SensorData); +/** + * @brief A MenuInformationClass to print the SensorData + */ +class MenuSensorData : public MenuInformationSites +{ +public: + /** + * @brief Construct a new MenuSensorData object + * + * @param SensorData + */ + MenuSensorData(SensorData *SensorData); - private: - void printPage() const override; +private: + void printPage() const override; - SensorData* sensorData; + SensorData *sensorData; }; -#endif //MENU_SENSOR_DATA_H +#endif // MENU_SENSOR_DATA_H diff --git a/src/SpecialMenus/Speed/menuSpeed.cpp b/src/SpecialMenus/Speed/menuSpeed.cpp index dcb26d6..6f4b170 100644 --- a/src/SpecialMenus/Speed/menuSpeed.cpp +++ b/src/SpecialMenus/Speed/menuSpeed.cpp @@ -1,18 +1,20 @@ /** * @file menuSpeed.cpp * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief * @version 0.1 * @date 2023-09-26 - * + * * @copyright Copyright (c) 2023 - * + * */ #include "menuSpeed.h" -void MenuSpeed::action(int16_t* values, uint8_t length) { - if (length != 2) { +void MenuSpeed::action(int16_t *values, uint8_t length) +{ + if (length != 2) + { return; } this->speeds.x = values[0] / 10.0; diff --git a/src/SpecialMenus/Speed/menuSpeed.h b/src/SpecialMenus/Speed/menuSpeed.h index 2bdf127..419cf91 100644 --- a/src/SpecialMenus/Speed/menuSpeed.h +++ b/src/SpecialMenus/Speed/menuSpeed.h @@ -1,12 +1,12 @@ /** * @file menuSpeed.h * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains a MenuIntInputWrapper to change speeds * @version 0.1 * @date 2023-09-26 - * + * * @copyright Copyright (c) 2023 - * + * */ #ifndef MENU_SPEED_H @@ -15,15 +15,24 @@ #include #include "moveControl.h" -class MenuSpeed : public MenuIntInputWrapper { - public: - MenuSpeed(DrivingSpeeds& speeds) : speeds(speeds){}; +/** + * @brief A MenuIntInputWrapper class to change speeds + */ +class MenuSpeed : public MenuIntInputWrapper +{ +public: + MenuSpeed(DrivingSpeeds &speeds) : speeds(speeds){}; - void action(int16_t* values, uint8_t length) override; - - private: - DrivingSpeeds& speeds; + /** + * @brief Changes the speeds + * + * @param values + * @param length + */ + void action(int16_t *values, uint8_t length) override; +private: + DrivingSpeeds &speeds; }; #endif // MENU_SPEED_H diff --git a/src/SpecialMenus/Systeminformation/menuSysteminformatio.cpp b/src/SpecialMenus/Systeminformation/menuSysteminformatio.cpp index bbad40c..a145123 100644 --- a/src/SpecialMenus/Systeminformation/menuSysteminformatio.cpp +++ b/src/SpecialMenus/Systeminformation/menuSysteminformatio.cpp @@ -4,71 +4,73 @@ * @brief Contains an implementation of the class MenuSysteminformation * @version 0.1 * @date 2022-12-27 - * + * * @copyright Copyright (c) 2022 - * + * */ #include "menuSysteminformation.h" -MenuSysteminformation::MenuSysteminformation(Battery* mainBattery) - : MenuInformationSites(8), mainBattery {mainBattery} { +MenuSysteminformation::MenuSysteminformation(Battery *mainBattery) + : MenuInformationSites(8), mainBattery{mainBattery} +{ this->noEqualLeft = true; } -void MenuSysteminformation::printPage() const { +void MenuSysteminformation::printPage() const +{ String lineOne = ""; String lineTwo = ""; - switch (this->getCurrentPage()) { - case 0: - lineOne = "Free Heap:"; - lineTwo.concat(ESP.getFreeHeap()); - break; + switch (this->getCurrentPage()) + { + case 0: + lineOne = "Free Heap:"; + lineTwo.concat(ESP.getFreeHeap()); + break; - case 1: - lineOne = "Max alloc Heap:"; - lineTwo.concat(ESP.getMaxAllocHeap()); - break; + case 1: + lineOne = "Max alloc Heap:"; + lineTwo.concat(ESP.getMaxAllocHeap()); + break; - case 2: - lineOne = "Uptime in secs:"; - lineTwo.concat((millis() / 1000)); - break; + case 2: + lineOne = "Uptime in secs:"; + lineTwo.concat((millis() / 1000)); + break; - case 3: - lineOne = "Main battery:"; - lineTwo = ""; - lineTwo.concat(this->mainBattery->getBatteryPercent()); - lineTwo.concat("% - V="); - lineTwo.concat(this->mainBattery->getBatteryVoltage()); - break; + case 3: + lineOne = "Main battery:"; + lineTwo = ""; + lineTwo.concat(this->mainBattery->getBatteryPercent()); + lineTwo.concat("% - V="); + lineTwo.concat(this->mainBattery->getBatteryVoltage()); + break; - case 4: - lineOne = "Current WiFi"; - lineTwo = "channel: "; - lineTwo.concat(Network::getCurrentChannel()); - break; + case 4: + lineOne = "Current WiFi"; + lineTwo = "channel: "; + lineTwo.concat(Network::getCurrentChannel()); + break; - case 5: - lineOne = "Software verion:"; - lineTwo = VERSION; - break; + case 5: + lineOne = "Software verion:"; + lineTwo = VERSION; + break; - case 6: - lineOne = "Build timestamp:"; - lineTwo = String(BUILD_TIMESTAMP).substring(0, 16); - break; + case 6: + lineOne = "Build timestamp:"; + lineTwo = String(BUILD_TIMESTAMP).substring(0, 16); + break; - case 7: - lineOne = "Kleiax Rover by"; - lineTwo = "Alexander Klein"; - break; + case 7: + lineOne = "Kleiax Rover by"; + lineTwo = "Alexander Klein"; + break; - default: - this->printDefault(); - return; + default: + this->printDefault(); + return; } this->print(lineOne, lineTwo); } - diff --git a/src/SpecialMenus/Systeminformation/menuSysteminformation.h b/src/SpecialMenus/Systeminformation/menuSysteminformation.h index 8b35dc6..754596f 100644 --- a/src/SpecialMenus/Systeminformation/menuSysteminformation.h +++ b/src/SpecialMenus/Systeminformation/menuSysteminformation.h @@ -4,9 +4,9 @@ * @brief Contains a class to print informations about the system * @version 0.1 * @date 2022-12-27 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef MENU_SYSTEMINFORMATION_H @@ -23,22 +23,23 @@ /** * @brief Prints information about the current system status. - * + * * The informations are about the batteries, memory and uptime. */ -class MenuSysteminformation : public MenuInformationSites { - public: - /** - * @brief Construct a new Menu Systeminformation object - * - * @param mainBattery - */ - MenuSysteminformation(Battery* mainBattery); +class MenuSysteminformation : public MenuInformationSites +{ +public: + /** + * @brief Construct a new Menu Systeminformation object + * + * @param mainBattery + */ + MenuSysteminformation(Battery *mainBattery); - private: - void printPage() const override; +private: + void printPage() const override; - Battery* mainBattery; + Battery *mainBattery; }; #endif // MENU_SYSTEMINFORMATION_H diff --git a/src/SpecialMenus/driveModi/Autopilot/menuAutopilot.h b/src/SpecialMenus/driveModi/Autopilot/menuAutopilot.h index 206ffab..48c94c9 100644 --- a/src/SpecialMenus/driveModi/Autopilot/menuAutopilot.h +++ b/src/SpecialMenus/driveModi/Autopilot/menuAutopilot.h @@ -4,9 +4,9 @@ * @brief Contains a class to print informations about the Autopilot * @version 0.1 * @date 2022-02-03 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef MENU_AUTOPILOT_DRIVE_H @@ -17,44 +17,44 @@ /** * @brief A class to print informations about the Autopilot - * + * */ -class MenuAutopilot : public MenuDriveMode { - public: - /** - * @brief Construct a new Menu Autopilot object - * - * @param driveManager for MenuDriveMode - */ - MenuAutopilot(DriveManager* driveManager) : MenuDriveMode(driveManager) {} +class MenuAutopilot : public MenuDriveMode +{ +public: + /** + * @brief Construct a new Menu Autopilot object + * + * @param driveManager for MenuDriveMode + */ + MenuAutopilot(DriveManager *driveManager) : MenuDriveMode(driveManager) {} - /** - * @brief Prints the Information to display and console - * - * The informations are only printed to the display if it - * set. - * - * Changes the DriveModi to Autopilot if it is the first time called - * and save the Autopilot object. - */ - void printPage() const override; - + /** + * @brief Prints the Information to display and console + * + * The informations are only printed to the display if it + * set. + * + * Changes the DriveModi to Autopilot if it is the first time called + * and save the Autopilot object. + */ + void printPage() const override; - /** - * @brief can be called to update shown data - */ - void update() override; + /** + * @brief can be called to update shown data + */ + void update() override; - private: - void init() override; - void runCommand() override; - void runCommandNo() override; +private: + void init() override; + void runCommand() override; + void runCommandNo() override; - bool mutable targetFreezed = false; - double mutable minDistance; + bool mutable targetFreezed = false; + double mutable minDistance; - Autopilot* autopilot; - RouteInfo routeInfo; + Autopilot *autopilot; + RouteInfo routeInfo; }; #endif // MENU_AUTOPILOT_DRIVE_H diff --git a/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.cpp b/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.cpp index c479fc7..83950a6 100644 --- a/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.cpp +++ b/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.cpp @@ -4,159 +4,167 @@ * @brief Contains an implementation of the class MenuManualDrive * @version 0.1 * @date 2022-01-20 - * + * * @copyright Copyright (c) 2022 - * + * */ #include "menuCalibrateCompass.h" -MenuCalibrateCompass::MenuCalibrateCompass(DriveManager* driveManager) : MenuDriveMode(driveManager) {} +MenuCalibrateCompass::MenuCalibrateCompass(DriveManager *driveManager) : MenuDriveMode(driveManager) {} -MenuCalibrateCompass::~MenuCalibrateCompass() { +MenuCalibrateCompass::~MenuCalibrateCompass() +{ delete this->caliCompass; this->caliCompassMode->setCalibrateCompass(); } -void MenuCalibrateCompass::printPage() const { +void MenuCalibrateCompass::printPage() const +{ String lineOne = ""; String lineTwo = ""; - switch (this->getCurrentPage()) { - case 0: - lineOne = "-Ready to drive-"; - lineTwo = "Compass Mode"; + switch (this->getCurrentPage()) + { + case 0: + lineOne = "-Ready to drive-"; + lineTwo = "Compass Mode"; + break; + + case 1: + lineOne = "Azimuth:"; + lineTwo.concat(this->caliCompassMode->getSensorData()->getRealAzimuth()); + break; + + case 2: + switch (this->caliCompass->getState()) + { + case CalibrateCompass::State::Ready: + lineOne = "Start compass"; + lineTwo = "calibration"; break; - case 1: - lineOne = "Azimuth:"; - lineTwo.concat(this->caliCompassMode->getSensorData()->getRealAzimuth()); - break; - - case 2: - switch (this->caliCompass->getState()) { - case CalibrateCompass::State::Ready : - lineOne = "Start compass"; - lineTwo = "calibration"; - break; - - case CalibrateCompass::State::Calibrating : - lineOne = "Calibrating..."; - lineTwo = "Move around"; - break; - - case CalibrateCompass::State::Finished: - lineOne = "Calibration"; - lineTwo = "finished"; - break; - - default: - break; - } + case CalibrateCompass::State::Calibrating: + lineOne = "Calibrating..."; + lineTwo = "Move around"; break; - case 3: - lineOne = "Save compass"; - lineTwo = "data in flash"; - break; - - case 4: - lineOne = "Load data"; - lineTwo = "from flash"; - break; - - case 5: - lineOne = "Remove"; - lineTwo = "calibration data"; - break; - - case 6: - lineOne = "Use current"; - lineTwo = "calibration data"; - break; - - case 7: - lineOne = "Reset for new"; - lineTwo = "calibration run"; - break; - - case 8: - lineOne = "X min: "; - lineOne.concat(this->caliCompass->getCalibrationData().data[0][0]); - lineTwo = "X max: "; - lineTwo.concat(this->caliCompass->getCalibrationData().data[0][1]); - break; - - case 9: - lineOne = "Y min: "; - lineOne.concat(this->caliCompass->getCalibrationData().data[1][0]); - lineTwo = "Y max: "; - lineTwo.concat(this->caliCompass->getCalibrationData().data[1][1]); - break; - - case 10: - lineOne = "Z min: "; - lineOne.concat(this->caliCompass->getCalibrationData().data[2][0]); - lineTwo = "Z max: "; - lineTwo.concat(this->caliCompass->getCalibrationData().data[2][1]); + case CalibrateCompass::State::Finished: + lineOne = "Calibration"; + lineTwo = "finished"; break; default: - this->printDefault(); + break; + } + break; + + case 3: + lineOne = "Save compass"; + lineTwo = "data in flash"; + break; + + case 4: + lineOne = "Load data"; + lineTwo = "from flash"; + break; + + case 5: + lineOne = "Remove"; + lineTwo = "calibration data"; + break; + + case 6: + lineOne = "Use current"; + lineTwo = "calibration data"; + break; + + case 7: + lineOne = "Reset for new"; + lineTwo = "calibration run"; + break; + + case 8: + lineOne = "X min: "; + lineOne.concat(this->caliCompass->getCalibrationData().data[0][0]); + lineTwo = "X max: "; + lineTwo.concat(this->caliCompass->getCalibrationData().data[0][1]); + break; + + case 9: + lineOne = "Y min: "; + lineOne.concat(this->caliCompass->getCalibrationData().data[1][0]); + lineTwo = "Y max: "; + lineTwo.concat(this->caliCompass->getCalibrationData().data[1][1]); + break; + + case 10: + lineOne = "Z min: "; + lineOne.concat(this->caliCompass->getCalibrationData().data[2][0]); + lineTwo = "Z max: "; + lineTwo.concat(this->caliCompass->getCalibrationData().data[2][1]); + break; + + default: + this->printDefault(); return; } this->print(lineOne, lineTwo); } -void MenuCalibrateCompass::init() { +void MenuCalibrateCompass::init() +{ this->firstPrint = false; this->caliCompassMode = new CalibrateCompassM(); this->driveManager->changeModus(this->caliCompassMode); this->caliCompass = new CalibrateCompass(this->caliCompassMode->getSensorData()->getRealCompass()); this->setCountPages(11); - MenuDriveMode::updateDelay = MenuCalibrateCompass::updateDelay; + MenuDriveMode::updateDelay = MenuCalibrateCompass::updateDelay; } -void MenuCalibrateCompass::runCommand() { - switch (this->getCurrentPage()) { - case 2: - switch (this->caliCompass->getState()) { - case CalibrateCompass::State::Ready : - this->caliCompassMode->setCalibrateCompass(this->caliCompass); - this->caliCompass->start(); - break; - - case CalibrateCompass::State::Finished: - this->caliCompassMode->setCalibrateCompass(); - this->caliCompass->useData(); - break; - - default: - break; - } +void MenuCalibrateCompass::runCommand() +{ + switch (this->getCurrentPage()) + { + case 2: + switch (this->caliCompass->getState()) + { + case CalibrateCompass::State::Ready: + this->caliCompassMode->setCalibrateCompass(this->caliCompass); + this->caliCompass->start(); break; - case 3: - this->caliCompass->saveData(); - break; - - case 4: - this->caliCompass->loadData(); - break; - - case 5: - this->caliCompass->removeCalibration(); - break; - - case 6: + case CalibrateCompass::State::Finished: + this->caliCompassMode->setCalibrateCompass(); this->caliCompass->useData(); - break; + break; - case 7: - this->caliCompass->reset(); - break; - default: break; + } + break; + + case 3: + this->caliCompass->saveData(); + break; + + case 4: + this->caliCompass->loadData(); + break; + + case 5: + this->caliCompass->removeCalibration(); + break; + + case 6: + this->caliCompass->useData(); + break; + + case 7: + this->caliCompass->reset(); + break; + + default: + break; } } diff --git a/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.h b/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.h index 91d54bc..fd57f64 100644 --- a/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.h +++ b/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.h @@ -4,9 +4,9 @@ * @brief Contains a class to print information about the class ManualControl * @version 0.1 * @date 2022-01-20 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef MENU_CALIBRATE_COMPASS_H @@ -18,37 +18,37 @@ /** * @brief A class to print informations about the class ManualControl - * + * */ -class MenuCalibrateCompass : public MenuDriveMode { - public: - /** - * @brief Construct a new Menu Manual Control object - * - * @param driveManager - */ - MenuCalibrateCompass(DriveManager* driveManager); - ~MenuCalibrateCompass(); +class MenuCalibrateCompass : public MenuDriveMode +{ +public: + /** + * @brief Construct a new Menu Manual Control object + * + * @param driveManager + */ + MenuCalibrateCompass(DriveManager *driveManager); + ~MenuCalibrateCompass(); - /** - * @brief Prints the Information to display and console - * - * The informations are only printed to the display if it - * set. - * - * Changes the DriveModi to Autopilot if it is the first time called. - */ - void printPage() const override; + /** + * @brief Prints the Information to display and console + * + * The informations are only printed to the display if it + * set. + * + * Changes the DriveModi to Autopilot if it is the first time called. + */ + void printPage() const override; - protected: - void init() override; - void runCommand() override; +private: + void init() override; + void runCommand() override; - private: - CalibrateCompassM* caliCompassMode = nullptr; - CalibrateCompass* caliCompass = nullptr; + CalibrateCompassM *caliCompassMode = nullptr; + CalibrateCompass *caliCompass = nullptr; - static constexpr uint16_t updateDelay = 500; + static constexpr uint16_t updateDelay = 500; }; #endif // MENU_CALIBRATE_COMPASS_H diff --git a/src/SpecialMenus/driveModi/CaptureRoute/menuCaptureRoute.h b/src/SpecialMenus/driveModi/CaptureRoute/menuCaptureRoute.h index d4505ce..679844f 100644 --- a/src/SpecialMenus/driveModi/CaptureRoute/menuCaptureRoute.h +++ b/src/SpecialMenus/driveModi/CaptureRoute/menuCaptureRoute.h @@ -4,9 +4,9 @@ * @brief Contains a class to print informations about CaptureRoute * @version 0.1 * @date 2022-01-31 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef MENU_CAPTURE_ROUTE_H #define MENU_MANUAL_DRIVE_H @@ -16,41 +16,41 @@ /** * @brief A class to print informations about the Autopilot - * + * */ -class MenuCaptureRoute : public MenuDriveMode { - public: - /** - * @brief Construct a new Menu Capture Route object - * - * @param driveManager - */ - MenuCaptureRoute(DriveManager* driveManager) : MenuDriveMode(driveManager) {} +class MenuCaptureRoute : public MenuDriveMode +{ +public: + /** + * @brief Construct a new Menu Capture Route object + * + * @param driveManager + */ + MenuCaptureRoute(DriveManager *driveManager) : MenuDriveMode(driveManager) {} - /** - * @brief Prints the Information to display and console - * - * The informations are only printed to the display if it - * set. - * - * Changes the DriveModi to CaptureRoute if it is the first time called - * and save the CaptureRoute object. - */ - void printPage() const override; + /** + * @brief Prints the Information to display and console + * + * The informations are only printed to the display if it + * set. + * + * Changes the DriveModi to CaptureRoute if it is the first time called + * and save the CaptureRoute object. + */ + void printPage() const override; - /** - * @brief can be called to update shown data - */ - void update() override; + /** + * @brief can be called to update shown data + */ + void update() override; - void runCommand() override; +private: + void runCommand() override; + void init() override; - private: - void init() override; + CaptureRoute *captureRoute = nullptr; - CaptureRoute* captureRoute = nullptr; - - static constexpr uint16_t updateDelay = 500; + static constexpr uint16_t updateDelay = 500; }; #endif // MENU_MANUAL_DRIVE_H diff --git a/src/SpecialMenus/driveModi/ManualDrive/menuManualDrive.cpp b/src/SpecialMenus/driveModi/ManualDrive/menuManualDrive.cpp index 8a5d1b9..9ef590e 100644 --- a/src/SpecialMenus/driveModi/ManualDrive/menuManualDrive.cpp +++ b/src/SpecialMenus/driveModi/ManualDrive/menuManualDrive.cpp @@ -4,77 +4,84 @@ * @brief Contains an implementation of the class MenuManualDrive * @version 0.1 * @date 2022-01-20 - * + * * @copyright Copyright (c) 2022 - * + * */ #include "menuManualDrive.h" -MenuManualControl::MenuManualControl(DriveManager* driveManager) : MenuDriveMode(driveManager) { +MenuManualControl::MenuManualControl(DriveManager *driveManager) : MenuDriveMode(driveManager) +{ this->noEqualLeft = true; } - -void MenuManualControl::printPage() const { +void MenuManualControl::printPage() const +{ String lineOne = ""; String lineTwo = ""; - switch (this->getCurrentPage()) { - case 0: - lineOne = "-Ready to drive-"; - break; + switch (this->getCurrentPage()) + { + case 0: + lineOne = "-Ready to drive-"; + break; - case 1: - lineOne = "Input mode:"; - if (this->manualControl->getInputMode() == ManualControl::InputMode::Analog) { - lineTwo = "Analog"; - } - else { - lineTwo = "Digital"; - } - break; + case 1: + lineOne = "Input mode:"; + if (this->manualControl->getInputMode() == ManualControl::InputMode::Analog) + { + lineTwo = "Analog"; + } + else + { + lineTwo = "Digital"; + } + break; - case 2: - lineOne = "Speed Menu"; - break; + case 2: + lineOne = "Speed Menu"; + break; - case 3: - lineOne = "Sensor Menu"; - break; + case 3: + lineOne = "Sensor Menu"; + break; - default: - this->printDefault(); + default: + this->printDefault(); return; } this->print(lineOne, lineTwo); } -void MenuManualControl::init() { +void MenuManualControl::init() +{ this->firstPrint = false; this->manualControl = new ManualControl(); this->driveManager->changeModus(this->manualControl); this->setCountPages(4); - MenuDriveMode::updateDelay = MenuManualControl::updateDelay; + MenuDriveMode::updateDelay = MenuManualControl::updateDelay; this->activateSpeedMenu(); MenuDriveMode::init(); } -void MenuManualControl::runCommand() { - switch (this->getCurrentPage()) { - case 1: - this->manualControl->switchInputMode(); - break; +void MenuManualControl::runCommand() +{ + switch (this->getCurrentPage()) + { + case 1: + this->manualControl->switchInputMode(); + break; - case 2: - this->enterSpeedMenu(); - break; + case 2: + this->enterSpeedMenu(); + break; - case 3: - this->enterSensorMenu(); - break; - - default: - break; + case 3: + this->enterSensorMenu(); + break; + + default: + break; } } diff --git a/src/SpecialMenus/driveModi/ManualDrive/menuManualDrive.h b/src/SpecialMenus/driveModi/ManualDrive/menuManualDrive.h index ee5eb0f..f405a00 100644 --- a/src/SpecialMenus/driveModi/ManualDrive/menuManualDrive.h +++ b/src/SpecialMenus/driveModi/ManualDrive/menuManualDrive.h @@ -4,9 +4,9 @@ * @brief Contains a class to print information about the class ManualControl * @version 0.1 * @date 2022-01-20 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef MENU_MANUAL_DRIVE_H @@ -17,36 +17,36 @@ /** * @brief A class to print informations about the class ManualControl - * + * */ -class MenuManualControl : public MenuDriveMode { - public: - /** - * @brief Construct a new Menu Manual Control object - * - * @param driveManager - */ - MenuManualControl(DriveManager* driveManager); +class MenuManualControl : public MenuDriveMode +{ +public: + /** + * @brief Construct a new Menu Manual Control object + * + * @param driveManager + */ + MenuManualControl(DriveManager *driveManager); - /** - * @brief Prints the Information to display and console - * - * The informations are only printed to the display if it - * set. - * - * Changes the DriveModi to Autopilot if it is the first time called. - */ - void printPage() const override; + /** + * @brief Prints the Information to display and console + * + * The informations are only printed to the display if it + * set. + * + * Changes the DriveModi to Autopilot if it is the first time called. + */ + void printPage() const override; - protected: - void init() override; - void runCommand() override; +private: + void init() override; + void runCommand() override; - private: - ManualControl* manualControl = nullptr; - CalibrateCompass* caliCompass = nullptr; + ManualControl *manualControl = nullptr; + CalibrateCompass *caliCompass = nullptr; - static constexpr uint16_t updateDelay = 500; + static constexpr uint16_t updateDelay = 500; }; #endif // MENU_MANUAL_DRIVE_H diff --git a/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp b/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp index 72dc8b8..aafcca5 100644 --- a/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp +++ b/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp @@ -4,25 +4,29 @@ * @brief Contains the implementation of the class MenuTestMode. * @version 0.1 * @date 2022-09-08 - * + * * @copyright Copyright (c) 2022 - * + * */ #include "menuTestMode.h" -MenuTestMode::MenuTestMode(DriveManager* driveManager) - : driveManager {driveManager} -{ +MenuTestMode::MenuTestMode(DriveManager *driveManager) + : driveManager{driveManager} +{ } -MenuTestMode::~MenuTestMode() { - if (isInit) { +MenuTestMode::~MenuTestMode() +{ + if (isInit) + { delete this->mainMenu; } } -void MenuTestMode::printMenu() { - if (!this->isInit) { +void MenuTestMode::printMenu() +{ + if (!this->isInit) + { this->isInit = true; this->init(); } @@ -30,62 +34,82 @@ void MenuTestMode::printMenu() { this->mainMenu->printMenu(); } -void MenuTestMode::down() { - if (this->checkInput()) { +void MenuTestMode::down() +{ + if (this->checkInput()) + { this->mainMenu->down(); } } -void MenuTestMode::up() { - if (this->checkInput()) { +void MenuTestMode::up() +{ + if (this->checkInput()) + { this->mainMenu->up(); } } -void MenuTestMode::right() { - if (this->checkInput()) { +void MenuTestMode::right() +{ + if (this->checkInput()) + { this->mainMenu->right(); } } -void MenuTestMode::left() { +void MenuTestMode::left() +{ if (this->mainMenu->isInSubmenu()) - if (this->checkInput()) { + if (this->checkInput()) + { this->mainMenu->left(); } - else { + else + { this->testMode->abortManeuver(); this->mainMenu->left(); } - else { + else + { this->parentMenu->printMenu(); } } -void MenuTestMode::yes() { - if (this->checkInput()) { +void MenuTestMode::yes() +{ + if (this->checkInput()) + { this->mainMenu->yes(); } } -void MenuTestMode::no() { - if (this->mainMenu->isInSubmenu()) { +void MenuTestMode::no() +{ + if (this->mainMenu->isInSubmenu()) + { if (this->checkInput()) this->mainMenu->no(); - else { + else + { this->testMode->abortManeuver(); this->mainMenu->no(); - }} - else{ - this->left();} + } + } + else + { + this->left(); + } } -void MenuTestMode::init() { +void MenuTestMode::init() +{ this->testMode = new TestMode(); this->driveManager->changeModus(this->testMode); - auto dummy = []() { - std::cout << "Dummy in Action" <testMode->getSpeedometerLeft()); auto *encoderRightMenu = new SpeedometerTest(this->testMode->getSpeedometerRight()); - // Set menus on LCD this->mainMenu->setLcd(this->lcd); engineMenu->setLcd(this->lcd); @@ -143,7 +166,6 @@ void MenuTestMode::init() { engineBothMenu->setMinMaxSteps(1, 0, secondsMax, 1); engineBothMenu->setPrintParentMenu(false); - // Entrys for the menus auto *engineAction = new MenuAction("Engine", engineMenu); auto *engineLeftAction = new MenuAction("Left", engineLeftMenu); @@ -162,7 +184,7 @@ void MenuTestMode::init() { auto *lightRedAction = new MenuAction("Red", dummy); auto *lightGreenAction = new MenuAction("Green", dummy); auto *lightBlueAction = new MenuAction("Blue", dummy); - auto *lightOffAction = new MenuAction("Off", dummy); + auto *lightOffAction = new MenuAction("Off", dummy); // Add entries to the menus this->mainMenu->addEntry(engineAction); @@ -182,74 +204,89 @@ void MenuTestMode::init() { lightMenu->addEntry(lightRedAction); lightMenu->addEntry(lightGreenAction); lightMenu->addEntry(lightBlueAction); - lightMenu->addEntry(lightOffAction); + lightMenu->addEntry(lightOffAction); } -void MenuTestMode::update() { - if (this->maneuverInAction) { - if (millis() - this->lastUpdateTime > updateDelay) { +void MenuTestMode::update() +{ + if (this->maneuverInAction) + { + if (millis() - this->lastUpdateTime > updateDelay) + { this->printManeuverTime(); this->lastUpdateTime = millis(); - }} + } + } } -bool MenuTestMode::checkInput() { - if (this->testMode->getBusy()) { +bool MenuTestMode::checkInput() +{ + if (this->testMode->getBusy()) + { this->printManeuverTime(); this->maneuverInAction = true; return false; } - if (this->maneuverInAction) { + if (this->maneuverInAction) + { this->maneuverInAction = false; } - - return true; + + return true; } -void MenuTestMode::printManeuverTime() { +void MenuTestMode::printManeuverTime() +{ uint8_t maneuverTime = this->testMode->getRemainingManeuverTime(); - if (maneuverTime) { + if (maneuverTime) + { String lineTwo = ""; lineTwo.concat(maneuverTime); lineTwo.concat(" secs"); this->print("Maneuver time:", lineTwo); - } else { + } + else + { this->maneuverInAction = false; this->printMenu(); } } -MenuTestModeWrapper::MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionSingle testModeFunction) - : menu {menu}, - testModeFunctionSingle {testModeFunction}, - testMode {menu->getTestMode()} +MenuTestModeWrapper::MenuTestModeWrapper(MenuTestMode *menu, TestModeFunctionSingle testModeFunction) + : menu{menu}, + testModeFunctionSingle{testModeFunction}, + testMode{menu->getTestMode()} { } -MenuTestModeWrapper::MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionDouble testModeFunction) - : menu {menu}, - testModeFunctionDouble {testModeFunction}, - testMode {menu->getTestMode()} +MenuTestModeWrapper::MenuTestModeWrapper(MenuTestMode *menu, TestModeFunctionDouble testModeFunction) + : menu{menu}, + testModeFunctionDouble{testModeFunction}, + testMode{menu->getTestMode()} { } -void MenuTestModeWrapper::action(int16_t* values, uint8_t length) { +void MenuTestModeWrapper::action(int16_t *values, uint8_t length) +{ // This function calls a member function with a pointer // Very helpful site: // https://isocpp.org/wiki/faq/pointers-to-members#fnptr-vs-memfnptr-types bool res = false; - if (length == 2 && static_cast(this->testModeFunctionDouble)) { + if (length == 2 && static_cast(this->testModeFunctionDouble)) + { res = (this->testMode->*this->testModeFunctionDouble)(values[0], values[1]); } - else if (length == 1 && static_cast(this->testModeFunctionSingle)) { + else if (length == 1 && static_cast(this->testModeFunctionSingle)) + { res = (this->testMode->*this->testModeFunctionSingle)(values[0]); } - if (res) { + if (res) + { this->menu->printManeuverTime(); this->menu->maneuverStarted(); } -} +} diff --git a/src/SpecialMenus/driveModi/TestMode/menuTestMode.h b/src/SpecialMenus/driveModi/TestMode/menuTestMode.h index 4022dbc..6d22523 100644 --- a/src/SpecialMenus/driveModi/TestMode/menuTestMode.h +++ b/src/SpecialMenus/driveModi/TestMode/menuTestMode.h @@ -4,9 +4,9 @@ * @brief Contains a class to use and print information about the TestMode. * @version 0.1 * @date 2022-09-08 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef MENU_TEST_MODE_H #define MENU_TEST_MODE_H @@ -20,80 +20,82 @@ /** * @brief Interact with the TestMode - * + * */ -class MenuTestMode : public MenuControl { - public: - /** - * @brief Construct a new Menu Test Mode object - * - * @param driveManager - */ - MenuTestMode(DriveManager *driveManager); - ~MenuTestMode(); +class MenuTestMode : public MenuControl +{ +public: + /** + * @brief Construct a new Menu Test Mode object + * + * @param driveManager + */ + MenuTestMode(DriveManager *driveManager); + ~MenuTestMode(); - /** - * @brief Prints the last informations - * - * On first call this function calls the init function. - * On every call this functions call the printMenu function from - * the mainMenu of this class. - */ - void printMenu() override; + /** + * @brief Prints the last informations + * + * On first call this function calls the init function. + * On every call this functions call the printMenu function from + * the mainMenu of this class. + */ + void printMenu() override; - /** - * @brief Prints maneuver Timer - * - * Aside from that the function looks if the maneuver is done and - * give the user input free. - */ - void printManeuverTime(); + /** + * @brief Prints maneuver Timer + * + * Aside from that the function looks if the maneuver is done and + * give the user input free. + */ + void printManeuverTime(); - void down() override; - void up() override; - void right() override; - void left() override; - void yes() override; - void no() override; + void down() override; + void up() override; + void right() override; + void left() override; + void yes() override; + void no() override; - /** - * @brief Calls the printManeuverTime function if a maneuver is in process. - * - */ - void update() override; + /** + * @brief Calls the printManeuverTime function if a maneuver is in process. + * + */ + void update() override; - TestMode* getTestMode() const { return this->testMode; } - void maneuverStarted() { this->maneuverInAction = true; } + TestMode *getTestMode() const { return this->testMode; } + void maneuverStarted() { this->maneuverInAction = true; } - private: - void init(); - bool checkInput(); +private: + void init(); + bool checkInput(); - DriveManager* driveManager; - TestMode* testMode = nullptr; - Menu* mainMenu = nullptr; + DriveManager *driveManager; + TestMode *testMode = nullptr; + Menu *mainMenu = nullptr; - bool isInit = false; - bool maneuverInAction = false; + bool isInit = false; + bool maneuverInAction = false; - uint32_t lastUpdateTime = 0; - uint16_t updateDelay = 1000; + uint32_t lastUpdateTime = 0; + uint16_t updateDelay = 1000; }; -typedef bool (TestMode::*TestModeFunctionSingle)(int16_t); -typedef bool (TestMode::*TestModeFunctionDouble)(int16_t, int16_t); -class MenuTestModeWrapper : public MenuIntInputWrapper { - public: - MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionSingle testModeFunction); - MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionDouble testModeFunction); +typedef bool (TestMode::*TestModeFunctionSingle)(int16_t); +typedef bool (TestMode::*TestModeFunctionDouble)(int16_t, int16_t); +class MenuTestModeWrapper : public MenuIntInputWrapper +{ +public: + MenuTestModeWrapper(MenuTestMode *menu, TestModeFunctionSingle testModeFunction); + MenuTestModeWrapper(MenuTestMode *menu, TestModeFunctionDouble testModeFunction); - void action(int16_t* values, uint8_t length) override; + void action(int16_t *values, uint8_t length) override; - private: - MenuTestMode* menu; - TestMode* testMode; - TestModeFunctionSingle testModeFunctionSingle = nullptr; - TestModeFunctionDouble testModeFunctionDouble = nullptr; +private: + MenuTestMode *menu; + TestMode *testMode; + TestModeFunctionSingle testModeFunctionSingle = nullptr; + TestModeFunctionDouble testModeFunctionDouble = nullptr; }; #endif // MENU_TEST_MODE_H diff --git a/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp b/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp index 4481e53..4f3735c 100644 --- a/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp +++ b/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp @@ -4,50 +4,54 @@ * @brief Contains the implementation of the class SpeedometerTest. * @version 0.1 * @date 2023-01-24 - * + * * @copyright Copyright (c) 2023 - * + * */ #include "speedometerTest.h" -SpeedometerTest::SpeedometerTest(Speedometer* speedometer) - : speedometer {speedometer} +SpeedometerTest::SpeedometerTest(Speedometer *speedometer) + : speedometer{speedometer} { this->speedometer->setDirection(Speedometer::Forward); } +void SpeedometerTest::printMenu() +{ + switch (this->state) + { + case State::Off: + this->print("Press Yes (O)", "to start"); + break; -void SpeedometerTest::printMenu() { - switch (this->state) { - case State::Off : - this->print("Press Yes (O)", "to start"); - break; + case State::Running: + this->print("Running, Yes (O)", "to stop"); + break; - case State::Running : - this->print("Running, Yes (O)", "to stop"); - break; + case State::Finished: + { + String res = ""; + res.concat(this->result); + this->print("Result: ", res); + } + break; - case State::Finished : { - String res = ""; - res.concat(this->result); - this->print("Result: ", res); - } - break; - - default: - this->print("Error in", "MenuTest.cpp"); - break; + default: + this->print("Error in", "MenuTest.cpp"); + break; } } - -void SpeedometerTest::left() { +void SpeedometerTest::left() +{ this->no(); } -void SpeedometerTest::no() { - if (this->state == State::Running){ +void SpeedometerTest::no() +{ + if (this->state == State::Running) + { speedometer->calibrationMeasurementStop(); } @@ -55,27 +59,29 @@ void SpeedometerTest::no() { this->parentMenu->printMenu(); } -void SpeedometerTest::yes() { - switch (this->state) { - case State::Off : - this->state = State::Running; - this->speedometer->calibrationMeasurementStart(); - this->printMenu(); - break; +void SpeedometerTest::yes() +{ + switch (this->state) + { + case State::Off: + this->state = State::Running; + this->speedometer->calibrationMeasurementStart(); + this->printMenu(); + break; - case State::Running : - this->state = State::Finished; - this->result = this->speedometer->calibrationMeasurementStop(); - this->printMenu(); - break; - - case State::Finished : - this->state = State::Running; - this->speedometer->calibrationMeasurementStart(); - this->printMenu(); - break; + case State::Running: + this->state = State::Finished; + this->result = this->speedometer->calibrationMeasurementStop(); + this->printMenu(); + break; - default: - break; + case State::Finished: + this->state = State::Running; + this->speedometer->calibrationMeasurementStart(); + this->printMenu(); + break; + + default: + break; } } diff --git a/src/SpecialMenus/driveModi/TestMode/speedometerTest.h b/src/SpecialMenus/driveModi/TestMode/speedometerTest.h index 3990403..ad8173a 100644 --- a/src/SpecialMenus/driveModi/TestMode/speedometerTest.h +++ b/src/SpecialMenus/driveModi/TestMode/speedometerTest.h @@ -4,9 +4,9 @@ * @brief Contains a class to test the wheel encoder. * @version 0.1 * @date 2023-01-24 - * + * * @copyright Copyright (c) 2023 - * + * */ #pragma once @@ -16,49 +16,51 @@ /** * @brief Tests the wheel encoder. - * + * */ -class SpeedometerTest : public MenuControl { - public: - /** - * @brief The states of the test. - */ - enum State { - Off, - Running, - Finished - }; +class SpeedometerTest : public MenuControl +{ +public: + /** + * @brief The states of the test. + */ + enum State + { + Off, + Running, + Finished + }; - /** - * @brief Construct a new Speedometer Test object - * - * @param speedometer - */ - SpeedometerTest(Speedometer* speedometer); + /** + * @brief Construct a new Speedometer Test object + * + * @param speedometer + */ + SpeedometerTest(Speedometer *speedometer); - /** - * @brief Prints the actual state of the test. - */ - void printMenu() override; + /** + * @brief Prints the actual state of the test. + */ + void printMenu() override; - /** - * @brief Calls no. - */ - void left() override; + /** + * @brief Calls no. + */ + void left() override; - /** - * @brief Exit the menu or end the test. - */ - void no() override; + /** + * @brief Exit the menu or end the test. + */ + void no() override; - /** - * @brief Starts or restarts the test. - */ - void yes() override; + /** + * @brief Starts or restarts the test. + */ + void yes() override; - private: - Speedometer* speedometer; - State state = State::Off; +private: + Speedometer *speedometer; + State state = State::Off; - uint16_t result = 0; + uint16_t result = 0; }; diff --git a/src/SpecialMenus/driveModi/menuDriveMode.cpp b/src/SpecialMenus/driveModi/menuDriveMode.cpp index 2245eee..527aeca 100644 --- a/src/SpecialMenus/driveModi/menuDriveMode.cpp +++ b/src/SpecialMenus/driveModi/menuDriveMode.cpp @@ -4,79 +4,114 @@ * @brief Contains an implementation of the class MenuDriveMode * @version 0.1 * @date 2022-01-31 - * + * * @copyright Copyright (c) 2022 - * + * */ #include "menuDriveMode.h" -MenuDriveMode::MenuDriveMode(DriveManager* driveManager) - : driveManager {driveManager} +MenuDriveMode::MenuDriveMode(DriveManager *driveManager) + : driveManager{driveManager} { } -void MenuDriveMode::left() { - if (static_cast(this->activeMenu)) { - if (static_cast(this->activeMenu)) { - this->activeMenu->left(); +MenuDriveMode::~MenuDriveMode() +{ + if (this->selfCreatedMenuSpeed) + { + delete this->menuSpeed; + } +} + +void MenuDriveMode::addSpeedMenu(MenuIntInput *menuSpeed) +{ + if (this->selfCreatedMenuSpeed) + { + delete this->menuSpeed; + this->selfCreatedMenuSpeed = false; + } + + this->menuSpeed = menuSpeed; +} + +void MenuDriveMode::left() +{ + if (static_cast(this->activeMenu)) + { + if (static_cast(this->activeMenu)) + { + this->activeMenu->left(); } return; } this->firstPrint = true; this->configureOnLeave(); - delete this->menuSpeed; + delete this->menuSpeed; this->driveManager->changeModus(); MenuInformationSites::left(); } -void MenuDriveMode::right() { - if (static_cast(this->activeMenu)) { +void MenuDriveMode::right() +{ + if (static_cast(this->activeMenu)) + { this->activeMenu->right(); return; } MenuInformationSites::right(); } -void MenuDriveMode::up() { - if (static_cast(this->activeMenu)) { +void MenuDriveMode::up() +{ + if (static_cast(this->activeMenu)) + { this->activeMenu->up(); return; } MenuInformationSites::up(); } -void MenuDriveMode::down() { - if (static_cast(this->activeMenu)) { +void MenuDriveMode::down() +{ + if (static_cast(this->activeMenu)) + { this->activeMenu->down(); return; } MenuInformationSites::down(); } -void MenuDriveMode::yes() { - if (static_cast(this->activeMenu)) { +void MenuDriveMode::yes() +{ + if (static_cast(this->activeMenu)) + { this->activeMenu->yes(); return; } MenuInformationSites::yes(); } -void MenuDriveMode::no() { - if (static_cast(this->activeMenu)) { +void MenuDriveMode::no() +{ + if (static_cast(this->activeMenu)) + { this->activeMenu->no(); return; } MenuInformationSites::no(); } -void MenuDriveMode::prepareReenterMenu() { +void MenuDriveMode::prepareReenterMenu() +{ this->activeMenu = nullptr; } -void MenuDriveMode::printMenu() { - if (static_cast(this->activeMenu)) { +void MenuDriveMode::printMenu() +{ + if (static_cast(this->activeMenu)) + { this->activeMenu->printMenu(); return; } @@ -84,40 +119,53 @@ void MenuDriveMode::printMenu() { MenuInformationSites::printMenu(); } -void MenuDriveMode::init() { +void MenuDriveMode::init() +{ this->activeMenu = nullptr; } -void MenuDriveMode::activateSpeedMenu() { - if (!this->driveManager->isActive()) { +void MenuDriveMode::activateSpeedMenu() +{ + if (!this->driveManager->isActive()) + { return; } - DrivingSpeeds& speeds = this->driveManager->getDriveModiPtr()->getSpeedsRef(); + if (this->selfCreatedMenuSpeed) + { + delete this->menuSpeed; + } + + DrivingSpeeds &speeds = this->driveManager->getDriveModiPtr()->getSpeedsRef(); auto *menu = new MenuIntInput(2, new MenuSpeed(speeds)); menu->setMinMax(5, UINT8_MAX); menu->setEntry(0, "x m/s e-1", driveManager->getDrivingSpeedsRef().x * 10); menu->setEntry(1, "z rad/s e-1", driveManager->getDrivingSpeedsRef().rot * 10); + this->selfCreatedMenuSpeed = true; this->addSpeedMenu(menu); } -void MenuDriveMode::enterSpeedMenu() { +void MenuDriveMode::enterSpeedMenu() +{ this->activeMenu = this->menuSpeed; this->enterMenu(); } -void MenuDriveMode::enterSensorMenu() { +void MenuDriveMode::enterSensorMenu() +{ this->activeMenu = this->menuSensor; this->enterMenu(); } -void MenuDriveMode::enterMenu() { - if (!static_cast(this->activeMenu)) { +void MenuDriveMode::enterMenu() +{ + if (!static_cast(this->activeMenu)) + { return; } - + this->activeMenu->printMenu(); this->activeMenu->setParentMenu(this); } diff --git a/src/SpecialMenus/driveModi/menuDriveMode.h b/src/SpecialMenus/driveModi/menuDriveMode.h index c74861e..ce9bcbf 100644 --- a/src/SpecialMenus/driveModi/menuDriveMode.h +++ b/src/SpecialMenus/driveModi/menuDriveMode.h @@ -4,9 +4,9 @@ * @brief Contains a base class for Menus about DriveModi * @version 0.1 * @date 2022-01-31 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef MENU_DRIVE_MODI_H #define MENU_DRIVE_MODI_H @@ -18,49 +18,80 @@ /** * @brief A base class for Menus about DriveModi - * + * */ -class MenuDriveMode : public MenuInformationSites { - public: - /** - * @brief Construct a new Menu Drive Mode object - * - * @param driveManager - */ - MenuDriveMode(DriveManager* driveManager); +class MenuDriveMode : public MenuInformationSites +{ +public: + /** + * @brief Construct a new Menu Drive Mode object + * + * @param driveManager + */ + MenuDriveMode(DriveManager *driveManager); - void addSensorMenu(MenuSensorData* menuSensor) { this->menuSensor = menuSensor; } - void addSpeedMenu(MenuIntInput* menuSpeed) { this->menuSpeed = menuSpeed; } + ~MenuDriveMode(); - /** - * @brief Goes back to the parentMenu. - */ - void left() override; - void right() override; - void up() override; - void down() override; - void yes() override; - void no() override; + void addSensorMenu(MenuSensorData *menuSensor) { this->menuSensor = menuSensor; } + void addSpeedMenu(MenuIntInput *menuSpeed); - void prepareReenterMenu() override; - void printMenu() override; + /** + * @brief Goes back to the parentMenu. + */ + void left() override; + void right() override; + void up() override; + void down() override; + void yes() override; + void no() override; - protected: - void init() override; - virtual void configureOnLeave() {} - void activateSpeedMenu(); - void enterSpeedMenu(); - void enterSensorMenu(); + void prepareReenterMenu() override; + void printMenu() override; - DriveManager* driveManager; - - bool firstPrint = true; +protected: + void init() override; - private: - void enterMenu(); + /** + * @brief Prepare leaving the menu + * + * Can be overwritten to add extra functionality to safely + * exit the menu. This function is called before the parentMenu + * is printed. + */ + virtual void configureOnLeave() {} - MenuControl* activeMenu = nullptr; - MenuSensorData* menuSensor = nullptr; - MenuIntInput* menuSpeed = nullptr; + /** + * @brief Creates an own SpeedMenu + * + * This function uses addSpeedMenu() at the end to that the new menu + */ + void activateSpeedMenu(); + + /** + * @brief Enter a Menu to edit the speeds + * + * To enter this menu it has to be set by addSpeedMenu() or activateSpeedMenu() + */ + void enterSpeedMenu(); + + /** + * @brief Enter a Menu with the SensorData + * + * To enter this menu it has to be set by addSensorMenu() + */ + void enterSensorMenu(); + + DriveManager *driveManager; + + bool firstPrint = true; + +private: + void enterMenu(); + + MenuControl *activeMenu = nullptr; + MenuSensorData *menuSensor = nullptr; + MenuIntInput *menuSpeed = nullptr; + + bool selfCreatedMenuSpeed = false; }; #endif // MENU_DRIVE_MODI_H diff --git a/src/driveModi/Modi/Autopilot/autopilot.h b/src/driveModi/Modi/Autopilot/autopilot.h index 6a5efc3..510ecda 100644 --- a/src/driveModi/Modi/Autopilot/autopilot.h +++ b/src/driveModi/Modi/Autopilot/autopilot.h @@ -4,15 +4,14 @@ * @brief Contains a class which use the navigate class to drive automaticaly * @version 0.1 * @date 2022-02-02 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef AUTOPILOT_H #define AUTOPILOT_H - #include "navigation.h" #include "driveModi/Modi/ManualControl/manualControl.h" @@ -20,110 +19,113 @@ class DirectionChangeSignal; /** * @brief This class use the navigate class to drive automaticaly - * + * * This class get the information from the navigate class. When an * object of this class is constructed the rover can be driven manually. * When the Rover is near to the first position of the Route, you can * switch to automatic drive. - * + * */ -class Autopilot : public ManualControl { - public: - enum State { - InsufficientAccuracy = -2, - NoRoute = -1, - None = 0, - NavigationStarted, - GetToStartPoint, - SelfDrivingAvailable, - SelfDriving, - SelfDrivingRotate, - TargetReached - }; +class Autopilot : public ManualControl +{ +public: + enum State + { + InsufficientAccuracy = -2, + NoRoute = -1, + None = 0, + NavigationStarted, + GetToStartPoint, + SelfDrivingAvailable, + SelfDriving, + SelfDrivingRotate, + TargetReached + }; - /** - * @brief Destroy the Autopilot object - * - * Disconnect the NTRIP-Client - */ - ~Autopilot(); + /** + * @brief Destroy the Autopilot object + * + * Disconnect the NTRIP-Client + */ + ~Autopilot(); - void restart(); + void restart(); - /** - * @brief Get the Route Info object - * - * @return RouteInfo - */ - RouteInfo getRouteInfo() const { return this->routeInfo; } + /** + * @brief Get the Route Info object + * + * @return RouteInfo + */ + RouteInfo getRouteInfo() const { return this->routeInfo; } - /** - * @brief Get the Course Correction object - * - * @return CourseCorrection - */ - CourseCorrection getCourseCorrection() const { return this->courseCorrection; } + /** + * @brief Get the Course Correction object + * + * @return CourseCorrection + */ + CourseCorrection getCourseCorrection() const { return this->courseCorrection; } - /** - * @brief Get the State object - * - * @return State - */ - State getState() const { return this->state; } - Navigation* getNavigation() const { return this->navigation; } - - /** - * @brief Tells if there are new informations to display - * - * @return true - * @return false - */ - bool shouldUpdate(); - void testRotate(int16_t degree); - void endRotate(); - void switchLoopMode() { this->loopMode = !this->loopMode; } - bool getLoopMode() const { return this->loopMode; } + /** + * @brief Get the State object + * + * @return State + */ + State getState() const { return this->state; } + Navigation *getNavigation() const { return this->navigation; } - private: - void init(); - void drive(); - void beginRotate(); - void rotate(); - void run() override; - void checkButtonInput(); - void askNavigationForOrder(); - void selfDriving(); - void restartLoop(); - void afterActivate() override; + /** + * @brief Tells if there are new informations to display + * + * @return true + * @return false + */ + bool shouldUpdate(); + void testRotate(int16_t degree); + void endRotate(); + void switchLoopMode() { this->loopMode = !this->loopMode; } + bool getLoopMode() const { return this->loopMode; } - Navigation* navigation = nullptr; - CourseCorrection courseCorrection{0, 0}; - RouteInfo routeInfo{0, 0}; - State state = State::None; - State lastState = State::None; - Navigation::Status lastOrderStatus; - DirectionChangeSignal* directionChangeSignal = nullptr; +private: + void init(); + void drive(); + void beginRotate(); + void rotate(); + void run() override; + void checkButtonInput(); + void askNavigationForOrder(); + void selfDriving(); + void restartLoop(); + void afterActivate() override; - bool updateDisplay = false; - bool loopMode = false; + Navigation *navigation = nullptr; + CourseCorrection courseCorrection{0, 0}; + RouteInfo routeInfo{0, 0}; + State state = State::None; + State lastState = State::None; + Navigation::Status lastOrderStatus; + DirectionChangeSignal *directionChangeSignal = nullptr; - uint8_t maxCourseDeviationBeforeAct = 5; - uint16_t autopilotChangeDelayMillis = 500; - uint32_t lastAutopilotChangeMillis = 0; + bool updateDisplay = false; + bool loopMode = false; - int16_t rotationAimAzimuth = 0; + uint8_t maxCourseDeviationBeforeAct = 5; + uint16_t autopilotChangeDelayMillis = 500; + uint32_t lastAutopilotChangeMillis = 0; - double minRemainingDistance = 0.25; + int16_t rotationAimAzimuth = 0; + + double minRemainingDistance = 0.25; }; -class DirectionChangeSignal : public DirectionChangeWrapper { - public: - DirectionChangeSignal(Autopilot* pilot); - ~DirectionChangeSignal(); - void action() override; +class DirectionChangeSignal : public DirectionChangeWrapper +{ +public: + DirectionChangeSignal(Autopilot *pilot); + ~DirectionChangeSignal(); + void action() override; - private: - Autopilot* pilot; +private: + Autopilot *pilot; }; #endif // AUTOPILOT_H diff --git a/src/driveModi/Modi/CalibrateCompass/calibrateCompassM.cpp b/src/driveModi/Modi/CalibrateCompass/calibrateCompassM.cpp index 81a970e..f4a2bd4 100644 --- a/src/driveModi/Modi/CalibrateCompass/calibrateCompassM.cpp +++ b/src/driveModi/Modi/CalibrateCompass/calibrateCompassM.cpp @@ -1,22 +1,25 @@ /** * @file calibrateCompassM.cpp * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief * @version 0.1 * @date 2023-09-03 - * + * * @copyright Copyright (c) 2023 - * + * */ #include "calibrateCompassM.h" - -void CalibrateCompassM::setCalibrateCompass(CalibrateCompass *caliCompass) { - if (static_cast(caliCompass)) { +void CalibrateCompassM::setCalibrateCompass(CalibrateCompass *caliCompass) +{ + if (static_cast(caliCompass)) + { this->caliCompass = caliCompass; this->addChildComponent(this->caliCompass); - } else if (static_cast(this->caliCompass)) { + } + else if (static_cast(this->caliCompass)) + { this->removeChildComponent(this->caliCompass); this->caliCompass = caliCompass; } diff --git a/src/driveModi/Modi/CalibrateCompass/calibrateCompassM.h b/src/driveModi/Modi/CalibrateCompass/calibrateCompassM.h index 753bbc1..50ef4f7 100644 --- a/src/driveModi/Modi/CalibrateCompass/calibrateCompassM.h +++ b/src/driveModi/Modi/CalibrateCompass/calibrateCompassM.h @@ -1,12 +1,12 @@ /** * @file calibrateCompassM.h * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains a Menu class to calibrate the compass * @version 0.1 * @date 2023-09-03 - * + * * @copyright Copyright (c) 2023 - * + * */ #ifndef CALIBRATE_COMPASS_M_H @@ -16,12 +16,21 @@ #include "driveModi/Modi/ManualControl/manualControl.h" -class CalibrateCompassM : public ManualControl { - public: - void setCalibrateCompass(CalibrateCompass* caliCompass = nullptr); +/** + * @brief A Menu class to interact with CalibrateCompass class + */ +class CalibrateCompassM : public ManualControl +{ +public: + /** + * @brief Set the CalibrateCompass object + * + * @param caliCompass + */ + void setCalibrateCompass(CalibrateCompass *caliCompass = nullptr); - private: - CalibrateCompass* caliCompass = nullptr; +private: + CalibrateCompass *caliCompass = nullptr; }; -#endif //CALIBRATE_COMPASS_M_H +#endif // CALIBRATE_COMPASS_M_H diff --git a/src/driveModi/Modi/CaptureRoute/captureRoute.h b/src/driveModi/Modi/CaptureRoute/captureRoute.h index 48caa1a..d60dd03 100644 --- a/src/driveModi/Modi/CaptureRoute/captureRoute.h +++ b/src/driveModi/Modi/CaptureRoute/captureRoute.h @@ -4,9 +4,9 @@ * @brief Contains a class to capture a driven route * @version 0.1 * @date 2022-02-15 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef CAPTURE_ROUTE_H @@ -19,61 +19,57 @@ /** * @brief A class to capture a driven class - * + * * This class inherits ManualControl so you can drive * normally as in ManualControl. If GPS signal is valid * you can add a Point everytime you want. - * + * */ -class CaptureRoute : public ManualControl { - public: - /** - * @brief Destroy the Capture Route object - * - * Disconnect the NTRIP-Client - */ - ~CaptureRoute(); +class CaptureRoute : public ManualControl +{ +public: + /** + * @brief Destroy the Capture Route object + * + * Disconnect the NTRIP-Client + */ + ~CaptureRoute(); - // /** - // * @brief Get the Navigation object - // * - // * @return Navigation* - // */ - // Navigation* getNavigation() const { return this->navigation; } + /** + * @brief Get the Route Info object + * + * @return RouteInfo + */ + RouteInfo getRouteInfo() const { return this->routeInfo; } - /** - * @brief Get the Route Info object - * - * @return RouteInfo - */ - RouteInfo getRouteInfo() const { return this->routeInfo; } - Navigation::Status getLastStatus() const { return this->status; } - Navigation* getNavigation() const { return this->navigation; } + Navigation::Status getLastStatus() const { return this->status; } + Navigation *getNavigation() const { return this->navigation; } - /** - * @brief Get the distance to the last saved oint - * - * @return double in meters - */ - double getDistanceToLastPoint() const; + /** + * @brief Get the distance to the last saved oint + * + * @return double in meters + */ + double getDistanceToLastPoint() const; - /** - * @brief Tells if there are new informations to display - * - * @return true - * @return false - */ - bool shouldUpdate(); - private: - void run() override; - void afterActivate() override; + /** + * @brief Tells if there are new informations to display + * + * @return true + * @return false + */ + bool shouldUpdate(); - Navigation* navigation = nullptr; - RouteInfo routeInfo; - Point lastSavedPoint; - Navigation::Status status = Navigation::Status::Complete; +private: + void run() override; + void afterActivate() override; - bool updateDisplay = false; + Navigation *navigation = nullptr; + RouteInfo routeInfo; + Point lastSavedPoint; + Navigation::Status status = Navigation::Status::Complete; + + bool updateDisplay = false; }; #endif // CAPTURE_ROUTE_H diff --git a/src/driveModi/Modi/ManualControl/manualControl.h b/src/driveModi/Modi/ManualControl/manualControl.h index bcda7df..319f1d3 100644 --- a/src/driveModi/Modi/ManualControl/manualControl.h +++ b/src/driveModi/Modi/ManualControl/manualControl.h @@ -4,53 +4,70 @@ * @brief A small class to drive the Rover by the controller joystick. * @version 0.1 * @date 2021-12-13 - * + * * @copyright Copyright (c) 2021 - * + * */ #ifndef MANUAL_CONTROL_H #define MANUAL_CONTROL_H #include "driveModi/driveModi.h" -class DirectionChangeWrapper { - public: - virtual void action() = 0; +class DirectionChangeWrapper +{ +public: + virtual void action() = 0; }; /** * @brief Drive the Rover with a Joystick - * - * This class gets the x and y value from the PS3 controller + * + * This class gets the x and y value from the ControlPad * and map the values to moveControl - * + * * @see MoveControl */ -class ManualControl : public DriveModi { - public: - enum class InputMode : uint8_t { - Analog, - Digital - }; +class ManualControl : public DriveModi +{ +public: + /** + * @brief The enum is used to change the interpretation of the joystick data + */ + enum class InputMode : uint8_t + { + Analog, + Digital + }; - void switchInputMode(); - void setInputMode(InputMode mode) { this->inputMode = mode; } - InputMode getInputMode() const { return this->inputMode; } - void setDirectionChangeCallback(DirectionChangeWrapper* callback) { this->directionChangeWrapper = callback; } + /** + * @brief Change the InputMode to the opposite + */ + void switchInputMode(); + void setInputMode(InputMode mode) { this->inputMode = mode; } + InputMode getInputMode() const { return this->inputMode; } - uint16_t getDutycycleLeft() const { return this->moveControl->getDutycycleLeft(); } - uint16_t getDutycycleRight() const { return this->moveControl->getDutycycleRight(); } + /** + * @brief Set the DirectionChangeWrapper object + * + * This callback is used to inform the CalcAzimuth Component about a direction change + * + * @param callback + */ + void setDirectionChangeCallback(DirectionChangeWrapper *callback) { this->directionChangeWrapper = callback; } - protected: - void run() override; + uint16_t getDutycycleLeft() const { return this->moveControl->getDutycycleLeft(); } + uint16_t getDutycycleRight() const { return this->moveControl->getDutycycleRight(); } - private: - void analogControl(); - void digitalControl(); +protected: + void run() override; - bool lastLoopTurned = false; - DirectionChangeWrapper* directionChangeWrapper = nullptr; - InputMode inputMode = InputMode::Analog; +private: + void analogControl(); + void digitalControl(); + + bool lastLoopTurned = false; + DirectionChangeWrapper *directionChangeWrapper = nullptr; + InputMode inputMode = InputMode::Analog; }; #endif // MANUAL_CONTROL_H diff --git a/src/driveModi/Modi/TestMode/testMode.cpp b/src/driveModi/Modi/TestMode/testMode.cpp index 9e26897..afda3dd 100644 --- a/src/driveModi/Modi/TestMode/testMode.cpp +++ b/src/driveModi/Modi/TestMode/testMode.cpp @@ -15,7 +15,8 @@ void TestMode::run() if (this->maneuver == Maneuver::Turn) { uint16_t delta = abs(this->azimuth - this->getSensorData()->getRealAzimuth()); - if (delta > this->degree) { + if (delta > this->degree) + { this->abort = true; } } @@ -31,7 +32,8 @@ void TestMode::run() bool TestMode::drive(int16_t cmDistance, int16_t degree) { - if (this->busy){ + if (this->busy) + { return false; } @@ -43,10 +45,12 @@ bool TestMode::drive(int16_t cmDistance, int16_t degree) // Only left or right this->moveControl->setSpeed(0); - if (degree < 0){ + if (degree < 0) + { this->moveControl->setRotationSpeed(-this->maxSpeeds.rot); } - else if (degree > 0){ + else if (degree > 0) + { this->moveControl->setRotationSpeed(this->maxSpeeds.rot); } @@ -62,10 +66,12 @@ bool TestMode::drive(int16_t cmDistance, int16_t degree) // Only forward or backward this->moveControl->setRotationSpeed(0); - if (cmDistance < 0){ + if (cmDistance < 0) + { this->moveControl->setSpeed(-this->maxSpeeds.x); } - else if (cmDistance > 0){ + else if (cmDistance > 0) + { this->moveControl->setSpeed(this->maxSpeeds.x); } @@ -78,10 +84,12 @@ bool TestMode::drive(int16_t cmDistance, int16_t degree) { // forward or backward and left or right // TODO: Calculate roationspeed - if (cmDistance < 0){ + if (cmDistance < 0) + { this->moveControl->setSpeed(-this->maxSpeeds.x); } - else if (cmDistance > 0){ + else if (cmDistance > 0) + { this->moveControl->setSpeed(this->maxSpeeds.x); } @@ -137,7 +145,8 @@ void TestMode::abortManeuver() uint8_t TestMode::getRemainingManeuverTime() const { - if (this->busy){ + if (this->busy) + { return static_cast((this->maneuverTime - (millis() - this->actionStart)) / 1000); } return 0; @@ -145,13 +154,16 @@ uint8_t TestMode::getRemainingManeuverTime() const bool TestMode::engineInit(int16_t powerPercentage, int16_t seconds) { - if (this->busy){ + if (this->busy) + { return false; } - if (powerPercentage > TestMode::maxPercentage || powerPercentage < -TestMode::maxPercentage){ + if (powerPercentage > TestMode::maxPercentage || powerPercentage < -TestMode::maxPercentage) + { return false; } - if (seconds < 0){ + if (seconds < 0) + { return false; } diff --git a/src/driveModi/Modi/TestMode/testMode.h b/src/driveModi/Modi/TestMode/testMode.h index bb49794..f82a493 100644 --- a/src/driveModi/Modi/TestMode/testMode.h +++ b/src/driveModi/Modi/TestMode/testMode.h @@ -26,7 +26,6 @@ class TestMode : public DriveModi public: /** * @brief Different states to test the engine - * */ enum Maneuver { @@ -38,6 +37,14 @@ public: Drive }; + /** + * @brief Let the rover drive + * + * @param cmDistance to drive + * @param degree degree to rotate over the hole distance + * @return true + * @return false + */ bool drive(int16_t cmDistance = 0, int16_t degree = 0); /** @@ -89,6 +96,7 @@ public: * @return false */ bool getBusy() const { return this->busy; } + Maneuver getManeuver() const { return this->maneuver; } Speedometer *getSpeedometerLeft() const { return this->moveControl->getSpeedometerLeft(); } Speedometer *getSpeedometerRight() const { return this->moveControl->getSpeedometerRight(); } diff --git a/src/driveModi/driveManager.h b/src/driveModi/driveManager.h index 1050a34..f3f014a 100644 --- a/src/driveModi/driveManager.h +++ b/src/driveModi/driveManager.h @@ -4,9 +4,9 @@ * @brief Contains a class to switch the DriveModi * @version 0.1 * @date 2021-12-14 - * + * * @copyright Copyright (c) 2021 - * + * */ #ifndef DRIVE_MANAGER_H @@ -20,58 +20,61 @@ #include "component.h" #include "sensorData.h" -class DriveManager : public Component { - public: +/** + * @brief A class to manage and hold the different DriveModi + * + */ +class DriveManager : public Component +{ +public: + /** + * @brief Construct a new Drive Manager object + * + * @param moveControl + * @param sensorData + * @param input + */ + DriveManager(MoveControl *moveControl, const SensorData *sensorData, const ControlPadInput *input); - /** - * @brief Construct a new Drive Manager object - * - * @param moveControl - * @param sensorData - * @param input - */ - DriveManager(MoveControl *moveControl, const SensorData* sensorData, const ControlPadInput *input); + /** + * @brief Construct a new Drive Manager object + * + * @param params + */ + DriveManager(DriveModiParams params); - /** - * @brief Construct a new Drive Manager object - * - * @param params - */ - DriveManager(DriveModiParams params); + /** + * @brief Change the DriveModi to a specific value + * + * Sets MoveControl to a safe state, delete the last + * DriveModi and than set the new DriveModi + * + * @param modus + */ + void changeModus(DriveModi *modus = nullptr); - /** - * @brief Change the DriveModi to a specific value - * - * Sets MoveControl to a safe state, delete the last - * DriveModi and than set the new DriveModi - * - * @param modus - */ - void changeModus(DriveModi* modus = nullptr); + /** + * @brief Get the DriveModi Ptr object + * + * This is a pointer to the Object of the current DriveMode. + * If you know which DriveMode is active, you can cast this + * pointer to it. + * + * @see getDriveModi + * @return DriveModi* + */ + DriveModi *getDriveModiPtr() const { return this->currentModusPtr; } + DrivingSpeeds &getDrivingSpeedsRef() { return this->drivingSpeeds; } - /** - * @brief Get the DriveModi Ptr object - * - * This is a pointer to the Object of the current DriveMode. - * If you know which DriveMode is active, you can cast this - * pointer to it. - * - * @see getDriveModi - * @return DriveModi* - */ - DriveModi* getDriveModiPtr() const { return this->currentModusPtr; } - DrivingSpeeds& getDrivingSpeedsRef() { return this->drivingSpeeds; } + bool isActive() const { return this->currentModusPtr; } - bool isActive() const { return this->currentModusPtr; } +private: + void run() override{}; + void init(); - private: - void run() override {}; - void init(); - - DriveModi *currentModusPtr = nullptr; - DriveModiParams driveModiParams; - DrivingSpeeds drivingSpeeds = {1, 7}; + DriveModi *currentModusPtr = nullptr; + DriveModiParams driveModiParams; + DrivingSpeeds drivingSpeeds = {1, 7}; }; - #endif // DRIVE_MANAGER_H diff --git a/src/driveModi/driveModi.cpp b/src/driveModi/driveModi.cpp index ef573d3..37a75c5 100644 --- a/src/driveModi/driveModi.cpp +++ b/src/driveModi/driveModi.cpp @@ -1,26 +1,30 @@ #include "driveModi.h" -DriveModi::~DriveModi() { +DriveModi::~DriveModi() +{ this->moveControl->setSpeed(0); this->moveControl->setRotationSpeed(0); this->moveControl->setDrivingStatus(MoveControl::Status::Stop); } -void DriveModi::activate(MoveControl* moveControl, ControlPadInput* input, SensorData* sensorData) { +void DriveModi::activate(MoveControl *moveControl, ControlPadInput *input, SensorData *sensorData) +{ this->moveControl = moveControl; this->input = input; this->sensorData = sensorData; this->init(); } -void DriveModi::activate(DriveModiParams params){ +void DriveModi::activate(DriveModiParams params) +{ this->moveControl = params.moveControl; this->input = params.input; this->sensorData = params.sensorData; this->init(); } -void DriveModi::init() { +void DriveModi::init() +{ this->moveControl->setDrivingStatus(MoveControl::Status::Drive); this->loopDelay = DriveModi::defaultDelay; this->afterActivate(); diff --git a/src/driveModi/driveModi.h b/src/driveModi/driveModi.h index daa6749..ba40324 100644 --- a/src/driveModi/driveModi.h +++ b/src/driveModi/driveModi.h @@ -4,9 +4,9 @@ * @brief Contains a virtual class for all Modi * @version 0.1 * @date 2021-12-14 - * + * * @copyright Copyright (c) 2021 - * + * */ #ifndef DRIVEMODI_H @@ -17,42 +17,64 @@ #include "controlPadInput.h" #include "sensorData.h" -struct DriveModiParams { - MoveControl* moveControl; - const ControlPadInput* input; - const SensorData* sensorData; +/** + * @brief The struct contains all objects needed by a DriveMode + */ +struct DriveModiParams +{ + MoveControl *moveControl; + const ControlPadInput *input; + const SensorData *sensorData; }; /** * @brief Baseclass to build DriveModi - * + * * This class must be inherited by other classes which want to be * act as a DriveModi, because the DriveModi structure uses polymorphism. */ -class DriveModi : public Component { - public: - virtual ~DriveModi(); +class DriveModi : public Component +{ +public: + virtual ~DriveModi(); - const SensorData* getSensorData() const { return this->sensorData; } + const SensorData *getSensorData() const { return this->sensorData; } - void activate(MoveControl* moveControl, ControlPadInput* input, SensorData* sensorData); - void activate(DriveModiParams params); + /** + * @brief This activates a DriveMode + * + * This function have to be called to provide the DriveMode + * with this objects + * + * @param moveControl + * @param input + * @param sensorData + */ + void activate(MoveControl *moveControl, ControlPadInput *input, SensorData *sensorData); + void activate(DriveModiParams params); - void setSpeeds(DrivingSpeeds speeds) { this->maxSpeeds = speeds; } - DrivingSpeeds getSpeeds() const { return this->maxSpeeds; } - DrivingSpeeds& getSpeedsRef() { return this->maxSpeeds; } + void setSpeeds(DrivingSpeeds speeds) { this->maxSpeeds = speeds; } + DrivingSpeeds getSpeeds() const { return this->maxSpeeds; } + DrivingSpeeds &getSpeedsRef() { return this->maxSpeeds; } - protected: - virtual void afterActivate() {} +protected: + /** + * @brief Prepare other things + * + * This function can be overwritten to prepare things + * for the specific DriveModi. This function will be + * called after activate(). + */ + virtual void afterActivate() {} - MoveControl *moveControl = nullptr; - DrivingSpeeds maxSpeeds = {1, 7}; - const ControlPadInput* input = nullptr; - const SensorData* sensorData = nullptr; + MoveControl *moveControl = nullptr; + DrivingSpeeds maxSpeeds = {1, 7}; + const ControlPadInput *input = nullptr; + const SensorData *sensorData = nullptr; - private: - void init(); +private: + void init(); - static constexpr uint8_t defaultDelay = 40; + static constexpr uint8_t defaultDelay = 40; }; #endif // DRIVEMODI_H diff --git a/src/main.cpp b/src/main.cpp index 9c3134f..8fc49a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -92,14 +92,14 @@ void setup() lcd->clear(); lcd->noBacklight(); - network = new Network(static_cast(NetworkConfig::ssid), - static_cast(NetworkConfig::password), + network = new Network(static_cast(NetworkConfig::ssid), + static_cast(NetworkConfig::password), setIPs()); network->activateEspNow(receiveCallback, sendCallback); if (NetworkConfig::mqtt) { - if (network->activateMqtt(static_cast(MqttConfig::user), - static_cast(MqttConfig::password))) + if (network->activateMqtt(static_cast(MqttConfig::user), + static_cast(MqttConfig::password))) { DebugMqtt::init(network->getMqttClient(), Loglevel::debug); debugMqtt = new DebugMqtt("Console"); @@ -125,11 +125,11 @@ void setup() sensorData = new SensorData(); sensorData->enableGnss(spiPort, PinNumbers::gnssSpiCs); sensorData->enableRealCompass(); - sensorData->enableNtrip(static_cast(NtripConfig::host), - NtripConfig::port, - static_cast(NtripConfig::mountPoint), - static_cast(NtripConfig::user), - static_cast(NtripConfig::password)); + sensorData->enableNtrip(static_cast(NtripConfig::host), + NtripConfig::port, + static_cast(NtripConfig::mountPoint), + static_cast(NtripConfig::user), + static_cast(NtripConfig::password)); // sensorData->enableGyroscope(); driveManager = new DriveManager(&moveController, sensorData, controlPad->getControlPadDataPtr()); diff --git a/src/moveControl.cpp b/src/moveControl.cpp index 145a786..6ad879d 100644 --- a/src/moveControl.cpp +++ b/src/moveControl.cpp @@ -17,19 +17,19 @@ MoveControl::MoveControl() leftSpeedometer{new Speedometer(PinNumbers::LeftMotor::encoder, Settings::wheelDiameter, Settings::encoderSteps)}, rightSpeedometer{new Speedometer(PinNumbers::RightMotor::encoder, Settings::wheelDiameter, Settings::encoderSteps)}, leftPid{new PID(&this->wheelspeedLeft, - &this->leftPidOut, - &this->wheelspeedLeftTarget, - Settings::Pid::Left::P, - Settings::Pid::Left::I, - Settings::Pid::Left::D, - DIRECT)}, + &this->leftPidOut, + &this->wheelspeedLeftTarget, + Settings::Pid::Left::P, + Settings::Pid::Left::I, + Settings::Pid::Left::D, + DIRECT)}, rightPid{new PID(&this->wheelspeedRight, - &this->rightPidOut, - &this->wheelspeedRightTarget, - Settings::Pid::Right::P, - Settings::Pid::Right::I, - Settings::Pid::Right::D, - DIRECT)} + &this->rightPidOut, + &this->wheelspeedRightTarget, + Settings::Pid::Right::P, + Settings::Pid::Right::I, + Settings::Pid::Right::D, + DIRECT)} { this->leftPid->SetOutputLimits(Settings::Pid::outMin, Settings::Pid::outMax); this->leftPid->SetSampleTime(Settings::Pid::sampleTime);