From a7930e291523def4abf9ba66ce91eda3641ba34c Mon Sep 17 00:00:00 2001 From: Alexander Klein Date: Fri, 13 Oct 2023 14:17:51 +0200 Subject: [PATCH] more refactor bug fixes --- .vscode/settings.json | 1 + doc/Diagrams/classdiagramm.uxf | 157 ------- doc/Diagrams/statesAutopilot.uxf | 390 ------------------ doc/TODO allgemein.txt | 39 -- include/moveControl.h | 1 + include/networkConfig.h | 4 +- lib/Menu | 1 + lib/MotorControl/motorControl.cpp | 29 +- lib/MotorControl/motorControl.h | 18 +- lib/Sensors/sensorData.h | 1 - platformio.ini | 24 +- src/SpecialMenus/driveModi/menuDriveMode.cpp | 1 - .../Modi/ManualControl/manualControl.cpp | 2 +- src/main.cpp | 8 +- 14 files changed, 21 insertions(+), 655 deletions(-) delete mode 100644 doc/Diagrams/classdiagramm.uxf delete mode 100644 doc/Diagrams/statesAutopilot.uxf create mode 160000 lib/Menu diff --git a/.vscode/settings.json b/.vscode/settings.json index 78046d2..733df74 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -129,6 +129,7 @@ "carr", "CIPO", "COPI", + "deadzone", "Doxygen", "Dutycycle", "gast", diff --git a/doc/Diagrams/classdiagramm.uxf b/doc/Diagrams/classdiagramm.uxf deleted file mode 100644 index 19ccf23..0000000 --- a/doc/Diagrams/classdiagramm.uxf +++ /dev/null @@ -1,157 +0,0 @@ -10UMLClass75010220650<<hardware>> -MotorControl --- -- target_power: int8_t -- power: int8_t -- direction: uint8_t - - -- pwm_pin: uint8_t -- pwm_channel: uint8_t -- pwm_res: uint8_t -- dutycycle_min: uint8_t -- dutycycle_max: uint8_t -- direction_1: uint8_t -- direction_2: uint8_t -- delay: uint8_t -- powersteps: uint8_t - -- last_millis: uint32_t --- -+ MotorControl() -+ init(pwm_pin: uint8_t, -   pwm_channel: uint8_t, -   dir_1: uint8_t, dir_2: uint8_t) -+ loop(): uint16_t -+ runMotorControl() - -+ setMinPwm(uint8_t) -+ setMaxPwm(uint8_t) -+ setPowerSteps(uint8_t): uint16_t -+ setTargetPower(uint8_t) -+ setDelay(uint8_t): uint16_t - -+ stop() -+ emergencyStop() -+ toString() -+ getPower(): int8_t -+ getTargetPower(): int8_t -+ isTargetPowerReached(): bool -+ isAccelerationPositive(): bool -+ isAccelerationNegative(): bool - -- setRealPower(power: int8_t) -- increasePower(power: int8_t) - -UMLClass80380220330<<hardware>> -Speedometer --- -- encoder: ESP32Encoder -- debug: DebugMqtt* -- name: String -- speed: double = 0 -- last_millis: uint64_t = 0; -- bufPos: uint8_t -- buf: int16_t[BUF_SIZE] --- -+ Speedometer() -+ init(pinA: uint8_t, -    pinB: uint8_t, -    name: String) -+ runSpeedometer() -+ setTargetPower(power: int8_t) -+ getSpeed(): double -+ getDirection(): uint8_t -- addValToBuf(val: int16_t) -- getAverage(): int16_tUMLClass700270370MoveControl --- -- debug: DebugMqtt* -- left_motor: MotorControl* -- right_motor: MotorControl* -- left_speedometer: Speedometer* -- right_speedometer: Speedometer* -- driving_status: DrivingStatus = stop -- x_speed: double = 0 -- rotation_speed: double = 0 -- wheelspeed_left_target: double = 0 -- wheelspeed_right_target: double = 0 --- -+ MoveControl() -+ init(left_motor: MotorControl*, -    right_motor: MotorControl*, -    left_speedometer: Speedometer*, -    right_speedometer: Speedometer*) -+ runMoveControl() -+ setDrivingStatus(status: DrivingStatus) -+ setSpeed(speed: double) -+ setRotationspeed(speed: double) -- calcWheelSpeed() -- regulateMotors()UMLClass37010220330<<driveModi>> -ManualControl --- -- encoder: ESP32Encoder -- debug: DebugMqtt* -- name: String -- speed: double = 0 -- last_millis: uint64_t = 0; -- bufPos: uint8_t -- buf: int16_t[BUF_SIZE] --- -+ Speedometer() -+ init(pinA: uint8_t, -    pinB: uint8_t, -    name: String) -+ runSpeedometer() -+ setTargetPower(power: int8_t) -+ getSpeed(): double -+ getDirection(): uint8_t -- addValToBuf(val: int16_t) -- getAverage(): int16_tUMLClass127010210240MenuControl --- -# parentMenu: MenuControl* -# lcd: LiquidCrystal_I2C* --- -/+down()/ -/+up()/ -/+right()/ -/+left()/ -/+yes()/ -/+no()/ - -/+update()/ -/+printMenu()/ - -+ setParentMenu(MenuControl*) -+ setLcd(LiquidCrystal_I2C*)UMLClass98010280270MenuAction --- -- name: char* - -- *function: void -- *callback: void - -- isMenu: bool -- menu: MenuControl --- -+ MenuAction(const char*, (*function), (*callback)) -+ MenuAction(const char*, (*function)) -+ MenuAction(const char*, MenuControl* menu) - -+ runAction() - -+ getName(): const char* -+ getIsMenu(): bool -+ getMenu(): MenuControl* -UMLClass1220360280160Menu --- -- inSubmenu: bool - -- entrys: list<MenuAction*> -- selectedEntry: list<MenuAction*>::iterator - -- isMenu: bool -- menu: MenuControl --- -+ addEntry(MenuAction* entry) -Relation135024030140lt=<<-10;10;10;120Relation1080270160190lt=- -m1=* -m2=0..110;10;10;160;140;160 \ No newline at end of file diff --git a/doc/Diagrams/statesAutopilot.uxf b/doc/Diagrams/statesAutopilot.uxf deleted file mode 100644 index 21f880d..0000000 --- a/doc/Diagrams/statesAutopilot.uxf +++ /dev/null @@ -1,390 +0,0 @@ - - - 10 - - UMLSpecialState - - 40 - 20 - 20 - 20 - - type=initial - - - - Relation - - 40 - 20 - 130 - 30 - - lt=<- - 110.0;10.0;10.0;10.0 - - - UMLState - - 150 - 10 - 100 - 40 - - search next point -bg=green - - - - UMLSpecialState - - 180 - 90 - 40 - 40 - - bg=green -type=decision - - - - Relation - - 190 - 40 - 30 - 70 - - lt=<- - 10.0;50.0;10.0;10.0 - - - UMLState - - 150 - 180 - 100 - 40 - - detect alignment -bg=green - - - - Relation - - 190 - 120 - 130 - 80 - - lt=<- -[distance <= 5m] - 10.0;60.0;10.0;10.0 - - - UMLObject - - 20 - 0 - 840 - 590 - - Autopilot - -valign=top - - - - Relation - - 210 - 90 - 140 - 40 - - lt=<- -[distance > 5m] - 120.0;20.0;10.0;20.0 - - - UMLState - - 330 - 90 - 100 - 40 - - Error -bg=red - - - - UMLState - - 150 - 270 - 100 - 40 - - correct alignment -bg=green - - - - UMLState - - 150 - 360 - 100 - 40 - - drive to point -bg=green - - - - Relation - - 190 - 210 - 30 - 80 - - lt=<- - 10.0;60.0;10.0;10.0 - - - Relation - - 190 - 300 - 30 - 80 - - lt=<- - 10.0;60.0;10.0;10.0 - - - Relation - - 90 - 280 - 80 - 120 - - lt=<- - 60.0;10.0;10.0;10.0;10.0;100.0;60.0;100.0 - - - UMLState - - 440 - 10 - 410 - 300 - - detect alignment -valign=top - - - - UMLSpecialState - - 460 - 60 - 20 - 20 - - type=final - - - - Relation - - 470 - 60 - 90 - 30 - - lt=-> - 10.0;10.0;70.0;10.0 - - - UMLState - - 540 - 50 - 110 - 40 - - drive 1m forward - - - - UMLState - - 540 - 140 - 110 - 40 - - drive 2m backward - - - - UMLState - - 540 - 230 - 110 - 40 - - drive 1m forward - - - - UMLState - - 700 - 230 - 120 - 40 - - calculate straight line - - - - Relation - - 580 - 80 - 30 - 80 - - lt=<- - 10.0;60.0;10.0;10.0 - - - Relation - - 580 - 170 - 30 - 80 - - lt=<- - 10.0;60.0;10.0;10.0 - - - UMLSpecialState - - 750 - 150 - 20 - 20 - - type=termination - - - - Relation - - 750 - 160 - 30 - 90 - - lt=<- - 10.0;10.0;10.0;70.0 - - - UMLState - - 440 - 320 - 410 - 260 - - correct alignment -valign=top - - - - UMLState - - 540 - 370 - 190 - 40 - - calculate relativ target position - - - - Relation - - 470 - 380 - 90 - 30 - - lt=-> - 10.0;10.0;70.0;10.0 - - - UMLSpecialState - - 460 - 380 - 20 - 20 - - type=final - - - - UMLState - - 580 - 460 - 120 - 40 - - rotate x degree - - - - Relation - - 630 - 400 - 30 - 80 - - lt=<- - 10.0;60.0;10.0;10.0 - - - Relation - - 630 - 490 - 30 - 80 - - lt=<- - 10.0;60.0;10.0;10.0 - - - UMLSpecialState - - 630 - 550 - 20 - 20 - - type=termination - - - diff --git a/doc/TODO allgemein.txt b/doc/TODO allgemein.txt index a3fc74a..4f549fa 100644 --- a/doc/TODO allgemein.txt +++ b/doc/TODO allgemein.txt @@ -1,45 +1,6 @@ -Maybe: - -> Time Measurement in component interface - -> Time warnings - -Do later: - -> Program underfloorLighting - -> Add an beeper - -> Program the beeper - -> Engine slow down without curve in motorControl - -> Network clean up (Mqtt remove?) - -> Extra class for maneuver, autopilot should inherit from int16_t - -> Remote Control - - Leds for gnss rtk etc - - what happens exactly when no data is arriving - -> Test Menu for big curve driving - -> Api with Names and show on Maps in Browser - -> Menu structure mit add functions for each menu mit pointer return to config (additional not replace) - -> Menu Display from parent as run() to make Menu as Component - -> Racing Mode - -> ConsolControl - -> Menü für Einstellungen - - WiFi (save in Flash) - -> Battery - - tabelle mit eigenen Werten übergeben und nicht in header (wiederverwendbarkeit) - - kalibrierungsmethode mit Menü - - Daten in flash speichern können - -> Check speration between Ui and Route (RouteMenu) - -> 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 - - autopilot - - Do now: Code: - Fernbedienung! - Latex: - Anhang: Liste mit allen Komponenten und Kurzbeschreibung - Unterschied funktionale und nicht funktionale Anforderungen Overfull H-Boxen Test Motor, Zeiten kontrolieren. Wenn einfach so dann bezug auf fehler bei Timing und freeRtos Was mit den nicht erfüllten Anforderungen machen? diff --git a/include/moveControl.h b/include/moveControl.h index a10c8a2..27a91bf 100644 --- a/include/moveControl.h +++ b/include/moveControl.h @@ -87,6 +87,7 @@ public: * @param status */ void setDrivingStatus(Status status); + Status getDrivingStatus() const { return this->driving_status; } /** * @brief Stops the engine immediately diff --git a/include/networkConfig.h b/include/networkConfig.h index 13aac37..b594ad6 100644 --- a/include/networkConfig.h +++ b/include/networkConfig.h @@ -14,12 +14,12 @@ #include -#define HW1 +#define HOTSPOT #ifdef HOTSPOT namespace NetworkConfig { - const char ssid[] = "Kleiax Handy"; + const char ssid[] = "KleiaxHandy"; const char password[] = "12345677"; const char ip[] = "192.168.43.4"; const char subnet[] = "255.255.255.0"; diff --git a/lib/Menu b/lib/Menu new file mode 160000 index 0000000..35b1478 --- /dev/null +++ b/lib/Menu @@ -0,0 +1 @@ +Subproject commit 35b147866604e9c95120814a121d7a8df84921e8 diff --git a/lib/MotorControl/motorControl.cpp b/lib/MotorControl/motorControl.cpp index 82a82ba..f112d11 100644 --- a/lib/MotorControl/motorControl.cpp +++ b/lib/MotorControl/motorControl.cpp @@ -33,6 +33,7 @@ void MotorControl::init(uint8_t pwmPin, uint8_t pwmChannel, uint8_t dir_1, uint8 ledcSetup(this->pwmChannel, MotorControl::pwmFreq, MotorControl::pwmRes); ledcAttachPin(this->pwmPin, this->pwmChannel); ledcWrite(this->pwmChannel, 0); + std::cout << "Init pwm" << std::endl; } void MotorControl::run() @@ -56,7 +57,7 @@ void MotorControl::run() return; } - // Positive or negative tagret speed + // Positive or negative target speed if (this->targetPower >= 0) { // Positive or negative speed @@ -97,28 +98,6 @@ void MotorControl::run() } } -void MotorControl::setMinPwm(uint8_t min) -{ - if (min > MotorControl::maxPwmMin) - { - min = MotorControl::maxPwmMin; - } - // transform percentage to real pwm value - min = static_cast(((static_cast(1) << pwmRes) - 1) * (min / 100.0)); - this->dutycycleMin = min; -} - -void MotorControl::setMaxPwm(uint8_t max) -{ - if (max > 100) - { - max = 100; - } - // transform percentage to real pwm value - max = static_cast(((static_cast(1) << pwmRes) - 1) * (max / 100.0)); - this->dutycycleMax = max; -} - void MotorControl::setTargetPower(int8_t power) { if (power <= 100 && power >= -100) @@ -174,10 +153,11 @@ void MotorControl::setRealPower(int8_t power) digitalWrite(this->dir_2, LOW); ledcWrite(this->pwmChannel, 0); this->dutycycle = 0; + std::cout << "abort" << std::endl; return; } - const uint8_t pwm_val = map(abs(power), 0, 100, this->dutycycleMin, this->dutycycleMax); + const uint8_t pwm_val = map(abs(power), 0, 100, MotorControl::minPwmVal, MotorControl::maxPwmVal); if ((this->direction == 1 || this->direction == 0) && power < 0) { // new direction backward @@ -192,6 +172,7 @@ void MotorControl::setRealPower(int8_t power) digitalWrite(this->dir_2, LOW); } + std::cout << "MotorControl::setRealPower pwm_val: " << (int) pwm_val << " channel:" << (int) this->pwmChannel << std::endl; ledcWrite(this->pwmChannel, pwm_val); this->dutycycle = pwm_val; } diff --git a/lib/MotorControl/motorControl.h b/lib/MotorControl/motorControl.h index fc576cd..55c91e9 100644 --- a/lib/MotorControl/motorControl.h +++ b/lib/MotorControl/motorControl.h @@ -38,20 +38,6 @@ public: */ void init(uint8_t pwmPin, uint8_t pwmChannel, uint8_t dir_1, uint8_t dir_2); - /** - * @brief Set the minimum duty cycle - * - * @param min duty cycle in percent - */ - void setMinPwm(uint8_t min); - - /** - * @brief Set the maximum duty cycle - * - * @param max duty cycle in percent - */ - void setMaxPwm(uint8_t max); - /** * @brief Set the Target Power * @@ -103,6 +89,8 @@ private: static constexpr uint8_t pwmRes = 8; static constexpr uint8_t powerSteps = 2; // A total of 20 levels ( 100 / SPEED_STEPS ) * RUN_MOTOR_CONTROL_DELAY = 500ms static constexpr uint8_t maxPwmMin = 80; + static constexpr uint8_t maxPwmVal = 250; + static constexpr uint8_t minPwmVal = 55; // Max 98% of 2^PWM_RES int8_t targetPower = 0; int8_t power = 0; @@ -111,8 +99,6 @@ private: uint8_t pwmPin = 0; uint8_t pwmChannel = 0; uint16_t dutycycle = 0; - uint8_t dutycycleMin = 55; - uint8_t dutycycleMax = 98; // Max 98% of 2^PWM_RES uint8_t dir_1 = 0; uint8_t dir_2 = 0; }; diff --git a/lib/Sensors/sensorData.h b/lib/Sensors/sensorData.h index d95cae7..0e2cd1a 100644 --- a/lib/Sensors/sensorData.h +++ b/lib/Sensors/sensorData.h @@ -13,7 +13,6 @@ #define SENSOR_DATA_H #include -#include #include #include "component.h" diff --git a/platformio.ini b/platformio.ini index 9d9aec8..8aff3e3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,16 +15,14 @@ board_build.partitions = no_ota.csv framework = arduino monitor_speed = 115200 upload_speed = 921600 -; monitor_port = COM6 +monitor_port = COM6 lib_deps = https://git.kleiax.de/PlatformIO-Libs/SparkFunGNSS.git knolleary/PubSubClient@^2.8 br3ttb/PID@^1.2.1 marcoschwartz/LiquidCrystal_I2C@^1.1.4 - bblanchon/ArduinoJson@^6.20.0 mprograms/QMC5883LCompass@^1.2.0 - jrowberg/I2Cdevlib-MPU6050@^1.0.0 -; upload_port = COM6 +upload_port = COM6 test_ignore = test_desktop build_type = debug monitor_filters = esp32_exception_decoder @@ -42,21 +40,3 @@ test_ignore = test_embedded [platformio] description = A Rover who should be drive a route by gps. - - -; Bei Möglichkeit folgendes aus clang tidy entfernen -; cppcoreguidelines-owning-memory -; -; -; -; -; -; -; -; -; -; -; -; -; -# diff --git a/src/SpecialMenus/driveModi/menuDriveMode.cpp b/src/SpecialMenus/driveModi/menuDriveMode.cpp index 527aeca..b949b1e 100644 --- a/src/SpecialMenus/driveModi/menuDriveMode.cpp +++ b/src/SpecialMenus/driveModi/menuDriveMode.cpp @@ -48,7 +48,6 @@ void MenuDriveMode::left() this->firstPrint = true; this->configureOnLeave(); - delete this->menuSpeed; this->driveManager->changeModus(); MenuInformationSites::left(); } diff --git a/src/driveModi/Modi/ManualControl/manualControl.cpp b/src/driveModi/Modi/ManualControl/manualControl.cpp index de54097..cb4bd62 100644 --- a/src/driveModi/Modi/ManualControl/manualControl.cpp +++ b/src/driveModi/Modi/ManualControl/manualControl.cpp @@ -47,7 +47,7 @@ void ManualControl::analogControl() void ManualControl::digitalControl() { - static constexpr uint8_t deadzone = 120; + static constexpr uint8_t deadzone = 110; const int16_t yAxis = this->input->x - 127; const int16_t xAxis = this->input->y - 127; diff --git a/src/main.cpp b/src/main.cpp index e4a49f4..6bca612 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,12 +129,16 @@ void setup() { wifiIndicator = '-'; } + + lcdWrapper = new LcdWrapper(lcd); + lcdWrapper->setCallback(lcdWrapperCallback); + lcdWrapper->loop(); + lcd->backlight(); + lcd->setCursor(0, 0); lcd->printf("%c Kleiax-Rover %c", wifiIndicator, wifiIndicator); lcd->setCursor(0, 1); lcd->printf("WiFi channel %u", Network::getCurrentChannel()); - lcdWrapper = new LcdWrapper(lcd); - lcdWrapper->setCallback(lcdWrapperCallback); makeMenu();