diff --git a/.vscode/settings.json b/.vscode/settings.json index 51c1d3c..fa5cb03 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -123,11 +123,13 @@ "Ahnung", "akku", "ardui", + "Baseclass", "blox", "bluedroid", "carr", "CIPO", "COPI", + "Doxygen", "Dutycycle", "gast", "GNSS", @@ -137,9 +139,12 @@ "Keine", "kleiax", "Lebennig", + "microcontroller", + "MQTT", "NMEA", "NMEAGPGGA", "NTRIP", + "pcnt", "pidl", "pidr", "Punica", diff --git a/doc/Doxygen/Doxyfile b/doc/Doxygen/Doxyfile index 3ad1597..b80b40a 100644 --- a/doc/Doxygen/Doxyfile +++ b/doc/Doxygen/Doxyfile @@ -51,7 +51,7 @@ PROJECT_BRIEF = "A small verhicle which should be drive a route with GP # pixels and the maximum width should not exceed 200 pixels. Doxygen will copy # the logo to the output directory. -PROJECT_LOGO = C:/Users/alex1/git/projektarbeit/doc/Doxygen/logo.png +PROJECT_LOGO = logo.png # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is @@ -606,7 +606,7 @@ HIDE_COMPOUND_REFERENCE= NO # will show which file needs to be included to use the class. # The default value is: YES. -SHOW_HEADERFILE = YES +# SHOW_HEADERFILE = YES # If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of # the files that are included by a file in the documentation of that file. @@ -824,7 +824,7 @@ WARN_IF_DOC_ERROR = YES # parameters have no documentation without warning. # The default value is: YES. -WARN_IF_INCOMPLETE_DOC = YES +# WARN_IF_INCOMPLETE_DOC = YES # This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that # are documented, but have no documentation for their parameters or return @@ -1608,7 +1608,7 @@ GENERATE_TREEVIEW = YES # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. -FULL_SIDEBAR = NO +# FULL_SIDEBAR = NO # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. @@ -1691,7 +1691,7 @@ USE_MATHJAX = NO # The default value is: MathJax_2. # This tag requires that the tag USE_MATHJAX is set to YES. -MATHJAX_VERSION = MathJax_2 +# MATHJAX_VERSION = MathJax_2 # When MathJax is enabled you can set the default output format to be used for # the MathJax output. For more details about the output format see MathJax diff --git a/doc/TODO allgemein.txt b/doc/TODO allgemein.txt index 771fbb1..6d6bbdb 100644 --- a/doc/TODO allgemein.txt +++ b/doc/TODO allgemein.txt @@ -28,6 +28,8 @@ Do later: -> update sparkfun gnss auf v3 für SPI korrekturdatenüvbetragung -> Rover Objekt mit Error zustand freeze, damit das wenn möglich auch auf dem Display angezeigt wird. -> ESP und Sensoren in den DeepSleep für Auschalten oder Akkuschutz + -> Doxygen comments + - navigation Do now: diff --git a/doc/latexSnippet.cpp b/doc/latexSnippet.cpp deleted file mode 100644 index ac4c65b..0000000 --- a/doc/latexSnippet.cpp +++ /dev/null @@ -1,9 +0,0 @@ -void KomponenteA::loop() { - this->komponenteB->loop(); - this->komponenteC->loop(); - - if (millis() - this->lastMillis < this->delayMillis) - return; - - this->doSomething(); -} diff --git a/include/Version.h b/include/Version.h index 109f133..99c9ad6 100644 --- a/include/Version.h +++ b/include/Version.h @@ -1,9 +1,8 @@ - // AUTO GENERATED FILE, DO NOT EDIT - #ifndef VERSION - #define VERSION "0.8.36" - #endif - #ifndef BUILD_TIMESTAMP - #define BUILD_TIMESTAMP "2023-08-13 15:13:34.491991" - #endif - \ No newline at end of file +// AUTO GENERATED FILE, DO NOT EDIT +#ifndef VERSION +#define VERSION "1.8.36" +#endif +#ifndef BUILD_TIMESTAMP +#define BUILD_TIMESTAMP "2023-10-13 15:13:34.491991" +#endif diff --git a/include/moveControl.h b/include/moveControl.h index f2a1f08..a10c8a2 100644 --- a/include/moveControl.h +++ b/include/moveControl.h @@ -4,9 +4,9 @@ * @brief Contains the MoveControl class * @version 0.1 * @date 2021-12-14 - * + * * @copyright Copyright (c) 2021 - * + * */ #ifndef MOVE_CONTROL_H #define MOVE_CONTROL_H @@ -22,178 +22,182 @@ #include "debugTimes.h" #include "component.h" - /** * @brief A struct to easy set the speed - * + * */ -struct DrivingSpeeds { +struct DrivingSpeeds +{ double x; double rot; }; /** * @brief This class manages the motors and the encoders - * + * * The class uses two PIDs to control the motors. The PIDs * use the Speedometer class to get the current speed and the * given target speed to calculate a new duty cycle for the motors. - * + * */ -class MoveControl : public Component { - public: - /** - * @brief used to set driving status - * - * When set to stop all motors are set to halt - * When set to Raw the PIDs are not used. The target - * values must be given withe @see setRawPowerLeft and - * @see setRawPowerRight. - * - * Drive is the normal working mode. - * - */ - enum Status {Stop, - Drive, - Raw}; +class MoveControl : public Component +{ +public: + /** + * @brief Used to set driving status + * + * When set to stop all motors are set to halt + * + * When set to Raw the PIDs are not used. The target + * values must be given withe setRawPowerLeft() and + * setRawPowerRight(). + * + * Drive is the normal working mode. + * + */ + enum Status + { + Stop, + Drive, + Raw + }; + /** + * @brief Construct a new Move Control object + * + * Initialize the motors, encoders and PIDs with given + * values in config.h + */ + MoveControl(); - /** - * @brief Construct a new Move Control object - * - * Initialize the motors, encoders and PIDs with given - * values in config.h - */ - MoveControl(); + /** + * @brief Destroy the Move Control object + * + * Stops the motors with emergencyStop() + */ + ~MoveControl(); - /** - * @brief Destroy the Move Control object - * - * Stops the motors with emergencyStop() - */ - ~MoveControl(); + /** + * @brief Set the Status + * + * Control if this component should work normally or with + * raw values for the motors. + * + * @see Status + * @param status + */ + void setDrivingStatus(Status status); - /** - * @brief Set the Status - * - * Control if this component should work normally or with - * raw values for the motors. - * - * @see Status - * @param status - */ - void setDrivingStatus(Status status); + /** + * @brief Stops the engine immediately + * + */ + void emergencyStop(); - /** - * @brief Stops the engine immediately - * - */ - void emergencyStop(); + /** + * @brief Set the target speed + * + * If the given speed is close to zero, then the + * target speed is set to zero. + * @param speed in m/s + */ + void setSpeed(double speed); - /** - * @brief Set the target speed - * - * If the given speed is close to zero, then the - * target speed is set to zero. - * @param speed in m/s - */ - void setSpeed(double speed); + /** + * @brief Set the rotationSpeed + * + * If the given rotationSpeed is close to zero, then the + * target rotationSpeed is set to zero. + * @param speed rad/s + */ + void setRotationSpeed(double speed); - /** - * @brief Set the rotationSpeed - * - * If the given rotationSpeed is close to zero, then the - * target rotationSpeed is set to zero. - * @param speed rad/s - */ - void setRotationSpeed(double speed); + /** + * @brief Set the speeds + * + * This function is a combination of the functions setSpeed() and + * setRotationSpeed(). The struct DrivingSpeeds + * is used for this. + * + * + * @param drivingSpeeds + */ + void setSpeeds(DrivingSpeeds drivingSpeeds); - /** - * @brief Set the speeds - * - * This function is a combination of @see setSpeed and - * @see setRotationSpeed. The struct @see DrivingSpeeds - * is used for this. - * - * @param drivingSpeeds - */ - void setSpeeds(DrivingSpeeds drivingSpeeds); + /** + * @brief Set raw power left + * + * This value has only an effect if the status is raw. + * @see setDrivingStatus + * + * @param power between -100 and 100 + */ + void setRawPowerLeft(int16_t power); - /** - * @brief Set raw power left - * - * This value has only an effect if the status is raw. - * @see setDrivingStatus - * - * @param power between -100 and 100 - */ - void setRawPowerLeft(int16_t power); + /** + * @brief Set the raw power right + * + * This value has only an effect if status is raw. + * + * @param power between -100 and 100 + */ + void setRawPowerRight(int16_t power); - /** - * @brief Set the raw power right - * - * This value has only an effect if status is raw. - * - * @param power between -100 and 100 - */ - void setRawPowerRight(int16_t power); + /** + * @brief Set the pid tunings + * + * @param side 0 -> left, 1 -> right + * @param pPart + * @param iPart + * @param dPart + */ + void setPidTunings(uint8_t side, double pPart, double iPart, double dPart); - /** - * @brief Set the pid tunings - * - * @param side 0 -> left, 1 -> right - * @param pPart - * @param iPart - * @param dPart - */ - void setPidTunings(uint8_t side, double pPart, double iPart, double dPart); + /** + * @brief Returns the PID object of the choosen side. + * + * @param side 0 -> left, 1 -> right + * @return PID* + */ + PID *getPID(uint8_t side) const; - /** - * @brief Returns the PID object of the choosen side. - * - * @param side 0 -> left, 1 -> right - * @return PID* - */ - PID* getPID(uint8_t side) const; + Speedometer *getSpeedometerLeft() const { return this->leftSpeedometer; } + Speedometer *getSpeedometerRight() const { return this->rightSpeedometer; } - Speedometer* getSpeedometerLeft() const { return this->leftSpeedometer; } - Speedometer* getSpeedometerRight() const { return this->rightSpeedometer; } + uint16_t getDutycycleLeft() const { return this->leftMotor->getDutycycle(); } + uint16_t getDutycycleRight() const { return this->rightMotor->getDutycycle(); } - uint16_t getDutycycleLeft() const { return this->leftMotor->getDutycycle(); } - uint16_t getDutycycleRight() const { return this->rightMotor->getDutycycle(); } +private: + void run() override; + static void setSpeedometerDirection(Speedometer *speedometer, double value); + void calcTargetWheelSpeed(); + void regulateMotors(); + void updateCurrentWheelSpeed(); - private: - void run() override; - static void setSpeedometerDirection(Speedometer *speedometer, double value); - void calcTargetWheelSpeed(); - void regulateMotors(); - void updateCurrentWheelSpeed(); + MotorControl *leftMotor; + MotorControl *rightMotor; + Speedometer *leftSpeedometer; + Speedometer *rightSpeedometer; + PID *leftPid; + PID *rightPid; - MotorControl *leftMotor; - MotorControl *rightMotor; - Speedometer *leftSpeedometer; - Speedometer *rightSpeedometer; - PID *leftPid; - PID *rightPid; + Status driving_status = Status::Stop; + DrivingSpeeds drivingSpeeds = {0, 0}; - Status driving_status = Status::Stop; - DrivingSpeeds drivingSpeeds = {0, 0}; + double wheelspeedLeftTarget = 0; + double wheelspeedRightTarget = 0; + double wheelspeedLeft = 0; + double wheelspeedRight = 0; + double leftPidOut = 0; + double rightPidOut = 0; - double wheelspeedLeftTarget = 0; - double wheelspeedRightTarget = 0; - double wheelspeedLeft = 0; - double wheelspeedRight = 0; - double leftPidOut = 0; - double rightPidOut = 0; - - uint8_t overTimeCounter = 0; - uint8_t overTimeMax = 100; - int8_t rawPowerLeft = 0; - int8_t rawPowerRight = 0; - - static constexpr int8_t maxPercentage = 100; - static constexpr float minSpeed = 0.2; - static constexpr uint8_t loopDelay = 20; + uint8_t overTimeCounter = 0; + uint8_t overTimeMax = 100; + int8_t rawPowerLeft = 0; + int8_t rawPowerRight = 0; + static constexpr int8_t maxPercentage = 100; + static constexpr float minSpeed = 0.2; + static constexpr uint8_t loopDelay = 20; }; #endif // MOVE_CONTROL_H diff --git a/include/networkConfig.h b/include/networkConfig.h index 8e28c90..13aac37 100644 --- a/include/networkConfig.h +++ b/include/networkConfig.h @@ -2,14 +2,14 @@ * @file networkConfig.h * @author Alexander Klein (alex@kleiax.de) * @brief Contains the settings for the Network class - * + * * With different defines the location can be choosen. - * + * * @version 0.1 * @date 2022-02-15 - * + * * @copyright Copyright (c) 2022 - * + * */ #include @@ -17,7 +17,8 @@ #define HW1 #ifdef HOTSPOT -namespace NetworkConfig { +namespace NetworkConfig +{ const char ssid[] = "Kleiax Handy"; const char password[] = "12345677"; const char ip[] = "192.168.43.4"; @@ -26,10 +27,11 @@ namespace NetworkConfig { const char dns[] = "8.8.8.8"; const bool mqtt = false; } -#endif //HOTSPOT +#endif // HOTSPOT #ifdef HW1 -namespace NetworkConfig { +namespace NetworkConfig +{ const char ssid[] = "hw1_gast"; const char password[] = "KeineAhnung"; const char ip[] = "192.168.0.4"; @@ -38,11 +40,12 @@ namespace NetworkConfig { const char dns[] = "8.8.8.8"; const bool mqtt = false; } -#endif //HW1 +#endif // HW1 -//Network config Rhede +// Network config Rhede #ifdef RHEDE -namespace NetworkConfig { +namespace NetworkConfig +{ const char ssid[] = "LebennigHuus"; const char password[] = "Punica-699"; const char ip[] = "192.168.11.4"; @@ -51,16 +54,18 @@ namespace NetworkConfig { const char dns[] = "8.8.8.8"; const bool mqtt = true; } -#endif //RHEDE +#endif // RHEDE -namespace MqttConfig { +namespace MqttConfig +{ const char server[] = "192.168.1.7"; const uint16_t port = 1883; const char user[] = "kleiax"; const char password[] = "p?{$_~5%hBM7wrcFkr55KWr#"; } -namespace NtripConfig { +namespace NtripConfig +{ const char host[] = "rtk2go.com"; const uint16_t port = 2101; // const char mountPoint[] = "GER-Dortmund"; diff --git a/lib/Battery/battery.cpp b/lib/Battery/battery.cpp index 8aedcb2..73b77de 100644 --- a/lib/Battery/battery.cpp +++ b/lib/Battery/battery.cpp @@ -37,12 +37,12 @@ void Battery::run() this->readAdcToBuf(); this->loopCounter++; - if (this->loopCounter >= this->calulationDelayMultiplier) + if (this->loopCounter >= this->calculateDelayMultiplier) { this->calculateBatteryVoltage(); this->calculateBatteryPercent(); this->loopCounter = 0; - this->calculatetNewValues = true; + this->calculatedNewValues = true; } } @@ -89,12 +89,12 @@ bool Battery::isBatteryLow(double voltage) const bool Battery::isNewValue() { - if (!this->calculatetNewValues) + if (!this->calculatedNewValues) { return false; } - this->calculatetNewValues = false; + this->calculatedNewValues = false; return true; } @@ -136,7 +136,7 @@ double Battery::calculateInputVoltage() return 0; } - return -this->adcCurveCoeficient[0] * pow(reading, 4) + this->adcCurveCoeficient[1] * pow(reading, 3) - this->adcCurveCoeficient[2] * pow(reading, 2) + this->adcCurveCoeficient[3] * reading + this->adcCurveCoeficient[4]; + return -this->adcCurveCoefficient[0] * pow(reading, 4) + this->adcCurveCoefficient[1] * pow(reading, 3) - this->adcCurveCoefficient[2] * pow(reading, 2) + this->adcCurveCoefficient[3] * reading + this->adcCurveCoefficient[4]; } void Battery::calculateBatteryVoltage() diff --git a/lib/Battery/battery.h b/lib/Battery/battery.h index 2afc17d..c2787a3 100644 --- a/lib/Battery/battery.h +++ b/lib/Battery/battery.h @@ -24,12 +24,20 @@ * * This class reads the voltage from an analog pin to calculate the * charge level of a 3 Cell Li-Poly battery pack. The battery pack have - * to be after a voltage diveder, so that maximum voltage for the + * to be after a voltage divider, so that maximum voltage for the * microcontroller is 3.3 Volt. */ class Battery : public Component { public: + /** + * @brief States when the calibration modes is active + * + * - None means that no calibration is running + * - Reading means that the adc takes multiple values to calculate an average + * - Waiting means that the user has to set the new wanted voltage + * - Finished means that all measurements was taken + */ enum CalibrationState { None, @@ -41,15 +49,25 @@ public: /** * @brief Construct a new Battery object * - * The voltage devider have to be calculated, so that the input + * The voltage divider have to be calculated, so that the input * voltage from 3.3 Volt is never exceeded. It is assumed that * the microcontroller is connected to the second resistor. * * @param pin The analog to read from. - * @param firstResistor First resistor of the voltage devider. - * @param secondResistor Second resistor of the voltage devider. + * @param firstResistor First resistor of the voltage divider. + * @param secondResistor Second resistor of the voltage divider. */ Battery(uint8_t pin, uint32_t firstResistor, uint32_t secondResistor); + + /** + * @brief Construct a new Battery object + * + * With this constructor the real voltage is not calculated with the + * voltage divider but with a table which contains the raw reading from + * the adc mapped to a specific voltage + * + * @param pin + */ Battery(uint8_t pin); /** @@ -79,13 +97,50 @@ public: */ bool isBatteryLow(double voltage) const; + /** + * @brief Check if a new voltage was been calculated + * + * @return true + * @return false + */ bool isNewValue(); // Calibration CalibrationState getCalibrationState() const { return this->calibrationState; } + + /** + * @brief Get the current calibration voltage target + * + * The returned value stand for the index of the table for this reason + * the real value have to be calculated. After the returned voltage has been set + * you have to call nextVoltageIsReady(). + * + * @return uint8_t voltage multiply with 0,1 and add 7 + */ uint8_t getCurrentCalibrationVoltage() const { return this->currentCalibrationVoltage; } + + /** + * @brief Read next wanted voltage + * + * If this function is called, the calibration mode reads the new voltage + * and save the value in the table. + */ void nextVoltageIsReady(); + + /** + * @brief Calibrate the battery readings + * + * This calibration has only an effect if the Component + * uses the table with the raw adc values. The calibration gives + * the user different voltages that have to be set with a + * laboratory power supply. The power supply have to be connected + * instead of the battery. + */ void startCalibration(); + + /** + * @brief abort the calibration + */ void finishCalibration(); private: @@ -109,14 +164,14 @@ private: uint8_t batteryPercent = 0; uint8_t batteryLowPercent = 10; uint8_t bufferPos = 0; - uint8_t calulationDelayMultiplier = 5; + uint8_t calculateDelayMultiplier = 5; uint8_t loopCounter = 0; uint8_t currentCalibrationVoltage = 0; // *0.1 + 7 uint16_t adcBuffer[bufferSize]; uint16_t *newRawAdcVoltages = nullptr; uint32_t firstResistor = 0; uint32_t secondResistor = 0; - bool calculatetNewValues = false; + bool calculatedNewValues = false; double batteryVoltage = 0; double batteryVoltageFactor; @@ -137,11 +192,11 @@ private: 2920, 2956, 2983, 3019, 3054, 3088, 3121, 3158, 3189, 3226, 3264, 3300, 3339, 3379, 3414, 3453, 3500, 3544, 3598, 3636, 3682, 3730, 3781, 3837, 3887, 3943, 3997, 4054, 4093, 4095}; - const double adcCurveCoeficient[5] = {0.000000000000016, - 0.000000000118171, - 0.000000301211691, - 0.001109019271794, - 0.034143524634089}; + const double adcCurveCoefficient[5] = {0.000000000000016, + 0.000000000118171, + 0.000000301211691, + 0.001109019271794, + 0.034143524634089}; }; #endif // BATTERY_H diff --git a/lib/CalcAzimuth/calcAzimuth.h b/lib/CalcAzimuth/calcAzimuth.h index c3aa08d..4b18315 100644 --- a/lib/CalcAzimuth/calcAzimuth.h +++ b/lib/CalcAzimuth/calcAzimuth.h @@ -1,7 +1,7 @@ /** * @file calcAzimuth.h * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains a class that calculates the azimuth from a last and a current position * @version 0.1 * @date 2023-09-03 * @@ -15,9 +15,18 @@ #include "component.h" #include "point.h" +/** + * @brief A class to calculate an azimuth + * + * This class calculates the current Azimuth with the last position + * where the rover has been rotated and the current position + */ class CalcAzimuth : public Component { public: + /** + * @brief States which represent the quality of the current calculated azimuth + */ enum State { Invalid, @@ -27,13 +36,40 @@ public: Super }; + /** + * @brief Construct a new Calc Azimuth object + * + * @param point current position + */ CalcAzimuth(Point point); + /** + * @brief Have to be called if the rover rotates + * + * @param point current position + */ void drivingDirectionChange(Point point); + + /** + * @brief update the current position + * + * This function should be called if the rover has moved in + * a straight direction, to calculated the current Azimuth. + * More distance to the point given to drivingDirectionChange() + * increase the accuracy of the calculation. + * + * @param point current position + */ void updateCurrentPosition(Point point); void disableCalcAzimuth() { this->directionChangeMode = false; } int16_t getAzimuth() const { return this->calcAzimuth; } + + /** + * @brief Get the State struct + * + * @return State current quality of the calculation + */ State getState() const { return this->state; } static String stateToString(State state); diff --git a/lib/calibrateCompass/calibrateCompass.cpp b/lib/CalibrateCompass/calibrateCompass.cpp similarity index 100% rename from lib/calibrateCompass/calibrateCompass.cpp rename to lib/CalibrateCompass/calibrateCompass.cpp diff --git a/lib/CalibrateCompass/calibrateCompass.h b/lib/CalibrateCompass/calibrateCompass.h new file mode 100644 index 0000000..f5ce2da --- /dev/null +++ b/lib/CalibrateCompass/calibrateCompass.h @@ -0,0 +1,110 @@ +/** + * @file calibrateCompass.h + * @author Alexander Klein (alex@kleiax.de) + * @brief Contains a class to calibrate the compass module + * @version 0.1 + * @date 2023-05-23 + * + * @copyright Copyright (c) 2023 + * + */ + +#pragma once + +#include +#include +#include + +#include "component.h" + +/** + * @brief A Class to calibrate the compass + * + * This class reads the raw values of the compass while + * the rove have to be moved. The lowest and highest values + * are used to calibrate the compass to the current location. + */ +class CalibrateCompass : public Component +{ +public: + /** + * @brief State of the calibration process + */ + enum State + { + Ready, + Calibrating, + Finished + }; + + /** + * @brief Type for calibration data + * + * The data consist of 6 values. For each for the 3 axis + * are to integer needed. + */ + struct CalibrationData + { + int data[3][2]; + }; + + CalibrateCompass(QMC5883LCompass *compass); + + /** + * @brief Starts the calibration + */ + void start(); + + /** + * @brief Use the measured calibration data + */ + void useData(); + + /** + * @brief Remove the measured calibration data + */ + void removeCalibration(); + + /** + * @brief Reset the calibration process to start again + */ + void reset(); + + /** + * @brief Save the measured calibration data to the flash + */ + void saveData(); + + /** + * @brief Load the measured calibration data from the flash + * + */ + void loadData(); + + State getState() const { return this->state; } + CalibrationData getCalibrationData() const { return this->data; } + + /** + * @brief Makes the calibration data printable with std::cout() + * + * @param stream + * @param caliComp + * @return std::ostream& + */ + friend std::ostream &operator<<(std::ostream &stream, const CalibrateCompass &caliComp); + +private: + void runAsChild() override; + void run() override; + void checkDataValidity(); + + QMC5883LCompass *compass; + State state = State::Ready; + CalibrationData data{}; + + void clearData(); + + bool dataValid = false; + const uint16_t maxTimeWithoutChange = 10000; + uint32_t lastChange = 0; +}; diff --git a/lib/Component/component.cpp b/lib/Component/component.cpp index 8bf2ab5..0595c77 100644 --- a/lib/Component/component.cpp +++ b/lib/Component/component.cpp @@ -19,7 +19,7 @@ void Component::loop() (*it)->loop(); } } - this->runAsChild(); + this->runAsChild();F if (this->onlyChilds) { diff --git a/lib/Component/component.h b/lib/Component/component.h index 7e4b93a..bf37591 100644 --- a/lib/Component/component.h +++ b/lib/Component/component.h @@ -1,7 +1,7 @@ /** * @file component.h * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains an interface to make non blocking components with delay. * @version 0.1 * @date 2023-08-16 * @@ -15,31 +15,123 @@ #include +/** + * @brief An Interface to make components + * + * A component is a task that be called in a loop which not + * runs every loop, so every component has a non blocking delay. + * + * A component can manage other components which called children components. + */ class Component { public: + /** + * @brief Construct a new Component object + * + * With the default constructor the created component is + * by default inactive. This does not affect the execution of + * the children components. + */ Component() {} + + /** + * @brief Construct a new Component object + * + * If the given parameter is zero, there are no differences to the + * default constructor. + * + * @param loopDelay the minimum time in milliseconds before the task runs + */ Component(uint16_t loopDelay); + /** + * @brief Runs the children components and the task + * + * The loop() function of the children is called every time this + * loop is called. + * + * The run() function which presents the task of this component is + * only called if the delay is reached. + */ void loop(); + /** + * @brief Deactivate this component + * + * If the component is deactivated the call of loop() ha no effect + */ void deactivate() { this->active = false; } void activate() { this->active = false; } protected: + /** + * @brief Override this function to avoid the delay + */ virtual void runAsChild() {} + + /** + * @brief Runs befor the run() function + * + * This function is only called, if the delay + * is reached. + * The function do nothing, except the function is overwritten + * by the class which inherits this class. + */ virtual void beforeRun() {} + + /** + * @brief The actual task + * + * This function have to be overwritten by the inheriting class. + */ virtual void run() = 0; + + /** + * @brief Runs after the run() function + * + * This function is only called, if the delay + * is reached. + * The function do nothing, except the function is overwritten + * by the class which inherits this class. + */ virtual void afterRun() {} + /** + * @brief Adds a child component + * + * The child component will be called every time the loop() function + * is called. + * + * @param child + */ void addChildComponent(Component *child); void removeChildComponent(Component *child); void activateOnlyChilds() { this->onlyChilds = true; } + + /** + * @brief Skip the actual task + * + * Same as set the loopDelay to zero. + */ void deactivateOnlyChilds() { this->onlyChilds = false; } + /** + * @brief Set the timer after task + * + * If this function is called once the measurement of the delay + * starts after task has finished. The default is, that the + * measurement begins at the start of the task. + */ void setTimerAfterTask() { this->timeUpdateAfter = true; } + /** + * @brief the minimum time in milliseconds before the task runs + * + * If this value is zero, the functions beforeRun(), run() and + * afterRun() would not be called + */ uint16_t loopDelay = 0; private: diff --git a/lib/ControllPad/controlPad.cpp b/lib/ControllPad/controlPad.cpp index 737ae6c..9fcf9ae 100644 --- a/lib/ControllPad/controlPad.cpp +++ b/lib/ControllPad/controlPad.cpp @@ -11,7 +11,7 @@ #include "controlPad.h" -ControlPad::ControlPad() : Component(5), controlInput{0, 0, 0, 0} {} +ControlPad::ControlPad() : Component(10), controlInput{0, 0, 0, 0} {} void ControlPad::run() { diff --git a/lib/ControllPad/controlPad.h b/lib/ControllPad/controlPad.h index 1df2ba2..c0f0904 100644 --- a/lib/ControllPad/controlPad.h +++ b/lib/ControllPad/controlPad.h @@ -1,7 +1,7 @@ /** * @file controlPad.h * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains a class that gets the input data * @version 0.1 * @date 2023-03-30 * @@ -16,15 +16,46 @@ #include #include +/** + * @brief A class to manage inputs + * + * This class converts the incoming data to the buttons and + * the axis from the joystick. The converted data will be send + * to the menu. + */ class ControlPad : public Component { public: ControlPad(); + /** + * @brief Insert the incoming data to convert + * + * The data is converted to the ControlPadInput struct. + * + * @param data have to be 4 byte long + */ void insertData(const uint8_t *data); + /** + * @brief Set the MenuControl object + * + * The MenuControl object is used to control the Menu. + * + * @see Menu + * @see ControlPadInput + * + * @param menuControl + */ void setMenuControl(MenuControl *menuControl) { this->menuControl = menuControl; } + /** + * @brief Get the Control Pad Data + * + * The pointer holds the lates data from the ControlPad + * + * @return const ControlPadInput* + */ const ControlPadInput *getControlPadDataPtr() const { return &this->controlInput; } bool isControlPadConnected() const { return this->connected; } diff --git a/lib/Counter/counter.h b/lib/Counter/counter.h index 34579e6..74c96b6 100644 --- a/lib/Counter/counter.h +++ b/lib/Counter/counter.h @@ -1,21 +1,65 @@ +/** + * @file counter.h + * @author Alexander Klein (alex@kleiax.de) + * @brief Contains a class that abstract the hardware counter from the esp32 + * @version 0.1 + * @date 2023-10-12 + * + * @copyright Copyright (c) 2023 + * + */ #pragma once #include #include #include +/** + * @brief A class that abstract the hardware counter from the esp32 + */ class Counter { public: + /** + * @brief Construct a new Counter object + * + * @param pin with incoming pulses + */ Counter(uint8_t pin); + /** + * @brief Pause the pulse counting + */ void pause(); + + /** + * @brief Resume the pulse counting + */ void resume(); + + /** + * @brief Start counting by zero again + */ void clear(); + /** + * @brief Get the counted pulses + * + * @return int16_t + */ int16_t getValue() const; + /** + * @brief Set the filter value + * + * The filter skip all pulses after a pulse for the filter time. + * The filter time depends on the frequency of the processor. The time + * for a whole tact multiplied with the filter value results the filter time. + * + * @param value max 1023 + */ void setFilterValue(uint16_t value); + void filterEnable(); void filterDisable(); @@ -26,7 +70,7 @@ private: static uint8_t amountOfCounter; - bool initalised = false; + bool initalized = false; uint8_t pulsePin; pcnt_unit_t unit; diff --git a/lib/LcdWrapper/LcdWrapper.cpp b/lib/LcdWrapper/LcdWrapper.cpp index 4d48230..80d66db 100644 --- a/lib/LcdWrapper/LcdWrapper.cpp +++ b/lib/LcdWrapper/LcdWrapper.cpp @@ -1,5 +1,5 @@ /** - * @file displayWrapper.cpp + * @file LcdWrapper.cpp * @author Alexander Klein (alex@kleiax.de) * @brief Contains the implementation of the class LcdWrapper * @version 0.1 diff --git a/lib/LcdWrapper/LcdWrapper.h b/lib/LcdWrapper/LcdWrapper.h index dd19cc5..e000fef 100644 --- a/lib/LcdWrapper/LcdWrapper.h +++ b/lib/LcdWrapper/LcdWrapper.h @@ -1,5 +1,5 @@ /** - * @file displayWrapper.h + * @file LcdWrapper.h * @author Alexander Klein (alex@kleiax.de) * @brief Contains the LcdWrapper class * @version 0.1 @@ -37,7 +37,6 @@ public: /** * @brief Empty the buffer - * */ void clear() override; diff --git a/lib/MQTT/debugMqtt.cpp b/lib/MQTT/debugMqtt.cpp index 3de8e95..e042414 100644 --- a/lib/MQTT/debugMqtt.cpp +++ b/lib/MQTT/debugMqtt.cpp @@ -5,101 +5,115 @@ * @see debugMqtt.h * @version 0.1 * @date 2021-12-13 - * + * * @copyright Copyright (c) 2021 - * + * */ #include "debugMqtt.h" -PubSubClient* DebugMqtt::client; +PubSubClient *DebugMqtt::client; Loglevel DebugMqtt::loglevel; bool DebugMqtt::isInit = false; char DebugMqtt::msg[MQTT_BUFFER_SIZE]; char DebugMqtt::topic[MQTT_BUFFER_SIZE]; - -DebugMqtt::DebugMqtt(const char* name, uint8_t bufSize) - : name {name} +DebugMqtt::DebugMqtt(const char *name, uint8_t bufSize) + : name{name} { - if (bufSize != 0) { + if (bufSize != 0) + { this->bufSize = bufSize; } this->buf = new char[this->bufSize]; } -DebugMqtt::~DebugMqtt() { +DebugMqtt::~DebugMqtt() +{ delete this->buf; } -void DebugMqtt::sendMsg(Loglevel loglevel, String topic, String msg) { - snprintf (static_cast(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast("%s: %s"),this->name ,msg.c_str()); - this->sendData(loglevel, topic, static_cast(DebugMqtt::msg)); +void DebugMqtt::sendMsg(Loglevel loglevel, String topic, String msg) +{ + snprintf(static_cast(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast("%s: %s"), this->name, msg.c_str()); + this->sendData(loglevel, topic, static_cast(DebugMqtt::msg)); } -void DebugMqtt::sendMsg(Loglevel loglevel, String msg) { +void DebugMqtt::sendMsg(Loglevel loglevel, String msg) +{ this->sendMsg(loglevel, "", msg); } -void DebugMqtt::sendData(Loglevel loglevel, String topic, String data) { - if (!DebugMqtt::isInit) { +void DebugMqtt::sendData(Loglevel loglevel, String topic, String data) +{ + if (!DebugMqtt::isInit) + { return; } - if (loglevel <= DebugMqtt::loglevel && loglevel > Loglevel::none) { - snprintf (static_cast(DebugMqtt::topic), MQTT_BUFFER_SIZE, static_cast("%s%s"), DebugMqtt::enum_to_string(loglevel).c_str(), topic.c_str()); - snprintf (static_cast(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast("%s"), data.c_str()); - client->publish(DebugMqtt::topic, static_cast(DebugMqtt::msg)); + if (loglevel <= DebugMqtt::loglevel && loglevel > Loglevel::none) + { + snprintf(static_cast(DebugMqtt::topic), MQTT_BUFFER_SIZE, static_cast("%s%s"), DebugMqtt::enum_to_string(loglevel).c_str(), topic.c_str()); + snprintf(static_cast(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast("%s"), data.c_str()); + client->publish(DebugMqtt::topic, static_cast(DebugMqtt::msg)); } } -void DebugMqtt::sendData(Loglevel loglevel, String data){ +void DebugMqtt::sendData(Loglevel loglevel, String data) +{ DebugMqtt::sendData(loglevel, "", data); } -void DebugMqtt::writeToInflux(String measurement_name, String field_set, float measurement, uint64_t nanos) { +void DebugMqtt::writeToInflux(String measurement_name, String field_set, float measurement, uint64_t nanos) +{ // Example String: "weather temperature=82 1465839830100400200"; - snprintf(static_cast(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast("%s %s=%f %llu"), measurement_name.c_str(), field_set.c_str(), measurement, nanos); - this->sendData(Loglevel::influx, static_cast(DebugMqtt::msg)); + snprintf(static_cast(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast("%s %s=%f %llu"), measurement_name.c_str(), field_set.c_str(), measurement, nanos); + this->sendData(Loglevel::influx, static_cast(DebugMqtt::msg)); } -void DebugMqtt::addCharacter(char character) { +void DebugMqtt::addCharacter(char character) +{ this->buf[this->bufPos] = character; this->bufPos++; - if (character == '\n' || this->bufPos >= this->bufSize - 1) { + if (character == '\n' || this->bufPos >= this->bufSize - 1) + { this->buf[this->bufPos - 1] = '\0'; this->sendMsg(Loglevel::info, buf); this->bufPos = 0; } } -void DebugMqtt::init(PubSubClient *client, Loglevel max_loglevel) { +void DebugMqtt::init(PubSubClient *client, Loglevel max_loglevel) +{ DebugMqtt::client = client; DebugMqtt::loglevel = max_loglevel; DebugMqtt::isInit = true; } -void DebugMqtt::changeLoglevel(Loglevel loglevel) { +void DebugMqtt::changeLoglevel(Loglevel loglevel) +{ DebugMqtt::loglevel = loglevel; } -String DebugMqtt::enum_to_string(Loglevel loglevel) { +String DebugMqtt::enum_to_string(Loglevel loglevel) +{ String topic = ""; topic += MQTT_DEBUG_TOPIC; - switch(loglevel){ - case Loglevel::error : + switch (loglevel) + { + case Loglevel::error: topic += "/Error"; break; - case Loglevel::warn : + case Loglevel::warn: topic += "/Warn"; break; - case Loglevel::info : + case Loglevel::info: topic += "/Info"; break; - case Loglevel::debug : + case Loglevel::debug: topic += "/Debug"; break; - case Loglevel::influx : + case Loglevel::influx: topic += "/Influx"; break; default: @@ -107,5 +121,4 @@ String DebugMqtt::enum_to_string(Loglevel loglevel) { break; } return topic; - } - +} diff --git a/lib/MQTT/debugMqtt.h b/lib/MQTT/debugMqtt.h index 194fd14..bb17640 100644 --- a/lib/MQTT/debugMqtt.h +++ b/lib/MQTT/debugMqtt.h @@ -4,9 +4,9 @@ * @brief Inherits a class to send debug messages over MQTT * @version 0.1 * @date 2021-12-13 - * + * * @copyright Copyright (c) 2021 - * + * */ #ifndef DEBUG_MQTT_H #define DEBUG_MQTT_H @@ -14,10 +14,9 @@ #include #include - /** - * @brief - * + * @brief + * * If you want to change the default topic * to an other value, than you have to define this define * in your code befor you include this File. @@ -28,151 +27,155 @@ /** * @brief Defualt for max message size - * + * * If you want to change the default size of 128 Byte * to an other value, than you have to define this define * in your code befor you include this File. */ #ifndef MQTT_BUFFER_SIZE #define MQTT_BUFFER_SIZE 128 -#endif //MQTT_BUFFER_SIZE +#endif // MQTT_BUFFER_SIZE /** * @brief An enum to set the log level - * + * * The log level is the last part of the MQTT topic. * Unless you give sendMsg() or sendData() a additional * topic as String. - * + * * @see sendMsg() * @see sendData() - * + * */ -enum Loglevel { none, - error, - warn, - info, - debug, - influx}; +enum Loglevel +{ + none, + error, + warn, + info, + debug, + influx +}; /** * @brief A class to send debug messages over MQTT - * + * * This class send debug messages over MQTT with different topics * by the enum Loglevel. Besides that this class supports to send * data via Telegraf into Grafana. - * + * * @see Loglevel */ -class DebugMqtt { - public: - /** - * @brief Construct a new Debug Mqtt object. - * - * @param name A String with send with every Message. - * @param bufSize for the addCharacter function. - */ - DebugMqtt(const char* name, uint8_t bufSize = 0); +class DebugMqtt +{ +public: + /** + * @brief Construct a new Debug Mqtt object. + * + * @param name A String with send with every Message. + * @param bufSize for the addCharacter function. + */ + DebugMqtt(const char *name, uint8_t bufSize = 0); - ~DebugMqtt(); + ~DebugMqtt(); - /** - * @brief Send a Message via MQTT - * - * This function uses sendData to send the given string and - * add the name to the message given by the constructer. - * - * @see sendData() - * @see Loglevel - * - * @param loglevel Loglevel given by the enum Loglevel - * @param topic Additional topic behind loglevel - * @param msg The message to send as String - */ - void sendMsg(Loglevel loglevel, String topic, String msg); - void sendMsg(Loglevel loglevel, String msg); + /** + * @brief Send a Message via MQTT + * + * This function uses sendData to send the given string and + * add the name to the message given by the constructer. + * + * @see sendData() + * @see Loglevel + * + * @param loglevel Loglevel given by the enum Loglevel + * @param topic Additional topic behind loglevel + * @param msg The message to send as String + */ + void sendMsg(Loglevel loglevel, String topic, String msg); + void sendMsg(Loglevel loglevel, String msg); - /** - * @brief Send a Message via MQTT - * - * This function sends the Data via MQTT with the given topic - * from Loglevel or followed by given String topic. - * Normally this function is called by sendMsg() or by - * writeToInflux() - * - * @see sendData() - * @see writeToInflux() - * @see Loglevel - * - * @param loglevel Loglevel given by the enum Loglevel - * @param topic Additional topic behind loglevel - * @param data The message to send as String - */ - static void sendData(Loglevel loglevel, String topic, String data); - static void sendData(Loglevel loglevel, String data); + /** + * @brief Send a Message via MQTT + * + * This function sends the Data via MQTT with the given topic + * from Loglevel or followed by given String topic. + * Normally this function is called by sendMsg() or by + * writeToInflux() + * + * @see sendData() + * @see writeToInflux() + * @see Loglevel + * + * @param loglevel Loglevel given by the enum Loglevel + * @param topic Additional topic behind loglevel + * @param data The message to send as String + */ + static void sendData(Loglevel loglevel, String topic, String data); + static void sendData(Loglevel loglevel, String data); - /** - * @brief Send a Message via MQTT for InfluxDB - * - * This function sends a MQTT message which is intended for - * Telegraf. Telegraf can listen on MQTT messages and put - * them in an Influx Database. - * - * @param measurement_name like a category - * @param field_set the name of the value e.g temperature - * @param measurement the real value - * @param nanos Current time in nanoseconds - */ - void writeToInflux(String measurement_name, String field_set, float measurement, uint64_t nanos); + /** + * @brief Send a Message via MQTT for InfluxDB + * + * This function sends a MQTT message which is intended for + * Telegraf. Telegraf can listen on MQTT messages and put + * them in an Influx Database. + * + * @param measurement_name like a category + * @param field_set the name of the value e.g temperature + * @param measurement the real value + * @param nanos Current time in nanoseconds + */ + void writeToInflux(String measurement_name, String field_set, float measurement, uint64_t nanos); - /** - * @brief Adds a single character to the buf - * - * The buf will be flushed out: - * 1. when the buffer is full - * 2. when the character is '\n' - * - * @param character - */ - void addCharacter(char character); + /** + * @brief Adds a single character to the buf + * + * The buf will be flushed out: + * 1. when the buffer is full + * 2. when the character is '\n' + * + * @param character + */ + void addCharacter(char character); - /** - * @brief Initialize debugMQTT for all instances - * - * You only have to call this function once for your project. - * If you call this function again you overwrite the client and - * the loglevel. If you only want du overwrite the max_loglevel - * use changeLoglevel() - * - * @see changeLoglevel() - * - * @param client PubSubClient - * @param max_loglevel Max loglevel to send. - */ - static void init(PubSubClient* client, Loglevel max_loglevel); + /** + * @brief Initialize debugMQTT for all instances + * + * You only have to call this function once for your project. + * If you call this function again you overwrite the client and + * the loglevel. If you only want du overwrite the max_loglevel + * use changeLoglevel() + * + * @see changeLoglevel() + * + * @param client PubSubClient + * @param max_loglevel Max loglevel to send. + */ + static void init(PubSubClient *client, Loglevel max_loglevel); - /** - * @brief Change loglevel - * - * This function changes the maximum loglevel which be send. - * - * @param loglevel - */ - static void changeLoglevel(Loglevel loglevel); + /** + * @brief Change loglevel + * + * This function changes the maximum loglevel which be send. + * + * @param loglevel + */ + static void changeLoglevel(Loglevel loglevel); - private: - const char* name; - char* buf; - uint8_t bufPos = 0; - uint8_t bufSize = 100; +private: + const char *name; + char *buf; + uint8_t bufPos = 0; + uint8_t bufSize = 100; - static String enum_to_string(Loglevel loglevel); + static String enum_to_string(Loglevel loglevel); - static PubSubClient* client; - static Loglevel loglevel; - static bool isInit; - static char msg[MQTT_BUFFER_SIZE]; - static char topic[MQTT_BUFFER_SIZE]; + static PubSubClient *client; + static Loglevel loglevel; + static bool isInit; + static char msg[MQTT_BUFFER_SIZE]; + static char topic[MQTT_BUFFER_SIZE]; }; #endif // DEBUG_MQTT_H diff --git a/lib/Navigation/navigation.h b/lib/Navigation/navigation.h index cfe7ed6..65d5689 100644 --- a/lib/Navigation/navigation.h +++ b/lib/Navigation/navigation.h @@ -52,9 +52,10 @@ public: }; /** - * @brief Construct a new Navigation object and using I2C + * @brief Construct a new Navigation object * - * @param route with which to navigate + * @param sensorData + * @param route */ Navigation(const SensorData *sensorData, Route *route = nullptr); @@ -89,11 +90,9 @@ public: /** * @brief Get the Course Correction object * - * This should be called by the driver to get new instructions. - * - * @param correction passed as refernce to get the data - * @return true if new correction data provided - * @return false if route is finished + * @param correction + * @param forceUpdate + * @return Status */ Status getCourseCorrection(CourseCorrection &correction, bool forceUpdate = false); diff --git a/lib/Network/network.cpp b/lib/Network/network.cpp index 3479e3e..93ae142 100644 --- a/lib/Network/network.cpp +++ b/lib/Network/network.cpp @@ -21,18 +21,18 @@ Network::Network(const char *ssid, const char *passphrase) this->init(ssid, passphrase); } -Network::Network(const char *ssid, const char *passphrase, NetworkAdresses adresses) - : adresses{adresses} +Network::Network(const char *ssid, const char *passphrase, NetworkAddresses adresses) + : addresses{adresses} { if (!WiFiGenericClass::mode(WIFI_AP_STA)) { std::cout << "Network::connectWiFi failed WiFi.mode" << std::endl; } - if (!WiFi.config(this->adresses.localIP, - this->adresses.gateway, - this->adresses.subnet, - this->adresses.dnsServer)) + if (!WiFi.config(this->addresses.localIP, + this->addresses.gateway, + this->addresses.subnet, + this->addresses.dnsServer)) { std::cout << "STA Failed to configure" << std::endl; } @@ -45,7 +45,7 @@ Network::~Network() delete mqttClient; } -bool Network::activateEspNow(recieveCallbackPtr reci, sendCallbackPtr send) +bool Network::activateEspNow(receiveCallbackPtr reci, sendCallbackPtr send) { if (esp_now_init() != ESP_OK) { @@ -76,7 +76,7 @@ bool Network::activateMqtt(const char *user, const char *passphrase) this->mqttPassphrase = passphrase; this->mqttClient = new PubSubClient(this->wifiClient); - this->mqttClient->setServer(this->adresses.mqttServer, this->adresses.mqttPort); + this->mqttClient->setServer(this->addresses.mqttServer, this->addresses.mqttPort); this->mqttClient->setSocketTimeout(1); if (this->wifiConnected) @@ -116,7 +116,7 @@ uint8_t Network::getCurrentChannel() void Network::runAsChild() { - if (!this->initSucessful) + if (!this->initSuccessful) { return; } @@ -154,21 +154,21 @@ void Network::init(const char *ssid, const char *passphrase) void Network::checkWifi() { - if ((WiFiSTAClass::status() != WL_CONNECTED) && (millis() - this->lastWifiRecoonectAttemp >= Network::wifiReconnectDelay)) + if ((WiFiSTAClass::status() != WL_CONNECTED) && (millis() - this->lastWifiReconnectAttempt >= Network::wifiReconnectDelay)) { std::cout << "Reconnecting to WiFi..." << std::endl; WiFi.disconnect(); this->wifiConnected = WiFi.reconnect(); - this->lastWifiRecoonectAttemp = millis(); + this->lastWifiReconnectAttempt = millis(); } } void Network::checkMqtt() { - if (!this->mqttClient->connected() && millis() - this->lastMqttReconnectAttemp > Network::mqttReconnectDelay) + if (!this->mqttClient->connected() && millis() - this->lastMqttReconnectAttempt > Network::mqttReconnectDelay) { this->mqttConnected = this->connectMqtt(); - this->lastMqttReconnectAttemp = millis(); + this->lastMqttReconnectAttempt = millis(); } if (this->mqttConnected) diff --git a/lib/Network/network.h b/lib/Network/network.h index acd7841..b35d255 100644 --- a/lib/Network/network.h +++ b/lib/Network/network.h @@ -20,10 +20,20 @@ #include #include -typedef void (*recieveCallbackPtr)(const uint8_t *mac, const uint8_t *incomingData, int len); +/** + * @brief Typedef to easy handle the receive Callback + */ +typedef void (*receiveCallbackPtr)(const uint8_t *mac, const uint8_t *incomingData, int len); + +/** + * @brief Typedef to easy handle the send Callback + */ typedef void (*sendCallbackPtr)(const uint8_t *mac_addr, esp_now_send_status_t status); -struct NetworkAdresses +/** + * @brief A Struct to hold all network addresses + */ +struct NetworkAddresses { IPAddress localIP; IPAddress gateway; @@ -33,17 +43,58 @@ struct NetworkAdresses uint16_t mqttPort = 1883; }; +/** + * @brief A class to manage the wireless connections + */ class Network : public Component { public: + /** + * @brief Construct a new Network object + * + * With this constructor the esp gets its ip from a Dhcp server + * + * @param ssid + * @param passphrase + */ Network(const char *ssid, const char *passphrase); - Network(const char *ssid, const char *passphrase, NetworkAdresses adresses); + + /** + * @brief Construct a new Network object + * + * This constructor is used for a static ip setup + * + * @param ssid + * @param passphrase + * @param addresses + */ + Network(const char *ssid, const char *passphrase, NetworkAddresses addresses); ~Network(); - bool activateEspNow(recieveCallbackPtr reci, sendCallbackPtr send); + /** + * @brief Activate ESP-NOW to communicate with the remote Control + * + * @param receive + * @param send + * @return true + * @return false + */ + bool activateEspNow(receiveCallbackPtr receive, sendCallbackPtr send); + + /** + * @brief Activate MQTT to send debug messages + * + * @param user + * @param passphrase + * @return true + * @return false + */ bool activateMqtt(const char *user = nullptr, const char *passphrase = nullptr); + /** + * @brief Print the current used IPs + */ const void printIPs(); bool isWifiConnected() const { return this->wifiConnected; } @@ -61,11 +112,11 @@ private: void checkMqtt(); bool connectMqtt(); - NetworkAdresses adresses; + NetworkAddresses addresses; WiFiClient wifiClient; PubSubClient *mqttClient = nullptr; - bool initSucessful = false; + bool initSuccessful = false; bool wifiConnected = false; bool mqttConnected = false; @@ -73,8 +124,8 @@ private: const char *mqttPassphrase = nullptr; uint8_t broadcastAddress[6] = {0xC8, 0xC9, 0xA3, 0xC8, 0x57, 0x10}; - uint32_t lastWifiRecoonectAttemp = 0; - uint32_t lastMqttReconnectAttemp = 0; + uint32_t lastWifiReconnectAttempt = 0; + uint32_t lastMqttReconnectAttempt = 0; static constexpr uint8_t wifiConnectTimeout = 20; static constexpr uint16_t wifiConnectLoopTime = 500; diff --git a/lib/Point/point.h b/lib/Point/point.h index 3cc4862..b229054 100644 --- a/lib/Point/point.h +++ b/lib/Point/point.h @@ -18,9 +18,9 @@ #define ROUTE_DISTANCE_BETWEEN_LATITUDE 111300 /** - * @brief A to handle points on the earth + * @brief A class to handle points on the earth * - * The points inherits latidue and longitude as doubles + * The points inherits latitude and longitude as doubles * */ class Point @@ -58,11 +58,10 @@ public: /** * @brief Construct a new Point object * - * @param lat latitude - * @param lon longitude - * @param horizontalAccuracy mm - * @param coords Coordinates - * @param imported if true than highest accuracy + * @param lat + * @param lon + * @param horizontalAccuracy + * @param creationTime */ Point(double lat, double lon, uint32_t horizontalAccuracy = 0, uint32_t creationTime = 0); Point(int32_t lat, int32_t lon, uint32_t horizontalAccuracy = 0, uint32_t creationTime = 0); diff --git a/lib/Route/route.h b/lib/Route/route.h index 7b38315..0b86be5 100644 --- a/lib/Route/route.h +++ b/lib/Route/route.h @@ -1,27 +1,28 @@ /** * @file route.h * @author Alexander Klein (alex@kleiax.de) - * @brief Contains the class Point and Route + * @brief Contains the class Route * @version 0.1 * @date 2022-01-31 - * + * * @copyright Copyright (c) 2022 - * + * */ #ifndef ROUTE_H #define ROUTE_H #include -#include +#include #include "point.h" /** * @brief Holds some route information - * + * */ -struct RouteInfo{ +struct RouteInfo +{ /** * @brief Selected number of Points */ @@ -35,77 +36,76 @@ struct RouteInfo{ /** * @brief A class to manage multiple points - * + * * The list of point presents a route which can be driven */ -class Route { - public: - /** - * @brief Adds a point to the list. - * - * @param point - */ - void addPointToRoute(Point point); +class Route +{ +public: + /** + * @brief Adds a point to the list. + * + * @param point + */ + void addPointToRoute(Point point); - /** - * @brief Delete all points. - * - */ - void clear(); + /** + * @brief Delete all points + */ + void clear(); - /** - * @brief Select the first point as target. - * - * @return Point - */ - Point startRoute(); + /** + * @brief Select the first point as target. + * + * @return Point + */ + Point startRoute(); - /** - * @brief Select the last point as target. - * - * @return Point - */ - Point endRoute(); + /** + * @brief Select the last point as target. + * + * @return Point + */ + Point endRoute(); - /** - * @brief Get the next point and set it as target. - * - * @return Point is zero if there are no more Points. - */ - Point getNextPoint(); + /** + * @brief Get the next point and set it as target. + * + * @return Point is zero if there are no more Points. + */ + Point getNextPoint(); - /** - * @brief Get the previous point and set it as target. - * - * @return Point - */ - Point getPreviousPoint(); + /** + * @brief Get the previous point and set it as target. + * + * @return Point + */ + Point getPreviousPoint(); - /** - * @brief Get the Route Info object - * - * @return RouteInfo - */ - RouteInfo getRouteInfo(); + /** + * @brief Get the Route Info object + * + * @return RouteInfo + */ + RouteInfo getRouteInfo(); - /** - * @brief Get the Started object - * - * The Route will be marked as started when startRoute or - * endRoute has been called. - * - * @return true - * @return false - */ - bool getStarted() const { return this->started; } + /** + * @brief Get the Started object + * + * The Route will be marked as started when startRoute or + * endRoute has been called. + * + * @return true + * @return false + */ + bool getStarted() const { return this->started; } - private: - uint16_t currentPoint = 0; - bool started = false; - - std::list points; - std::list::iterator it; +private: + uint16_t currentPoint = 0; + bool started = false; + std::list points; + std::list::iterator it; }; #endif // ROUTE_H diff --git a/lib/Sensors/sensorData.cpp b/lib/Sensors/sensorData.cpp index b80c8ac..f5246e8 100644 --- a/lib/Sensors/sensorData.cpp +++ b/lib/Sensors/sensorData.cpp @@ -1,5 +1,5 @@ /** - * @file senors.cpp + * @file sensorData.cpp * @author Alexander Klein (alex@kleiax.de) * @brief * @version 0.1 @@ -83,32 +83,32 @@ void SensorData::enableCalcCompass() // TODO: !!! implementieren } -void SensorData::enableGyroskop() +void SensorData::enableGyroscope() { - this->gyroskop = new MPU6050(); - this->gyroskop->initialize(); - if (!this->gyroskop->testConnection()) + this->gyroscope = new MPU6050(); + this->gyroscope->initialize(); + if (!this->gyroscope->testConnection()) { - std::cout << "SensorData::enableGyroskop: Gyroskop is not conntected. Freeze!" << std::endl; + std::cout << "SensorData::enableGyroscope: Gyroskop is not conntected. Freeze!" << std::endl; while (true) { } } - const uint8_t deviceStatus = this->gyroskop->dmpInitialize(); + const uint8_t deviceStatus = this->gyroscope->dmpInitialize(); // TODO: !!! MagicNumer 6x - this->gyroskop->setXGyroOffset(220); - this->gyroskop->setYGyroOffset(76); - this->gyroskop->setZGyroOffset(-85); - this->gyroskop->setZAccelOffset(1788); + this->gyroscope->setXGyroOffset(220); + this->gyroscope->setYGyroOffset(76); + this->gyroscope->setZGyroOffset(-85); + this->gyroscope->setZAccelOffset(1788); if (deviceStatus == 0) { - this->gyroskop->CalibrateAccel(6); - this->gyroskop->CalibrateGyro(6); - this->gyroskop->PrintActiveOffsets(); - this->gyroskop->setDMPEnabled(true); + this->gyroscope->CalibrateAccel(6); + this->gyroscope->CalibrateGyro(6); + this->gyroscope->PrintActiveOffsets(); + this->gyroscope->setDMPEnabled(true); } else { @@ -116,7 +116,7 @@ void SensorData::enableGyroskop() // 1 = initial memory load failed // 2 = DMP configuration updates failed // (if it's going to break, usually the code will be 1) - std::cout << "SensorData::enableGyroskop: DMP Initialization failed (code" << static_cast(deviceStatus) << "). Freeze!" << std::endl; + std::cout << "SensorData::enableGyroscope: DMP Initialization failed (code" << static_cast(deviceStatus) << "). Freeze!" << std::endl; while (true) { } @@ -236,11 +236,11 @@ void SensorData::run() this->realAzimuth = this->realCompass->getAzimuth(); } - if (static_cast(this->gyroskop) && this->gyroskop->dmpGetCurrentFIFOPacket(static_cast(this->gyroBuffer))) + if (static_cast(this->gyroscope) && this->gyroscope->dmpGetCurrentFIFOPacket(static_cast(this->gyroBuffer))) { - this->gyroskop->dmpGetQuaternion(&this->quaternion, static_cast(this->gyroBuffer)); - this->gyroskop->dmpGetGravity(&this->gravity, &this->quaternion); - this->gyroskop->dmpGetYawPitchRoll(static_cast(this->yawPitchRoll), &this->quaternion, &this->gravity); + this->gyroscope->dmpGetQuaternion(&this->quaternion, static_cast(this->gyroBuffer)); + this->gyroscope->dmpGetGravity(&this->gravity, &this->quaternion); + this->gyroscope->dmpGetYawPitchRoll(static_cast(this->yawPitchRoll), &this->quaternion, &this->gravity); } } diff --git a/lib/Sensors/sensorData.h b/lib/Sensors/sensorData.h index 598e42c..7eb69cf 100644 --- a/lib/Sensors/sensorData.h +++ b/lib/Sensors/sensorData.h @@ -1,7 +1,7 @@ /** * @file sensorData.h * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains the SensorData class * @version 0.1 * @date 2023-09-02 * @@ -26,8 +26,12 @@ #include "ntripClient.h" #include "point.h" -class Sensors; +/** + * @brief A class to manage all sensors + * + * Each sensor have separately to be enabled + */ class SensorData : public Component { public: @@ -35,26 +39,89 @@ public: ~SensorData(); void enableNtrip(String host, uint16_t port, String mountPoint, String user, String password); + + /** + * @brief Enable the gnss module over spi + * + * @param spiPort + * @param csPin + */ void enableGnss(SPIClass *spiPort, uint8_t csPin); + + /** + * @brief Enable the gnss module over i2c + */ void enableGnss(); + void enableRealCompass(); void enableCalcCompass(); - void enableGyroskop(); + void enableGyroscope(); - // Interface Const kram + // Interface Const + /** + * @brief Get the azimuth measured by the compass module + * + * @return int16_t + */ int16_t getRealAzimuth() const { return this->realAzimuth; } + + /** + * @brief Get the azimuth calculated by CalcAzimuth + * + * Consider to call getCalcAzimuthState() to check, if the data is valid. + * + * @return int16_t + */ int16_t getCalcAzimuth() const { return this->calcAzimuth; } + + /** + * @brief Get the CalcAzimuth::State object + * + * Needed to check the quality of calculated azimuth + * + * @return CalcAzimuth::State + */ CalcAzimuth::State getCalcAzimuthState() const; Point getCurrentPos() const { return this->currentPosition; } const UBX_NAV_PVT_data_t *getGnssData() const { return this->gnssData; }; NTRIPClientStates getNtripState() const; + + /** + * @brief Get the data from the gyroscope + * + * The returned float pointer is an array of 3 floats + * - Yaw + * - Pitch + * - Roll + * + * @return const float* + */ const float *getGyroData() const { return this->yawPitchRoll; } + /** + * @brief Get the CalcCompass object + * @return CalcAzimuth* + */ CalcAzimuth *getCalcCompass() const { return this->calcCompass; } + + /** + * @brief Get the RealCompass object + * @return QMC5883LCompass* + */ QMC5883LCompass *getRealCompass() const { return this->realCompass; } + + /** + * @brief Get the NTRIPClient object + * @return NTRIPClient* + */ NTRIPClient *getNtripClient() const { return this->ntripClient; } - MPU6050 *getGyroskop() const { return this->gyroskop; } + + /** + * @brief Get the Gyroscope object + * @return MPU6050* + */ + MPU6050 *getGyroscope() const { return this->gyroscope; } // static /** @@ -77,7 +144,7 @@ private: CalcAzimuth *calcCompass = nullptr; SFE_UBLOX_GNSS *gnss = nullptr; NTRIPClient *ntripClient = nullptr; - MPU6050 *gyroskop = nullptr; + MPU6050 *gyroscope = nullptr; UBX_NAV_PVT_data_t *gnssData = nullptr; Point currentPosition; diff --git a/lib/Speedometer/speedometer.h b/lib/Speedometer/speedometer.h index 87ff979..a47f1ff 100644 --- a/lib/Speedometer/speedometer.h +++ b/lib/Speedometer/speedometer.h @@ -48,7 +48,7 @@ public: * * @param pin Pin on the Esp from the encoder. * @param diameter Diameter of the wheel in meters. - * @param steps Encodersteps for a complete wheel rotation. + * @param steps EncoderSteps for a complete wheel rotation. */ Speedometer(uint8_t pin, double diameter, uint16_t steps); @@ -78,12 +78,24 @@ public: Direction getDirection() const { return this->currentDirection; } /** - * @brief Get the calculated speed of the Wheel + * @brief Get the calculated speed of the wheel * * @return double speed in m/s */ double getSpeed() const { return this->speed; } + + /** + * @brief Get the calculated speed of the wheel + * + * @return double speed in rad/s + */ double getSpeedRad() const { return this->rad; }; + + /** + * @brief Get the calculated average speed of the wheel + * + * @return double speed in m/s + */ double getAvgSpeed() const; /** diff --git a/lib/Times/debugTimes.cpp b/lib/Times/debugTimes.cpp index d94e856..82b5d73 100644 --- a/lib/Times/debugTimes.cpp +++ b/lib/Times/debugTimes.cpp @@ -1,7 +1,7 @@ /** * @file debugTimes.cpp * @author Alexander Klein (alex@kleiax.de) - * @brief Implemention of the class debugTimes.h. + * @brief Implementation of the class debugTimes.h. * @version 0.1 * @date 2021-12-13 * @@ -19,7 +19,7 @@ DebugTimes::DebugTimes() if (DebugTimes::printWarning) { std::cout << std::endl - << "Warning: DebugTimes is muuted, no times are be shown." << std::endl + << "Warning: DebugTimes is muted, no times are be shown." << std::endl << std::endl; DebugTimes::printWarning = false; } diff --git a/lib/Times/debugTimes.h b/lib/Times/debugTimes.h index 5327a94..da82965 100644 --- a/lib/Times/debugTimes.h +++ b/lib/Times/debugTimes.h @@ -53,7 +53,7 @@ public: /** * @brief Print the elapsed time to consol * - * @param name Functionname to print + * @param name FunctionName to print * @param minTime A minimum time before printing * * @return uint16_t elapsed milliseconds diff --git a/lib/calibrateCompass/calibrateCompass.h b/lib/calibrateCompass/calibrateCompass.h deleted file mode 100644 index 9fc953c..0000000 --- a/lib/calibrateCompass/calibrateCompass.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @file calibrateCompass.h - * @author Alexander Klein (alex@kleiax.de) - * @brief - * @version 0.1 - * @date 2023-05-23 - * - * @copyright Copyright (c) 2023 - * - */ - -#pragma once - -#include -#include -#include - -#include "component.h" - -class CalibrateCompass : public Component -{ -public: - enum State - { - Ready, - Calibrating, - Finished - }; - - struct CallibrationData - { - int data[3][2]; - }; - - CalibrateCompass(QMC5883LCompass *compass); - - void start(); - void useData(); - void removeCalibration(); - void reset(); - void saveData(); - void loadData(); - - State getState() const { return this->state; } - CallibrationData getCallibrationData() const { return this->data; } - - friend std::ostream &operator<<(std::ostream &stream, const CalibrateCompass &caliComp); - -private: - void runAsChild() override; - void run() override; - void checkDataValidity(); - - QMC5883LCompass *compass; - State state = State::Ready; - CallibrationData data{}; - - void clearData(); - - bool dataValid = false; - const uint16_t maxTimeWithoutChange = 10000; - uint32_t lastChange = 0; -}; diff --git a/src/OutputBuf/outputBuf.cpp b/src/OutputBuf/outputBuf.cpp index c33c288..7d4cd83 100644 --- a/src/OutputBuf/outputBuf.cpp +++ b/src/OutputBuf/outputBuf.cpp @@ -1,5 +1,5 @@ /** - * @file outputBufMqtt.cpp + * @file outputBuf.cpp * @author Alexander Klein (alex@kleiax.de) * @brief Contains the implementation of the class OutputBufMqtt * @version 0.1 diff --git a/src/OutputBuf/outputBuf.h b/src/OutputBuf/outputBuf.h index 6b785b4..fa6abb3 100644 --- a/src/OutputBuf/outputBuf.h +++ b/src/OutputBuf/outputBuf.h @@ -1,5 +1,5 @@ /** - * @file outputBufMqtt.h + * @file outputBuf.h * @author Alexander Klein (alex@kleiax.de) * @brief Contains a small class that provide a streambuf * @@ -38,6 +38,7 @@ class OutputBuf : public std::streambuf { * @brief Construct a new Output Buf Mqtt object * * @param debugMqtt + * @param serialBT */ OutputBuf(DebugMqtt* debugMqtt = nullptr, BluetoothSerial* serialBT = nullptr); diff --git a/src/SpecialMenus/Systeminformation/menuSysteminformation.h b/src/SpecialMenus/Systeminformation/menuSysteminformation.h index d0d885a..8b35dc6 100644 --- a/src/SpecialMenus/Systeminformation/menuSysteminformation.h +++ b/src/SpecialMenus/Systeminformation/menuSysteminformation.h @@ -31,8 +31,7 @@ class MenuSysteminformation : public MenuInformationSites { /** * @brief Construct a new Menu Systeminformation object * - * @param mainBattery - * @param gamepad + * @param mainBattery */ MenuSysteminformation(Battery* mainBattery); diff --git a/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.cpp b/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.cpp index 9715f31..c479fc7 100644 --- a/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.cpp +++ b/src/SpecialMenus/driveModi/CalibrateCompass/menuCalibrateCompass.cpp @@ -81,23 +81,23 @@ void MenuCalibrateCompass::printPage() const { case 8: lineOne = "X min: "; - lineOne.concat(this->caliCompass->getCallibrationData().data[0][0]); + lineOne.concat(this->caliCompass->getCalibrationData().data[0][0]); lineTwo = "X max: "; - lineTwo.concat(this->caliCompass->getCallibrationData().data[0][1]); + lineTwo.concat(this->caliCompass->getCalibrationData().data[0][1]); break; case 9: lineOne = "Y min: "; - lineOne.concat(this->caliCompass->getCallibrationData().data[1][0]); + lineOne.concat(this->caliCompass->getCalibrationData().data[1][0]); lineTwo = "Y max: "; - lineTwo.concat(this->caliCompass->getCallibrationData().data[1][1]); + lineTwo.concat(this->caliCompass->getCalibrationData().data[1][1]); break; case 10: lineOne = "Z min: "; - lineOne.concat(this->caliCompass->getCallibrationData().data[2][0]); + lineOne.concat(this->caliCompass->getCalibrationData().data[2][0]); lineTwo = "Z max: "; - lineTwo.concat(this->caliCompass->getCallibrationData().data[2][1]); + lineTwo.concat(this->caliCompass->getCalibrationData().data[2][1]); break; default: diff --git a/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp b/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp index 7f88b5b..72dc8b8 100644 --- a/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp +++ b/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp @@ -164,7 +164,7 @@ void MenuTestMode::init() { auto *lightBlueAction = new MenuAction("Blue", dummy); auto *lightOffAction = new MenuAction("Off", dummy); - // Add entrys to the menus + // Add entries to the menus this->mainMenu->addEntry(engineAction); this->mainMenu->addEntry(drivingAction); this->mainMenu->addEntry(encoderAction); diff --git a/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp b/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp index 8d88049..4481e53 100644 --- a/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp +++ b/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp @@ -1,5 +1,5 @@ /** - * @file menuTest.cpp + * @file speedometerTest.cpp * @author Alexander Klein (alex@kleiax.de) * @brief Contains the implementation of the class SpeedometerTest. * @version 0.1 diff --git a/src/SpecialMenus/driveModi/TestMode/speedometerTest.h b/src/SpecialMenus/driveModi/TestMode/speedometerTest.h index 609e474..3990403 100644 --- a/src/SpecialMenus/driveModi/TestMode/speedometerTest.h +++ b/src/SpecialMenus/driveModi/TestMode/speedometerTest.h @@ -1,5 +1,5 @@ /** - * @file menuTest.h + * @file speedometerTest.h * @author Alexander Klein (alex@kleiax.de) * @brief Contains a class to test the wheel encoder. * @version 0.1 diff --git a/src/driveModi/driveManager.h b/src/driveModi/driveManager.h index 8c7f5f9..1050a34 100644 --- a/src/driveModi/driveManager.h +++ b/src/driveModi/driveManager.h @@ -22,14 +22,21 @@ class DriveManager : public Component { public: + /** * @brief Construct a new Drive Manager object * - * Creates a Navigation 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); /** diff --git a/src/main.cpp b/src/main.cpp index 3431a27..9c3134f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -70,7 +70,7 @@ void restart(); void receiveCallback(const uint8_t *mac, const uint8_t *incomingData, int len); void sendCallback(const uint8_t *mac_addr, esp_now_send_status_t status); void lcdWrapperCallback(const char data[][LcdWrapper::totalRows], uint8_t lines, uint8_t rows); -NetworkAdresses setIPs(); +NetworkAddresses setIPs(); void setup() { @@ -130,7 +130,7 @@ void setup() static_cast(NtripConfig::mountPoint), static_cast(NtripConfig::user), static_cast(NtripConfig::password)); - // sensorData->enableGyroskop(); + // sensorData->enableGyroscope(); driveManager = new DriveManager(&moveController, sensorData, controlPad->getControlPadDataPtr()); char wifiIndicator = 'X'; @@ -355,9 +355,9 @@ void lcdWrapperCallback(const char data[][LcdWrapper::totalRows], uint8_t lines, } } -NetworkAdresses setIPs() +NetworkAddresses setIPs() { - NetworkAdresses adresses; + NetworkAddresses adresses; adresses.localIP.fromString(static_cast(NetworkConfig::ip)); adresses.subnet.fromString(static_cast(NetworkConfig::subnet)); adresses.gateway.fromString(static_cast(NetworkConfig::gateway));