- added batteryCalibration
- start with default Menus for DriveModes
This commit is contained in:
@@ -45,12 +45,16 @@ Code:
|
||||
sensor data gnss daten aktualisieren
|
||||
Menübaum korrigieren, Verlinkung Sensor in Mode etc.
|
||||
esp und sensoren in den deepsleep
|
||||
battery Prozent ausgabe wirkt komisch
|
||||
|
||||
Latex:
|
||||
Anhang: Liste mit allen Komponenten und Kurzbeschreibung
|
||||
Unterschied funktionale und nicht funktionale Anforderungen
|
||||
Strom nicht über Zeit sondern Rampe
|
||||
Formel für Zeit anfahrrampe Einheiten
|
||||
Überall den Durchmesser der Räder auf 12cm und Pulse auf 384 / 3 = 128
|
||||
|
||||
3D:
|
||||
|
||||
|
||||
Rover:
|
||||
Spannungsteiler neu kalibrieren.
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ namespace PinNumbers {
|
||||
constexpr uint8_t dir1 = 27;
|
||||
constexpr uint8_t dir2 = 12;
|
||||
constexpr uint8_t pwm = 13;
|
||||
constexpr uint8_t encoder = 26;
|
||||
constexpr uint8_t encoder = 32;
|
||||
constexpr uint8_t pmwChannel = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define RHEDE
|
||||
#define HOTSPOT
|
||||
|
||||
#ifdef HOTSPOT
|
||||
namespace NetworkConfig {
|
||||
|
||||
+51
-1
@@ -27,10 +27,15 @@ Battery::Battery(uint8_t pin) {
|
||||
}
|
||||
|
||||
void Battery::run() {
|
||||
if (this->calibrationState != CalibrationState::None) {
|
||||
this->runCalibration();
|
||||
return;
|
||||
}
|
||||
|
||||
this->readAdcToBuf();
|
||||
this->loopCounter++;
|
||||
|
||||
if (this->loopCounter == this->calulationDelayMultiplier) {
|
||||
if (this->loopCounter >= this->calulationDelayMultiplier) {
|
||||
this->calculateBatteryVoltage();
|
||||
this->calculateBatteryPercent();
|
||||
this->loopCounter = 0;
|
||||
@@ -40,6 +45,28 @@ void Battery::run() {
|
||||
return;
|
||||
}
|
||||
|
||||
void Battery::runCalibration() {
|
||||
if (this->calibrationState != CalibrationState::Reading)
|
||||
return;
|
||||
|
||||
this->readAdcToBuf();
|
||||
if (this->bufferPos == 0) {
|
||||
uint16_t res = this->getBufAvg();
|
||||
this->newRawAdcVoltages[this->currentCalibrationVoltage] = res;
|
||||
std::cout << "Index: "
|
||||
<< (int) this->currentCalibrationVoltage
|
||||
<< " Value: "
|
||||
<< (int) res
|
||||
<< std::endl;
|
||||
this->currentCalibrationVoltage++;
|
||||
this->calibrationState = CalibrationState::Waiting;
|
||||
|
||||
if (this->currentCalibrationVoltage == 60) {
|
||||
this->calibrationState = CalibrationState::Finished;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double Battery::getBatteryVoltage() const {
|
||||
double res = this->batteryVoltage;
|
||||
return (int)(res*100+0.5)/100.0;
|
||||
@@ -59,6 +86,29 @@ bool Battery::isNewValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Battery::nextVoltageIsReady() {
|
||||
if (this->calibrationState == CalibrationState::Waiting) {
|
||||
this->calibrationState = CalibrationState::Reading;
|
||||
}
|
||||
}
|
||||
|
||||
void Battery::startCalibration() {
|
||||
this->calibrationState = CalibrationState::Waiting;
|
||||
this->currentCalibrationVoltage = 0;
|
||||
this->bufferPos = 0;
|
||||
this->loopDelay = 50;
|
||||
this->newRawAdcVoltages = new uint16_t[60];
|
||||
}
|
||||
|
||||
void Battery::finishCalibration() {
|
||||
if (this->calibrationState != CalibrationState::None)
|
||||
return;
|
||||
|
||||
delete[] this->newRawAdcVoltages;
|
||||
this->calibrationState = CalibrationState::None;
|
||||
this->loopDelay = 100;
|
||||
}
|
||||
|
||||
double Battery::calculateInputVoltage() {
|
||||
// Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
|
||||
double reading = this->getBufAvg();
|
||||
|
||||
+25
-6
@@ -29,6 +29,13 @@
|
||||
*/
|
||||
class Battery : public Component {
|
||||
public:
|
||||
enum CalibrationState {
|
||||
None,
|
||||
Reading,
|
||||
Waiting,
|
||||
Finished
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Construct a new Battery object
|
||||
*
|
||||
@@ -72,8 +79,16 @@ class Battery : public Component {
|
||||
|
||||
bool isNewValue();
|
||||
|
||||
//Calibration
|
||||
CalibrationState getCalibrationState() const { return this->calibrationState; }
|
||||
uint8_t getCurrentCalibrationVoltage() const { return this->currentCalibrationVoltage; }
|
||||
void nextVoltageIsReady();
|
||||
void startCalibration();
|
||||
void finishCalibration();
|
||||
|
||||
private:
|
||||
void run() override;
|
||||
void runCalibration();
|
||||
double calculateInputVoltage();
|
||||
void calculateBatteryVoltage();
|
||||
void calculateBatteryPercent();
|
||||
@@ -83,6 +98,8 @@ class Battery : public Component {
|
||||
|
||||
static const uint8_t bufferSize = 30;
|
||||
|
||||
CalibrationState calibrationState = CalibrationState::None;
|
||||
|
||||
uint8_t absurdLowVoltage = 5;
|
||||
uint8_t pin;
|
||||
uint8_t batteryPercent = 0;
|
||||
@@ -90,7 +107,9 @@ class Battery : public Component {
|
||||
uint8_t bufferPos = 0;
|
||||
uint8_t calulationDelayMultiplier = 5;
|
||||
uint8_t loopCounter = 0;
|
||||
uint8_t currentCalibrationVoltage = 0; // *0.1 + 7
|
||||
uint16_t adcBuffer[bufferSize];
|
||||
uint16_t* newRawAdcVoltages;
|
||||
uint32_t r1 = 0;
|
||||
uint32_t r2 = 0;
|
||||
bool calculatetNewValues = false;
|
||||
@@ -108,12 +127,12 @@ class Battery : public Component {
|
||||
const double startVoltage = 7;
|
||||
const double stepVoltage = 0.1;
|
||||
const uint16_t rawAdcVoltages[60] = // from 7.0V to 12.9V in 0.1V steps
|
||||
{1820, 1851, 1880, 1910, 1937, 1967, 1992, 2020, 2048, 2080,
|
||||
2109, 2136, 2163, 2189, 2218, 2244, 2273, 2302, 2334, 2363,
|
||||
2391, 2415, 2441, 2471, 2499, 2531, 2557, 2587, 2617, 2646,
|
||||
2674, 2699, 2730, 2761, 2791, 2816, 2843, 2872, 2900, 2930,
|
||||
2958, 2991, 3017, 3049, 3080, 3115, 3144, 3178, 3208, 3242,
|
||||
3276, 3313, 3346, 3389, 3433, 3470, 3509, 3548, 3590, 3636};
|
||||
{1992, 2021, 2056, 2090, 2118, 2145, 2177, 2208, 2241, 2272,
|
||||
2298, 2331, 2362, 2387, 2420, 2453, 2482, 2514, 2543, 2577,
|
||||
2607, 2640, 2670, 2703, 2736, 2763, 2794, 2826, 2858, 2890,
|
||||
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};
|
||||
};
|
||||
|
||||
#endif // BATTERY_H
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ board_build.partitions = no_ota.csv
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
upload_speed = 921600
|
||||
monitor_port = COM3
|
||||
monitor_port = COM6
|
||||
lib_deps =
|
||||
https://git.kleiax.de/PlatformIO-Libs/SparkFunGNSS.git
|
||||
knolleary/PubSubClient@^2.8
|
||||
@@ -26,7 +26,7 @@ lib_deps =
|
||||
https://git.kleiax.de/PlatformIO-Libs/Menu.git
|
||||
nrf24/RF24@^1.4.5
|
||||
jrowberg/I2Cdevlib-MPU6050@^1.0.0
|
||||
upload_port = COM3
|
||||
upload_port = COM6
|
||||
test_ignore = test_desktop
|
||||
build_type = debug
|
||||
monitor_filters = esp32_exception_decoder
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @file menuCalibrateBattery.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-09-26
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
|
||||
#include "menuCalibrateBattery.h"
|
||||
|
||||
MenuCalibrateBattery::MenuCalibrateBattery(Battery* battery) {
|
||||
this->setUpdateDelay(400);
|
||||
this->battery = battery;
|
||||
}
|
||||
|
||||
void MenuCalibrateBattery::printMenu() {
|
||||
if (this->battery->getCalibrationState() == Battery::CalibrationState::None)
|
||||
this->battery->startCalibration();
|
||||
|
||||
String lineOne = "";
|
||||
String lineTwo = "";
|
||||
|
||||
switch (this->battery->getCalibrationState()) {
|
||||
case Battery::CalibrationState::Waiting:
|
||||
lineOne = "Target Voltage:";
|
||||
lineTwo = "7 + ";
|
||||
lineTwo.concat(this->battery->getCurrentCalibrationVoltage());
|
||||
lineTwo.concat(" / 10");
|
||||
break;
|
||||
|
||||
case Battery::CalibrationState::Reading:
|
||||
lineOne = "Reading...";
|
||||
break;
|
||||
|
||||
case Battery::CalibrationState::Finished:
|
||||
lineOne = "Finished!";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
this->print(lineOne, lineTwo);
|
||||
}
|
||||
|
||||
void MenuCalibrateBattery::left() {
|
||||
this->battery->finishCalibration();
|
||||
|
||||
if (parentMenu)
|
||||
this->parentMenu->printMenu();
|
||||
}
|
||||
|
||||
void MenuCalibrateBattery::right() {
|
||||
if (this->battery->getCalibrationState() == Battery::CalibrationState::Waiting)
|
||||
this->battery->nextVoltageIsReady();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @file menuCalibrateBattery.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-09-26
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MENU_CALIBRATE_BATTERY_H
|
||||
#define MENU_CALIBRATE_BATTERY_H
|
||||
|
||||
#include "menuControl.h"
|
||||
#include "battery.h"
|
||||
|
||||
class MenuCalibrateBattery : public MenuControl {
|
||||
public:
|
||||
MenuCalibrateBattery(Battery* battery);
|
||||
|
||||
void printMenu() override;
|
||||
|
||||
void left() override;
|
||||
void no() override { this->left(); }
|
||||
void right() override;
|
||||
void yes() override { this->right(); }
|
||||
|
||||
private:
|
||||
Battery* battery;
|
||||
};
|
||||
|
||||
#endif //MENU_CALIBRATE_BATTERY_H
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @file menuSpeed.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-09-26
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
|
||||
#include "menuSpeed.h"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @file menuSpeed.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-09-26
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MENU_SPEED_H
|
||||
#define MENU_SPEED_H
|
||||
|
||||
#include <menuIntInput.h>
|
||||
|
||||
class MenuSpeed : MenuIntInput {
|
||||
|
||||
};
|
||||
|
||||
#endif // MENU_SPEED_H
|
||||
@@ -14,6 +14,7 @@
|
||||
MenuSysteminformation::MenuSysteminformation(Battery* mainBattery)
|
||||
: MenuInformationSites(8) {
|
||||
this->mainBattery = mainBattery;
|
||||
this->noEqualLeft = true;
|
||||
}
|
||||
|
||||
void MenuSysteminformation::printPage() const {
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include "menuInformationSites.h"
|
||||
#include "driveModi/driveManager.h"
|
||||
#include "SpecialMenus/SensorData/menuSensorData.h"
|
||||
#include "SpecialMenus/Speed/menuSpeed.h"
|
||||
|
||||
/**
|
||||
* @brief A base class for Menus about DriveModi
|
||||
@@ -36,6 +38,9 @@ class MenuDriveMode : public MenuInformationSites {
|
||||
void configureOnLeave() {}
|
||||
|
||||
DriveManager* driveManager;
|
||||
MenuSensorData* menuSensor;
|
||||
MenuSpeed* menuSpeed;
|
||||
|
||||
bool firstPrint = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include "SpecialMenus/PID/menuPidSettings.h"
|
||||
#include "SpecialMenus/Route/menuRoute.h"
|
||||
#include "SpecialMenus/SensorData/menuSensorData.h"
|
||||
#include "SpecialMenus/CalibrateBattery/menuCalibrateBattery.h"
|
||||
|
||||
MoveControl moveController;
|
||||
Network* network;
|
||||
@@ -216,6 +217,7 @@ void makeMenu() {
|
||||
MenuSensorData* sen_m = new MenuSensorData(sensorData);
|
||||
//TODO: Wie bekommt jeder die dumme Route?
|
||||
MenuRoute* rout_m = new MenuRoute(new Route());
|
||||
MenuCalibrateBattery* bat_m = new MenuCalibrateBattery(mainBattery);
|
||||
|
||||
auto_m->setUpdateDelay(1000);
|
||||
sys_m->setUpdateDelay(1500);
|
||||
@@ -242,6 +244,7 @@ void makeMenu() {
|
||||
set_m->addEntry(new MenuAction("Speed", dummy));
|
||||
set_m->addEntry(new MenuAction("Distance", dummy));
|
||||
set_m->addEntry(new MenuAction("WiFi", dummy));
|
||||
set_m->addEntry(new MenuAction("Battery", bat_m));
|
||||
|
||||
// Entry for the PID Menu
|
||||
pid_m->addEntry(new MenuAction("Left", pidl_m));
|
||||
|
||||
Reference in New Issue
Block a user