fix bug in route add akku menu begin with akkuread

This commit is contained in:
2022-02-05 22:41:25 +01:00
parent aa9bf99349
commit 1ef44864e2
12 changed files with 141 additions and 42 deletions
+66
View File
@@ -0,0 +1,66 @@
/**
* @file akku.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-02-05
*
* @copyright Copyright (c) 2022
*
*/
#include "akku.h"
Akku::Akku(uint8_t pin, double maxVolt, double emptyVolt) {
this->pin = pin;
this->maxVolt = maxVolt;
this->emptyVolt = emptyVolt;
this->updateOnePercent();
}
void Akku::setEmptyVoltage(double volt) {
this->emptyVolt = volt;
this->updateOnePercent();
}
void Akku::setMaxVoltage(double volt) {
this->maxVolt = volt;
this->updateOnePercent();
}
double Akku::getVoltage() {
double rawVoltage = this->readVoltage();
if (this->maxVolt) {
}
return rawVoltage;
}
uint8_t Akku::getPercent() {
uint8_t res = 0;
if (this->emptyVolt)
res = (uint8_t) ((this->getVoltage() - this->emptyVolt) / this->onePercent);
return res;
}
bool Akku::isEmpty() {
if (this->getVoltage() < this->emptyVolt) {
return true;
}
return false;
}
double Akku::readVoltage() {
// Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
double reading = analogRead(this->pin);
if(reading < 1 || reading > 4095) return 0;
return - 0.000000000000016 * pow(reading,4)
+ 0.000000000118171 * pow(reading,3)
- 0.000000301211691 * pow(reading,2)
+ 0.001109019271794 * reading
+ 0.034143524634089;
}
double Akku::updateOnePercent() {
this->onePercent = (this->maxVolt - this->emptyVolt) / 100.0;
}
+46
View File
@@ -0,0 +1,46 @@
/**
* @file akku.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-02-05
*
* @copyright Copyright (c) 2022
*
*/
#ifndef AKKU_H
#define AKKU_H
#include <stdint.h>
#include <math.h>
#include <Arduino.h>
class Akku {
public:
Akku(uint8_t pin, double maxVolt = 0, double emptyVolt = 0);
void setEmptyVoltage(double volt);
void setMaxVoltage(double volt);
double getVoltage();
uint8_t getPercent();
bool isEmpty();
private:
double readVoltage();
double updateOnePercent();
uint8_t pin;
double maxVolt;
double emptyVolt;
double onePercent;
const float capacityVoltages[21] = {9.82, 10.83, 11.06, 11.12,
11.18, 11.24, 11.3, 11.36,
11.39, 11.45, 11.51, 11.56,
11.62, 11.74, 11.86, 11.95,
12.07, 12.25, 12.33, 12.45,
12.6 };
};
#endif // AKKU_H
+1 -1
View File
@@ -131,4 +131,4 @@ double Navigation::courseTo(Point p1, Point p2) {
if (p1.isValid() && p2.isValid())
return TinyGPSPlus::courseTo(p1.lat, p1.lon, p2.lat, p2.lon);
return -1;
}
}
+8 -5
View File
@@ -11,6 +11,9 @@
#include "route.h"
// TODO: Delete iostream
#include <iostream>
Route::Route() {
}
@@ -22,16 +25,16 @@ void Route::addPointToRoute(Point point) {
Point Route::startRoute() {
if (this->points.size() < 1)
return Point(0, 0);
*this->it = this->points.begin();
this->it = this->points.begin();
this->currentPoint = 1;
return **this->it;
return *this->it;
}
Point Route::getNextPoint() {
if (*this->it != this->points.end()) {
if (this->it != this->points.end()) {
this->it++;
this->currentPoint++;
return **this->it;
return *this->it;
}
else
return Point(0, 0);
@@ -42,4 +45,4 @@ RouteInfo Route::getRouteInfo() {
info.totalPoints = this->points.size();
info.currentPoint = this->currentPoint;
return info;
}
}
+2 -2
View File
@@ -49,8 +49,8 @@ class Route {
uint16_t currentPoint = 0;
std::list<Point> points;
std::list<Point>::iterator* it;
std::list<Point>::iterator it;
};
#endif // ROUTE_H
#endif // ROUTE_H