- added wifi channel on boot screen

- added wifi to systeminformation
- added accuracy settings to capturee route and autopilot
- fix data loss in calibrate compass
- fix autopilot dont switch to ready for selfdriving
This commit is contained in:
2023-06-02 22:30:21 +02:00
parent 38c8a58988
commit 8796da97b5
12 changed files with 104 additions and 47 deletions
+2
View File
@@ -16,6 +16,7 @@
#include <WiFi.h> #include <WiFi.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include <esp_now.h> #include <esp_now.h>
#include <esp_wifi.h>
#include "networkConfig.h" #include "networkConfig.h"
@@ -44,6 +45,7 @@ class Network {
*/ */
static bool connectWifi(); static bool connectWifi();
static bool connectEspNow(recieveCallbackPtr reci, sendCallbackPtr send); static bool connectEspNow(recieveCallbackPtr reci, sendCallbackPtr send);
static uint8_t getCurrentChannel();
/** /**
* @brief Set all general settings to connect to a broker. * @brief Set all general settings to connect to a broker.
+1 -1
View File
@@ -21,7 +21,7 @@
#define PWMRES 8 #define PWMRES 8
#define POWERSTEPS 2 // A total of 20 levels ( 100 / SPEED_STEPS ) * RUN_MOTOR_CONTROL_DELAY = 500ms #define POWERSTEPS 2 // A total of 20 levels ( 100 / SPEED_STEPS ) * RUN_MOTOR_CONTROL_DELAY = 500ms
#define PWMMIN 55 #define PWMMIN 55
#define PWMMAX 80 // Max 98% of 2^PWM_RES #define PWMMAX 90 // Max 98% of 2^PWM_RES
/** /**
* @brief A class which use PWM to control the power of DC Motor * @brief A class which use PWM to control the power of DC Motor
+3
View File
@@ -185,6 +185,9 @@ class Navigation {
uint16_t getAzimuth() const { return this->azimuth; } uint16_t getAzimuth() const { return this->azimuth; }
QMC5883LCompass* getCompass() const { return this->compass; } QMC5883LCompass* getCompass() const { return this->compass; }
Point::Accuracy getMinAccuracy() const { return this->minAccuracy; }
void setMinAccuracy(Point::Accuracy accuracy) { this->minAccuracy = accuracy; }
/** /**
* @brief Set the output status for PVTdata. * @brief Set the output status for PVTdata.
* *
@@ -12,7 +12,7 @@
#include "menuSysteminformation.h" #include "menuSysteminformation.h"
MenuSysteminformation::MenuSysteminformation(Battery* mainBattery) MenuSysteminformation::MenuSysteminformation(Battery* mainBattery)
: MenuInformationSites(5) { : MenuInformationSites(6) {
this->mainBattery = mainBattery; this->mainBattery = mainBattery;
} }
@@ -44,6 +44,12 @@ void MenuSysteminformation::printPage() const {
break; break;
case 4: case 4:
lineOne = "Current WiFi";
lineTwo = "channel: ";
lineTwo.concat(Network::getCurrentChannel());
break;
case 5:
lineOne = "Kleiax Rover by"; lineOne = "Kleiax Rover by";
lineTwo = "Alexander Klein"; lineTwo = "Alexander Klein";
break; break;
@@ -17,6 +17,7 @@
#include "controlPadInput.h" #include "controlPadInput.h"
#include "menuInformationSites.h" #include "menuInformationSites.h"
#include "battery.h" #include "battery.h"
#include "network.h"
/** /**
* @brief Prints information about the current system status. * @brief Prints information about the current system status.
@@ -158,6 +158,14 @@ void MenuAutopilot::printPage() const {
lineTwo.concat(" - Decrease"); lineTwo.concat(" - Decrease");
break; break;
case 10:
lineOne = "Current minimal";
if (this->driveManager->getNavigation()->getMinAccuracy() >= Point::Accuracy::twoDigOfCM)
lineTwo = "accuracy is high";
else
lineTwo = "accuracy is low";
break;
default: default:
this->printDefault(); this->printDefault();
return; return;
@@ -189,6 +197,13 @@ void MenuAutopilot::runCommand() const {
case 9: case 9:
this->minDistance = this->driveManager->getNavigation()->decreaseMinDistanceToReachPoint(); this->minDistance = this->driveManager->getNavigation()->decreaseMinDistanceToReachPoint();
break; break;
case 10:
if (this->driveManager->getNavigation()->getMinAccuracy() >= Point::Accuracy::twoDigOfCM)
this->driveManager->getNavigation()->setMinAccuracy(Point::Accuracy::none);
else
this->driveManager->getNavigation()->setMinAccuracy(Point::Accuracy::twoDigOfCM);
break;
default: default:
break; break;
@@ -204,7 +219,7 @@ void MenuAutopilot::update() {
} }
void MenuAutopilot::init() { void MenuAutopilot::init() {
this->setCountPages(10); this->setCountPages(11);
this->driveManager->changeModus(Modi::Autopilot); this->driveManager->changeModus(Modi::Autopilot);
this->autopilot = (Autopilot*) this->driveManager->getDriveModiPtr(); this->autopilot = (Autopilot*) this->driveManager->getDriveModiPtr();
this->routeInfo = this->autopilot->getRouteInfo(); this->routeInfo = this->autopilot->getRouteInfo();
@@ -77,20 +77,25 @@ void MenuCalibrateCompass::printPage() const {
break; break;
case 7: case 7:
lineOne = "Reset for new";
lineTwo = "calibration run";
break;
case 8:
lineOne = "X min: "; lineOne = "X min: ";
lineOne.concat(this->caliCompass->getCallibrationData().data[0][0]); lineOne.concat(this->caliCompass->getCallibrationData().data[0][0]);
lineTwo = "X max: "; lineTwo = "X max: ";
lineTwo.concat(this->caliCompass->getCallibrationData().data[0][1]); lineTwo.concat(this->caliCompass->getCallibrationData().data[0][1]);
break; break;
case 8: case 9:
lineOne = "Y min: "; lineOne = "Y min: ";
lineOne.concat(this->caliCompass->getCallibrationData().data[1][0]); lineOne.concat(this->caliCompass->getCallibrationData().data[1][0]);
lineTwo = "Y max: "; lineTwo = "Y max: ";
lineTwo.concat(this->caliCompass->getCallibrationData().data[1][1]); lineTwo.concat(this->caliCompass->getCallibrationData().data[1][1]);
break; break;
case 9: case 10:
lineOne = "Z min: "; lineOne = "Z min: ";
lineOne.concat(this->caliCompass->getCallibrationData().data[2][0]); lineOne.concat(this->caliCompass->getCallibrationData().data[2][0]);
lineTwo = "Z max: "; lineTwo = "Z max: ";
@@ -109,7 +114,7 @@ void MenuCalibrateCompass::init() {
this->firstPrint = false; this->firstPrint = false;
this->driveManager->changeModus(Modi::ManualControl); this->driveManager->changeModus(Modi::ManualControl);
this->manualControl = (ManualControl*) this->driveManager->getDriveModiPtr(); this->manualControl = (ManualControl*) this->driveManager->getDriveModiPtr();
this->setCountPages(10); this->setCountPages(11);
this->updateDelay = 500; this->updateDelay = 500;
} }
@@ -125,7 +130,6 @@ void MenuCalibrateCompass::runCommand() const {
case CalibrateCompass::State::Finished: case CalibrateCompass::State::Finished:
this->manualControl->setCalibrateCompass(); this->manualControl->setCalibrateCompass();
this->caliCompass->useData(); this->caliCompass->useData();
this->caliCompass->reset();
break; break;
default: default:
@@ -147,7 +151,11 @@ void MenuCalibrateCompass::runCommand() const {
case 6: case 6:
this->caliCompass->useData(); this->caliCompass->useData();
break; break;
case 7:
this->caliCompass->reset();
break;
default: default:
break; break;
@@ -91,6 +91,14 @@ void MenuCaptureRoute::printPage() const {
else else
lineOne.concat("0"); lineOne.concat("0");
break; break;
case 7:
lineOne = "Current minimal";
if (this->driveManager->getNavigation()->getMinAccuracy() >= Point::Accuracy::twoDigOfCM)
lineTwo = "accuracy is high";
else
lineTwo = "accuracy is low";
break;
default: default:
this->printDefault(); this->printDefault();
@@ -106,8 +114,23 @@ void MenuCaptureRoute::update() {
this->printMenu(); this->printMenu();
} }
void MenuCaptureRoute::runCommand() const {
switch (this->getCurrentPage())
{
case 7:
if (this->driveManager->getNavigation()->getMinAccuracy() >= Point::Accuracy::twoDigOfCM)
this->driveManager->getNavigation()->setMinAccuracy(Point::Accuracy::none);
else
this->driveManager->getNavigation()->setMinAccuracy(Point::Accuracy::twoDigOfCM);
break;
default:
break;
}
}
void MenuCaptureRoute::init() { void MenuCaptureRoute::init() {
this->setCountPages(7); this->setCountPages(8);
this->updateDelay = 500; this->updateDelay = 500;
this->driveManager->changeModus(Modi::CaptureRoute); this->driveManager->changeModus(Modi::CaptureRoute);
this->captureRoute = (CaptureRoute*) this->driveManager->getDriveModiPtr(); this->captureRoute = (CaptureRoute*) this->driveManager->getDriveModiPtr();
@@ -42,6 +42,8 @@ class MenuCaptureRoute : public MenuDriveMode {
*/ */
void update() override; void update() override;
void runCommand() const override;
private: private:
void init() override; void init() override;
+7 -7
View File
@@ -53,6 +53,7 @@ void Autopilot::runAutopilot() {
case State::NavigationStarted: case State::NavigationStarted:
this->askNavigationForOrder(); this->askNavigationForOrder();
this->checkButtonInput();
break; break;
case State::GetToStartPoint: case State::GetToStartPoint:
@@ -128,15 +129,14 @@ void Autopilot::checkButtonInput() {
if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action) if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action)
&& millis() - this->lastAutopilotChangeMillis > this->autopilotChangeDelayMillis) { && millis() - this->lastAutopilotChangeMillis > this->autopilotChangeDelayMillis) {
if (this->state == State::SelfDrivingAvailable) { if (this->state == State::SelfDrivingAvailable)
this->state = State::SelfDriving; this->state = State::SelfDriving;
this->updateDisplay = true; else if (this->state == State::SelfDriving)
this->lastAutopilotChangeMillis = millis();
} else if (this->state == State::SelfDriving) {
this->state = State::SelfDrivingAvailable; this->state = State::SelfDrivingAvailable;
this->updateDisplay = true; else if (this->state == State::NavigationStarted)
this->lastAutopilotChangeMillis = millis(); this->state = State::GetToStartPoint;
} this->updateDisplay = true;
this->lastAutopilotChangeMillis = millis();
} }
} }
+15 -31
View File
@@ -118,7 +118,7 @@ void setup() {
lcd->backlight(); lcd->backlight();
lcd->printf("%c Kleiax-Rover %c", wifiIndicator, wifiIndicator); lcd->printf("%c Kleiax-Rover %c", wifiIndicator, wifiIndicator);
lcd->setCursor(0, 1); lcd->setCursor(0, 1);
lcd->print("Press PS-Button"); lcd->printf("WiFi channel %u", Network::getCurrentChannel());
lcdWrapper = new LcdWrapper(lcd); lcdWrapper = new LcdWrapper(lcd);
lcdWrapper->setCallback(lcdWrapperCallback); lcdWrapper->setCallback(lcdWrapperCallback);
@@ -231,41 +231,25 @@ void makeMenu() {
sys_m->setUpdateDelay(1500); sys_m->setUpdateDelay(1500);
rout_m->setLcd(lcdWrapper); rout_m->setLcd(lcdWrapper);
// Entry for the main menu // Entry for the main menu
MenuAction* mode_e = new MenuAction("Mode", mode_m); main_m->addEntry(new MenuAction("Mode", mode_m));
MenuAction* gps_e = new MenuAction("GPS", gps_m); main_m->addEntry(new MenuAction("GPS", gps_m));
MenuAction* pid_e = new MenuAction("PID", pid_m); main_m->addEntry(new MenuAction("Route", rout_m));
MenuAction* restart_e = new MenuAction("Restart", restart); main_m->addEntry(new MenuAction("PID", pid_m));
MenuAction* sys_e = new MenuAction("Systeminfo", sys_m); main_m->addEntry(new MenuAction("Systeminfo", sys_m));
MenuAction* rout_e = new MenuAction("Route", rout_m); main_m->addEntry(new MenuAction("Restart", restart));
main_m->addEntry(mode_e);
main_m->addEntry(gps_e);
main_m->addEntry(rout_e);
main_m->addEntry(pid_e);
main_m->addEntry(sys_e);
main_m->addEntry(restart_e);
// Entry for the mode Menu // Entry for the mode Menu
MenuAction* autopilot_e = new MenuAction("Autopilot", auto_m); mode_m->addEntry(new MenuAction("Manual Control", man_m));
MenuAction* captureRoute_e = new MenuAction("Capture Route", cap_m); mode_m->addEntry(new MenuAction("Capture Route", cap_m));
MenuAction* consolControl_e = new MenuAction("Consol Control", dummy); mode_m->addEntry(new MenuAction("Autopilot", auto_m));
MenuAction* manualControl_e = new MenuAction("Manual Control", man_m); mode_m->addEntry(new MenuAction("Gauge Compass", comp_m));
MenuAction* testMode_e = new MenuAction("Test Mode", testM_m); mode_m->addEntry(new MenuAction("Test Mode", testM_m));
MenuAction* caliComp_e = new MenuAction("Gauge Compass", comp_m); mode_m->addEntry(new MenuAction("Consol Control", dummy));
mode_m->addEntry(manualControl_e);
mode_m->addEntry(captureRoute_e);
mode_m->addEntry(autopilot_e);
mode_m->addEntry(caliComp_e);
mode_m->addEntry(testMode_e);
mode_m->addEntry(consolControl_e);
// Entry for the PID Menu // Entry for the PID Menu
MenuAction* pidl_e = new MenuAction("Left", pidl_m); pid_m->addEntry(new MenuAction("Left", pidl_m));
MenuAction* pidr_e = new MenuAction("Right", pidr_m); pid_m->addEntry(new MenuAction("Right", pidr_m));
pid_m->addEntry(pidl_e);
pid_m->addEntry(pidr_e);
// Other config // Other config
pidl_m->setMinMax(0, UINT8_MAX); pidl_m->setMinMax(0, UINT8_MAX);
+13
View File
@@ -113,6 +113,19 @@ bool Network::connectEspNow(recieveCallbackPtr reci, sendCallbackPtr send) {
return true; return true;
} }
uint8_t Network::getCurrentChannel() {
uint8_t channel;
wifi_second_chan_t secondChannel;
if (esp_wifi_get_channel(&channel, &secondChannel) != ESP_OK) {
std::cout << "Network::getCurrentChannel - Error!" << std::endl;
return -1;
}
// std::cout << "Network::getCurrentChannel - Current WiFi channel: "
// << (int) channel << " second channel: " << (int) secondChannel
// << std::endl;
return channel;
}
bool Network::checkMQTT() { bool Network::checkMQTT() {
static uint64_t lastReconnectAttempt = 0; static uint64_t lastReconnectAttempt = 0;
if (!mqtt_client->connected()) { if (!mqtt_client->connected()) {