- 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 <PubSubClient.h>
#include <esp_now.h>
#include <esp_wifi.h>
#include "networkConfig.h"
@@ -44,6 +45,7 @@ class Network {
*/
static bool connectWifi();
static bool connectEspNow(recieveCallbackPtr reci, sendCallbackPtr send);
static uint8_t getCurrentChannel();
/**
* @brief Set all general settings to connect to a broker.
+1 -1
View File
@@ -21,7 +21,7 @@
#define PWMRES 8
#define POWERSTEPS 2 // A total of 20 levels ( 100 / SPEED_STEPS ) * RUN_MOTOR_CONTROL_DELAY = 500ms
#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
+3
View File
@@ -185,6 +185,9 @@ class Navigation {
uint16_t getAzimuth() const { return this->azimuth; }
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.
*
@@ -12,7 +12,7 @@
#include "menuSysteminformation.h"
MenuSysteminformation::MenuSysteminformation(Battery* mainBattery)
: MenuInformationSites(5) {
: MenuInformationSites(6) {
this->mainBattery = mainBattery;
}
@@ -44,6 +44,12 @@ void MenuSysteminformation::printPage() const {
break;
case 4:
lineOne = "Current WiFi";
lineTwo = "channel: ";
lineTwo.concat(Network::getCurrentChannel());
break;
case 5:
lineOne = "Kleiax Rover by";
lineTwo = "Alexander Klein";
break;
@@ -17,6 +17,7 @@
#include "controlPadInput.h"
#include "menuInformationSites.h"
#include "battery.h"
#include "network.h"
/**
* @brief Prints information about the current system status.
@@ -158,6 +158,14 @@ void MenuAutopilot::printPage() const {
lineTwo.concat(" - Decrease");
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:
this->printDefault();
return;
@@ -190,6 +198,13 @@ void MenuAutopilot::runCommand() const {
this->minDistance = this->driveManager->getNavigation()->decreaseMinDistanceToReachPoint();
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:
break;
}
@@ -204,7 +219,7 @@ void MenuAutopilot::update() {
}
void MenuAutopilot::init() {
this->setCountPages(10);
this->setCountPages(11);
this->driveManager->changeModus(Modi::Autopilot);
this->autopilot = (Autopilot*) this->driveManager->getDriveModiPtr();
this->routeInfo = this->autopilot->getRouteInfo();
@@ -77,20 +77,25 @@ void MenuCalibrateCompass::printPage() const {
break;
case 7:
lineOne = "Reset for new";
lineTwo = "calibration run";
break;
case 8:
lineOne = "X min: ";
lineOne.concat(this->caliCompass->getCallibrationData().data[0][0]);
lineTwo = "X max: ";
lineTwo.concat(this->caliCompass->getCallibrationData().data[0][1]);
break;
case 8:
case 9:
lineOne = "Y min: ";
lineOne.concat(this->caliCompass->getCallibrationData().data[1][0]);
lineTwo = "Y max: ";
lineTwo.concat(this->caliCompass->getCallibrationData().data[1][1]);
break;
case 9:
case 10:
lineOne = "Z min: ";
lineOne.concat(this->caliCompass->getCallibrationData().data[2][0]);
lineTwo = "Z max: ";
@@ -109,7 +114,7 @@ void MenuCalibrateCompass::init() {
this->firstPrint = false;
this->driveManager->changeModus(Modi::ManualControl);
this->manualControl = (ManualControl*) this->driveManager->getDriveModiPtr();
this->setCountPages(10);
this->setCountPages(11);
this->updateDelay = 500;
}
@@ -125,7 +130,6 @@ void MenuCalibrateCompass::runCommand() const {
case CalibrateCompass::State::Finished:
this->manualControl->setCalibrateCompass();
this->caliCompass->useData();
this->caliCompass->reset();
break;
default:
@@ -149,6 +153,10 @@ void MenuCalibrateCompass::runCommand() const {
this->caliCompass->useData();
break;
case 7:
this->caliCompass->reset();
break;
default:
break;
}
@@ -92,6 +92,14 @@ void MenuCaptureRoute::printPage() const {
lineOne.concat("0");
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:
this->printDefault();
return;
@@ -106,8 +114,23 @@ void MenuCaptureRoute::update() {
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() {
this->setCountPages(7);
this->setCountPages(8);
this->updateDelay = 500;
this->driveManager->changeModus(Modi::CaptureRoute);
this->captureRoute = (CaptureRoute*) this->driveManager->getDriveModiPtr();
@@ -42,6 +42,8 @@ class MenuCaptureRoute : public MenuDriveMode {
*/
void update() override;
void runCommand() const override;
private:
void init() override;
+5 -5
View File
@@ -53,6 +53,7 @@ void Autopilot::runAutopilot() {
case State::NavigationStarted:
this->askNavigationForOrder();
this->checkButtonInput();
break;
case State::GetToStartPoint:
@@ -128,17 +129,16 @@ void Autopilot::checkButtonInput() {
if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action)
&& millis() - this->lastAutopilotChangeMillis > this->autopilotChangeDelayMillis) {
if (this->state == State::SelfDrivingAvailable) {
if (this->state == State::SelfDrivingAvailable)
this->state = State::SelfDriving;
this->updateDisplay = true;
this->lastAutopilotChangeMillis = millis();
} else if (this->state == State::SelfDriving) {
else if (this->state == State::SelfDriving)
this->state = State::SelfDrivingAvailable;
else if (this->state == State::NavigationStarted)
this->state = State::GetToStartPoint;
this->updateDisplay = true;
this->lastAutopilotChangeMillis = millis();
}
}
}
void Autopilot::askNavigationForOrder() {
this->lastOrderStatus = this->navigation->getCourseCorrection(this->courseCorrection);
+15 -31
View File
@@ -118,7 +118,7 @@ void setup() {
lcd->backlight();
lcd->printf("%c Kleiax-Rover %c", wifiIndicator, wifiIndicator);
lcd->setCursor(0, 1);
lcd->print("Press PS-Button");
lcd->printf("WiFi channel %u", Network::getCurrentChannel());
lcdWrapper = new LcdWrapper(lcd);
lcdWrapper->setCallback(lcdWrapperCallback);
@@ -231,41 +231,25 @@ void makeMenu() {
sys_m->setUpdateDelay(1500);
rout_m->setLcd(lcdWrapper);
// Entry for the main menu
MenuAction* mode_e = new MenuAction("Mode", mode_m);
MenuAction* gps_e = new MenuAction("GPS", gps_m);
MenuAction* pid_e = new MenuAction("PID", pid_m);
MenuAction* restart_e = new MenuAction("Restart", restart);
MenuAction* sys_e = new MenuAction("Systeminfo", sys_m);
MenuAction* rout_e = new MenuAction("Route", rout_m);
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);
main_m->addEntry(new MenuAction("Mode", mode_m));
main_m->addEntry(new MenuAction("GPS", gps_m));
main_m->addEntry(new MenuAction("Route", rout_m));
main_m->addEntry(new MenuAction("PID", pid_m));
main_m->addEntry(new MenuAction("Systeminfo", sys_m));
main_m->addEntry(new MenuAction("Restart", restart));
// Entry for the mode Menu
MenuAction* autopilot_e = new MenuAction("Autopilot", auto_m);
MenuAction* captureRoute_e = new MenuAction("Capture Route", cap_m);
MenuAction* consolControl_e = new MenuAction("Consol Control", dummy);
MenuAction* manualControl_e = new MenuAction("Manual Control", man_m);
MenuAction* testMode_e = new MenuAction("Test Mode", testM_m);
MenuAction* caliComp_e = new MenuAction("Gauge Compass", comp_m);
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);
mode_m->addEntry(new MenuAction("Manual Control", man_m));
mode_m->addEntry(new MenuAction("Capture Route", cap_m));
mode_m->addEntry(new MenuAction("Autopilot", auto_m));
mode_m->addEntry(new MenuAction("Gauge Compass", comp_m));
mode_m->addEntry(new MenuAction("Test Mode", testM_m));
mode_m->addEntry(new MenuAction("Consol Control", dummy));
// Entry for the PID Menu
MenuAction* pidl_e = new MenuAction("Left", pidl_m);
MenuAction* pidr_e = new MenuAction("Right", pidr_m);
pid_m->addEntry(pidl_e);
pid_m->addEntry(pidr_e);
pid_m->addEntry(new MenuAction("Left", pidl_m));
pid_m->addEntry(new MenuAction("Right", pidr_m));
// Other config
pidl_m->setMinMax(0, UINT8_MAX);
+13
View File
@@ -113,6 +113,19 @@ bool Network::connectEspNow(recieveCallbackPtr reci, sendCallbackPtr send) {
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() {
static uint64_t lastReconnectAttempt = 0;
if (!mqtt_client->connected()) {