documentation checked and edit
for all files in lib folder
This commit is contained in:
@@ -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()
|
||||
|
||||
+66
-11
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 <QMC5883LCompass.h>
|
||||
#include <Preferences.h>
|
||||
#include <iostream>
|
||||
|
||||
#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;
|
||||
};
|
||||
@@ -19,7 +19,7 @@ void Component::loop()
|
||||
(*it)->loop();
|
||||
}
|
||||
}
|
||||
this->runAsChild();
|
||||
this->runAsChild();F
|
||||
|
||||
if (this->onlyChilds)
|
||||
{
|
||||
|
||||
@@ -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 <list>
|
||||
|
||||
/**
|
||||
* @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:
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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 <controlPadInput.h>
|
||||
#include <component.h>
|
||||
|
||||
/**
|
||||
* @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; }
|
||||
|
||||
+45
-1
@@ -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 <Arduino.h>
|
||||
#include <driver/pcnt.h>
|
||||
#include <cinttypes>
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+48
-35
@@ -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<char*>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char*>("%s: %s"),this->name ,msg.c_str());
|
||||
this->sendData(loglevel, topic, static_cast<const char*>(DebugMqtt::msg));
|
||||
void DebugMqtt::sendMsg(Loglevel loglevel, String topic, String msg)
|
||||
{
|
||||
snprintf(static_cast<char *>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char *>("%s: %s"), this->name, msg.c_str());
|
||||
this->sendData(loglevel, topic, static_cast<const char *>(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<char*>(DebugMqtt::topic), MQTT_BUFFER_SIZE, static_cast<const char*>("%s%s"), DebugMqtt::enum_to_string(loglevel).c_str(), topic.c_str());
|
||||
snprintf (static_cast<char*>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char*>("%s"), data.c_str());
|
||||
client->publish(DebugMqtt::topic, static_cast<const char*>(DebugMqtt::msg));
|
||||
if (loglevel <= DebugMqtt::loglevel && loglevel > Loglevel::none)
|
||||
{
|
||||
snprintf(static_cast<char *>(DebugMqtt::topic), MQTT_BUFFER_SIZE, static_cast<const char *>("%s%s"), DebugMqtt::enum_to_string(loglevel).c_str(), topic.c_str());
|
||||
snprintf(static_cast<char *>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char *>("%s"), data.c_str());
|
||||
client->publish(DebugMqtt::topic, static_cast<const char *>(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<char*>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char*>("%s %s=%f %llu"), measurement_name.c_str(), field_set.c_str(), measurement, nanos);
|
||||
this->sendData(Loglevel::influx, static_cast<const char*>(DebugMqtt::msg));
|
||||
snprintf(static_cast<char *>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char *>("%s %s=%f %llu"), measurement_name.c_str(), field_set.c_str(), measurement, nanos);
|
||||
this->sendData(Loglevel::influx, static_cast<const char *>(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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+120
-117
@@ -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 <iostream>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
+13
-13
@@ -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)
|
||||
|
||||
+59
-8
@@ -20,10 +20,20 @@
|
||||
#include <esp_now.h>
|
||||
#include <esp_wifi.h>
|
||||
|
||||
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;
|
||||
|
||||
+6
-7
@@ -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);
|
||||
|
||||
+66
-66
@@ -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 <cstdint>
|
||||
#include <list>
|
||||
#include <list>
|
||||
|
||||
#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<Point> points;
|
||||
std::list<Point>::iterator it;
|
||||
private:
|
||||
uint16_t currentPoint = 0;
|
||||
bool started = false;
|
||||
|
||||
std::list<Point> points;
|
||||
std::list<Point>::iterator it;
|
||||
};
|
||||
|
||||
#endif // ROUTE_H
|
||||
|
||||
+20
-20
@@ -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<int>(deviceStatus) << "). Freeze!" << std::endl;
|
||||
std::cout << "SensorData::enableGyroscope: DMP Initialization failed (code" << static_cast<int>(deviceStatus) << "). Freeze!" << std::endl;
|
||||
while (true)
|
||||
{
|
||||
}
|
||||
@@ -236,11 +236,11 @@ void SensorData::run()
|
||||
this->realAzimuth = this->realCompass->getAzimuth();
|
||||
}
|
||||
|
||||
if (static_cast<bool>(this->gyroskop) && this->gyroskop->dmpGetCurrentFIFOPacket(static_cast<uint8_t *>(this->gyroBuffer)))
|
||||
if (static_cast<bool>(this->gyroscope) && this->gyroscope->dmpGetCurrentFIFOPacket(static_cast<uint8_t *>(this->gyroBuffer)))
|
||||
{
|
||||
this->gyroskop->dmpGetQuaternion(&this->quaternion, static_cast<uint8_t *>(this->gyroBuffer));
|
||||
this->gyroskop->dmpGetGravity(&this->gravity, &this->quaternion);
|
||||
this->gyroskop->dmpGetYawPitchRoll(static_cast<float *>(this->yawPitchRoll), &this->quaternion, &this->gravity);
|
||||
this->gyroscope->dmpGetQuaternion(&this->quaternion, static_cast<uint8_t *>(this->gyroBuffer));
|
||||
this->gyroscope->dmpGetGravity(&this->gravity, &this->quaternion);
|
||||
this->gyroscope->dmpGetYawPitchRoll(static_cast<float *>(this->yawPitchRoll), &this->quaternion, &this->gravity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <QMC5883LCompass.h>
|
||||
#include <Preferences.h>
|
||||
#include <iostream>
|
||||
|
||||
#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;
|
||||
};
|
||||
Reference in New Issue
Block a user