Merge branch 'main' of git.kleiax.de:kleiax/Projektarbeit-Rover into main

This commit is contained in:
2023-08-14 07:15:26 +02:00
39 changed files with 763 additions and 315 deletions
+56 -14
View File
@@ -83,18 +83,13 @@ void MenuRoute::init() {
this->mainMenu = new Menu;
MenuRoutePoints* pointsMenu = new MenuRoutePoints(this->route);
Menu* importMenu = new Menu;
Menu* exportMenu = new Menu;
Menu* clearMenu = new Menu;
this->mainMenu->setLcd(this->lcd);
pointsMenu->setLcd(this->lcd);
importMenu->setLcd(this->lcd);
exportMenu->setLcd(this->lcd);
clearMenu->setLcd(this->lcd);
MenuIntInput* importWrapper = new MenuIntInput(1, new MenuRouteWrapper(this, &MenuRoute::importRoute));
MenuIntInput* exportWrapper = new MenuIntInput(1, new MenuRouteWrapper(this, &MenuRoute::exportRoute));
MenuIntInput* deleteWrapper = new MenuIntInput(1, new MenuRouteWrapper(this, &MenuRoute::deleteRoute));
MenuActionRoute* clearWrapper = new MenuActionRoute(this, &MenuRoute::clearRoute);
importWrapper->setLcd(this->lcd);
@@ -107,15 +102,16 @@ void MenuRoute::init() {
exportWrapper->setPrintParentMenu(false);
exportWrapper->setEntry(0, "Export Route");
MenuAction* pointsAction = new MenuAction("Points", pointsMenu);
MenuAction* importAction = new MenuAction("Import", importWrapper);
MenuAction* exportAction = new MenuAction("Export", exportWrapper);
MenuAction* clearAction = new MenuAction("Clear", clearWrapper);
deleteWrapper->setLcd(this->lcd);
deleteWrapper->setMinMax(0, 100);
deleteWrapper->setPrintParentMenu(false);
deleteWrapper->setEntry(0, "Delete Route");
this->mainMenu->addEntry(pointsAction);
this->mainMenu->addEntry(importAction);
this->mainMenu->addEntry(exportAction);
this->mainMenu->addEntry(clearAction);
this->mainMenu->addEntry(new MenuAction("Points", pointsMenu));
this->mainMenu->addEntry(new MenuAction("Clear", clearWrapper));
this->mainMenu->addEntry(new MenuAction("Import", importWrapper));
this->mainMenu->addEntry(new MenuAction("Export", exportWrapper));
this->mainMenu->addEntry(new MenuAction("Delete", deleteWrapper));
}
void MenuRoute::importRoute(uint8_t routeNumber) {
@@ -236,6 +232,52 @@ void MenuRoute::exportRoute(uint8_t routeNumber) {
http.end();
}
void MenuRoute::deleteRoute(uint8_t routeNumber) {
this->blockInput = true;
String lineOne = "";
String lineTwo = "";
if (WiFi.status() != WL_CONNECTED) {
lineOne = "Not connected to";
lineTwo = "the WiFi.";
this->print(lineOne, lineTwo);
this->blockInput = false;
return;
}
if (ESP.getMaxAllocHeap() < JSON_DOCUMENT_SIZE_ROUTE) {
lineOne = "Not enough mem";
lineTwo = "for Json obj";
this->print(lineOne, lineTwo);
this->blockInput = false;
return;
}
WiFiClient client;
HTTPClient http;
DynamicJsonDocument doc(JSON_DOCUMENT_SIZE_ROUTE);
String host = "http://rover.kleiax.de/api/";
host.concat(routeNumber);
http.begin(client, host);
int httpResponseCode = http.sendRequest("DELETE");
lineOne = "Delete complete";
lineTwo = "Code: ";
if (httpResponseCode == 202)
deserializeJson(doc, http.getStream());
else
lineOne = "HTTP Error";
lineTwo.concat(httpResponseCode);
this->print(lineOne, lineTwo);
this->blockInput = false;
http.end();
}
void MenuRoute::clearRoute(uint8_t none) {
this->route->clear();
this->print("Currente route", "deleted...");
+2
View File
@@ -109,6 +109,8 @@ class MenuRoute : public MenuControl {
*/
void exportRoute(uint8_t routeNumber);
void deleteRoute(uint8_t routeNumber);
/**
* @brief Delete the current Route.
*
@@ -12,7 +12,7 @@
#include "menuSysteminformation.h"
MenuSysteminformation::MenuSysteminformation(Battery* mainBattery)
: MenuInformationSites(5) {
: MenuInformationSites(8) {
this->mainBattery = mainBattery;
}
@@ -44,6 +44,22 @@ void MenuSysteminformation::printPage() const {
break;
case 4:
lineOne = "Current WiFi";
lineTwo = "channel: ";
lineTwo.concat(Network::getCurrentChannel());
break;
case 5:
lineOne = "Software verion:";
lineTwo = VERSION;
break;
case 6:
lineOne = "Build timestamp:";
lineTwo = String(BUILD_TIMESTAMP).substring(0, 16);
break;
case 7:
lineOne = "Kleiax Rover by";
lineTwo = "Alexander Klein";
break;
@@ -14,9 +14,12 @@
#include <Arduino.h>
#include "Version.h"
#include "controlPadInput.h"
#include "menuInformationSites.h"
#include "battery.h"
#include "network.h"
/**
* @brief Prints information about the current system status.
@@ -43,7 +43,7 @@ void MenuAutopilot::printPage() const {
lineTwo = "";
switch (this->autopilot->getState()) {
case Autopilot::State::InsufficientAccuarcy :
lineTwo = "Err: No NTRIP";
lineTwo = "Err: LowAccuracy";
break;
case Autopilot::State::NoRoute :
@@ -66,6 +66,10 @@ void MenuAutopilot::printPage() const {
lineTwo = "Autopilot active";
break;
case Autopilot::State::SelfDrivingRotate :
lineTwo = "Rotating";
break;
case Autopilot::State::TargetReached :
lineTwo = "Target reached";
break;
@@ -158,10 +162,69 @@ 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;
case 11:
lineOne = "CalcAzi: ";
lineTwo = "State: ";
lineOne.concat(this->driveManager->getNavigation()->getCalcAzimuth());
switch (this->driveManager->getNavigation()->getCalcAzimuthState()) {
case Navigation::CalcAzimuthState::Bad :
lineTwo.concat("Bad");
break;
case Navigation::CalcAzimuthState::Good :
lineTwo.concat("Good");
break;
case Navigation::CalcAzimuthState::Invalid :
lineTwo.concat("Invalid");
break;
case Navigation::CalcAzimuthState::Ok :
lineTwo.concat("Ok");
break;
case Navigation::CalcAzimuthState::Super :
lineTwo.concat("Super");
break;
default:
lineTwo.concat("Unkown");
break;
}
break;
case 12:
lineOne = "Test rotate";
lineTwo = "180 degree";
break;
case 13:
lineOne = "Test rotate";
lineTwo = "270 degree";
break;
case 14:
lineOne = "Test rotate";
lineTwo = "45 degree";
break;
case 15:
lineOne = "Test rotate";
lineTwo = "20 degree";
break;
default:
this->printDefault();
return;
}
}
this->print(lineOne, lineTwo);
}
@@ -189,6 +252,29 @@ void MenuAutopilot::runCommand() const {
case 9:
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;
case 12:
this->autopilot->testRotate(180);
break;
case 13:
this->autopilot->testRotate(270);
break;
case 14:
this->autopilot->testRotate(45);
break;
case 15:
this->autopilot->testRotate(20);
break;
default:
break;
@@ -204,7 +290,7 @@ void MenuAutopilot::update() {
}
void MenuAutopilot::init() {
this->setCountPages(10);
this->setCountPages(16);
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:
@@ -147,7 +151,11 @@ void MenuCalibrateCompass::runCommand() const {
case 6:
this->caliCompass->useData();
break;
break;
case 7:
this->caliCompass->reset();
break;
default:
break;
@@ -91,6 +91,14 @@ void MenuCaptureRoute::printPage() const {
else
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();
@@ -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;
@@ -27,44 +27,66 @@ void MenuManualControl::printPage() const {
break;
case 1:
lineOne = "Speed: ";
lineOne.concat(this->manualControl->getMaxSpeed());
lineTwo = "Increase by 0.1";
lineOne = "Input mode:";
if (this->manualControl->getInputMode() == ManualControl::InputMode::Analog)
lineTwo = "Analog";
else
lineTwo = "Digital";
break;
case 2:
lineOne = "Speed: ";
lineOne.concat(this->manualControl->getMaxSpeed());
lineTwo = "Decrease by 0.1";
lineTwo = "Increase by 0.1";
break;
case 3:
lineOne = "RotSpeed: ";
lineOne.concat(this->manualControl->getMaxRotation());
lineTwo = "Increase by 0.1";
lineOne = "Speed: ";
lineOne.concat(this->manualControl->getMaxSpeed());
lineTwo = "Decrease by 0.1";
break;
case 4:
lineOne = "RotSpeed: ";
lineOne.concat(this->manualControl->getMaxRotation());
lineTwo = "Decrease by 0.1";
lineTwo = "Increase by 0.1";
break;
case 5:
lineOne = "RotSpeed: ";
lineOne.concat(this->manualControl->getMaxRotation());
lineTwo = "Decrease by 0.1";
break;
case 6:
lineOne = "Dutycycle Left:";
lineTwo.concat(this->manualControl->getDutycycleLeft());
break;
case 6:
case 7:
lineOne = "Dutycycle Right:";
lineTwo.concat(this->manualControl->getDutycycleRight());
break;
case 7:
case 8:
lineOne = "Azimuth:";
lineTwo.concat(this->driveManager->getNavigation()->getAzimuth());
break;
case 9: {
UBX_NAV_PVT_data_t* gpsData = this->driveManager->getNavigation()->getUbxData();
lineOne = "magDec: ";
lineTwo = "magAcc: ";
if (gpsData->valid.bits.validMag) {
lineOne.concat(gpsData->magDec);
lineTwo.concat(gpsData->magAcc);
} else {
lineOne.concat("invalid");
lineTwo.concat("invalid");
}
break;
}
default:
this->printDefault();
return;
@@ -77,28 +99,31 @@ void MenuManualControl::init() {
this->firstPrint = false;
this->driveManager->changeModus(Modi::ManualControl);
this->manualControl = (ManualControl*) this->driveManager->getDriveModiPtr();
this->setCountPages(8);
this->setCountPages(10);
this->updateDelay = 500;
}
void MenuManualControl::runCommand() const {
switch (this->getCurrentPage()) {
case 1:
this->manualControl->increaseMaxSpeed();
this->manualControl->switchInputMode();
break;
case 2:
this->manualControl->decreaseMaxSpeed();
this->manualControl->increaseMaxSpeed();
break;
case 3:
this->manualControl->increaseMaxRotation();
this->manualControl->decreaseMaxSpeed();
break;
case 4:
this->manualControl->increaseMaxRotation();
break;
case 5:
this->manualControl->increaseMaxRotation();
break;
default:
break;
+86 -19
View File
@@ -12,13 +12,31 @@
#include "driveModi/Modi/Autopilot/autopilot.h"
#include "autopilot.h"
DirectionChangeSignal::DirectionChangeSignal(Navigation* navigation) {
this->navigation = navigation;
this->action();
}
DirectionChangeSignal::~DirectionChangeSignal() {
navigation->dissableCalcAzimuth();
}
void DirectionChangeSignal::action() {
this->navigation->drivingDirectionChange();
}
Autopilot::Autopilot(MoveControl* moveControl, const ControlPadInput *input, Navigation* navigation)
: ManualControl(moveControl, input) {
this->setInputMode(ManualControl::InputMode::Digital);
this->directionChangeSignal = new DirectionChangeSignal(navigation);
this->setDirectionChangeCallback(this->directionChangeSignal);
this->navigation = navigation;
this->init();
}
Autopilot::~Autopilot() {
delete this->directionChangeSignal;
// this->navigation->getNTRIPClient()->setActivated(false);
}
@@ -53,6 +71,7 @@ void Autopilot::runAutopilot() {
case State::NavigationStarted:
this->askNavigationForOrder();
this->checkButtonInput();
break;
case State::GetToStartPoint:
@@ -72,6 +91,11 @@ void Autopilot::runAutopilot() {
this->selfDriving();
break;
case SelfDrivingRotate:
this->checkButtonInput();
this->rotate();
break;
case State::TargetReached:
break;
@@ -92,6 +116,14 @@ bool Autopilot::shouldUpdate() {
return false;
}
void Autopilot::testRotate(int16_t degree) {
if (!degree)
return;
this->courseCorrection.correction = degree;
this->beginRotate();
}
void Autopilot::init() {
if (this->navigation->startNavigation())
this->state = State::NavigationStarted;
@@ -115,28 +147,62 @@ void Autopilot::drive() {
this,moveControl->setSpeed(0);
}
void Autopilot::rotate() {
this->moveControl->setSpeed(0);
if (this->courseCorrection.correction > 0)
this->moveControl->setRotationSpeed(this->rotationSpeed);
else
void Autopilot::beginRotate() {
if (this->state != State::SelfDrivingRotate) {
this->lastState = this->state;
this->state = State::SelfDrivingRotate;
this->rotationAimAzimuth = this->navigation->getAzimuth() + this->courseCorrection.correction;
this->rotationAimAzimuth = Navigation::fixDegree(this->rotationAimAzimuth);
this->moveControl->setRotationSpeed(-this->rotationSpeed);
this->moveControl->setSpeed(0);
if (this->courseCorrection.correction > 0)
this->moveControl->setRotationSpeed(-this->rotationSpeed);
else
this->moveControl->setRotationSpeed(this->rotationSpeed);
}
}
void Autopilot::rotate() {
if (abs(this->navigation->getAzimuth() - this->rotationAimAzimuth) < 5) {
this->endRotate();
return;
}
if ((abs(this->navigation->getAzimuth() - this->rotationAimAzimuth) < 15)
&&
((this->courseCorrection.correction > 0
&& this->rotationAimAzimuth < this->navigation->getAzimuth())
|| (this->courseCorrection.correction < 0
&& this->rotationAimAzimuth > this->navigation->getAzimuth())))
{
this->endRotate();
std::cout << "Autopilot::rotate: Rover rotated too far" << std::endl;
}
}
void Autopilot::endRotate() {
if (this->state != State::SelfDrivingRotate)
return;
this->state = this->lastState;
this->navigation->drivingDirectionChange();
this->moveControl->setRotationSpeed(0);
this->moveControl->emergencyStop();
this->moveControl->setDrivingStatus(MoveControl::Status::Drive);
}
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::SelfDrivingRotate)
this->state = State::SelfDrivingAvailable;
this->updateDisplay = true;
this->lastAutopilotChangeMillis = millis();
}
else if (this->state == State::NavigationStarted)
this->state = State::GetToStartPoint;
this->updateDisplay = true;
this->lastAutopilotChangeMillis = millis();
}
}
@@ -172,10 +238,11 @@ void Autopilot::askNavigationForOrder() {
}
void Autopilot::selfDriving() {
if (this->lastOrderStatus == Navigation::Status::Updated) {
if (abs(this->courseCorrection.correction) >= this->maxCourseDeviationBerforeAct)
this->rotate();
else
this->drive();
}
if (this->state != State::SelfDriving)
return;
if (abs(this->courseCorrection.correction) >= this->maxCourseDeviationBerforeAct)
this->beginRotate();
else
this->drive();
}
+19 -10
View File
@@ -17,6 +17,16 @@
#include "moveControl.h"
#include "driveModi/Modi/ManualControl/manualControl.h"
class DirectionChangeSignal : public DirectionChangeWrapper {
public:
DirectionChangeSignal(Navigation* navigation);
~DirectionChangeSignal();
void action() override;
private:
Navigation* navigation;
};
/**
* @brief This class use the navigate class to drive automaticaly
*
@@ -36,6 +46,7 @@ class Autopilot : public ManualControl {
GetToStartPoint,
SelfDrivingAvailable,
SelfDriving,
SelfDrivingRotate,
TargetReached
};
@@ -66,15 +77,6 @@ class Autopilot : public ManualControl {
*/
void loop();
/**
* @brief Manges the autopilot
*
* If the first Point is near to current location you can turn
* the autopilot on.
* Gets the course correction and decide what to do.
*/
void runAutopilot();
void restart();
/**
@@ -105,11 +107,15 @@ class Autopilot : public ManualControl {
* @return false
*/
bool shouldUpdate();
void testRotate(int16_t degree);
void endRotate();
private:
void init();
void drive();
void beginRotate();
void rotate();
void runAutopilot();
void checkButtonInput();
void askNavigationForOrder();
void selfDriving();
@@ -120,6 +126,7 @@ class Autopilot : public ManualControl {
State state = State::None;
State lastState = State::None;
Navigation::Status lastOrderStatus;
DirectionChangeSignal* directionChangeSignal;
bool updateDisplay = false;
@@ -131,8 +138,10 @@ class Autopilot : public ManualControl {
uint32_t loopLastMillis = 0;
uint32_t lastAutopilotChangeMillis = 0;
int16_t rotationAimAzimuth;
double drivingSpeed = 1;
double rotationSpeed = 3;
double rotationSpeed = 4.5;
double minRemainingDistance = 0.25;
};
@@ -26,14 +26,30 @@ void ManualControl::loop() {
if (this->caliCompass)
this->caliCompass->loop();
if (millis() - this->lastMillis < delay) {
if (millis() - this->lastMillis < delay)
return;
switch (this->inputMode) {
case InputMode::Analog :
this->analogControl();
break;
case InputMode::Digital :
this->digitalControl();
break;
default:
break;
}
this->runManualControl();
this->lastMillis = millis();
}
void ManualControl::runManualControl() {
void ManualControl::switchInputMode() {
this->inputMode = (this->inputMode == InputMode::Analog) ? InputMode::Digital : InputMode::Analog;
}
void ManualControl::analogControl() {
// Have to be int16_t to avoid overflow (int8_t = 255 - 127 = -128)
int16_t y = this->input->x - 127;
int16_t x = this->input->y - 127;
@@ -49,3 +65,30 @@ void ManualControl::runManualControl() {
value_per_step = this->max_rotation * 2 / UINT8_MAX;
this->moveControl->setRotationSpeed(x * value_per_step);
}
void ManualControl::digitalControl() {
int16_t y = this->input->x - 127;
int16_t x = this->input->y - 127;
if (y > 120)
this->moveControl->setSpeed(-this->max_speed);
else if (y < -120)
this->moveControl->setSpeed(this->max_speed);
else
this->moveControl->setSpeed(0);
if (x > 120)
this->moveControl->setRotationSpeed(this->max_rotation);
else if (x < -120)
this->moveControl->setRotationSpeed(-this->max_rotation);
else
this->moveControl->setRotationSpeed(0);
if (this->directionChangeWrapper && (x > 120 || x < -120))
this->lastLoopTurned = true;
else if (this->lastLoopTurned) {
if (this->directionChangeWrapper)
this->directionChangeWrapper->action();
this->lastLoopTurned = false;
}
}
@@ -16,6 +16,11 @@
#include "controlPadInput.h"
#include "calibrateCompass.h"
class DirectionChangeWrapper {
public:
virtual void action() = 0;
};
/**
* @brief Drive the Rover with a Joystick
*
@@ -26,6 +31,11 @@
*/
class ManualControl : public DriveModi {
public:
enum class InputMode : uint8_t {
Analog,
Digital
};
ManualControl(MoveControl *moveControl, const ControlPadInput *input);
/**
@@ -35,7 +45,7 @@ class ManualControl : public DriveModi {
~ManualControl();
/**
* @brief Calls runManualControl() to update all values.
* @brief Calls analogControl() to update all values.
*
* This function should be called every mainloop. If the delay is not reached, than the
* functions returns immediately.
@@ -44,12 +54,6 @@ class ManualControl : public DriveModi {
*/
void loop() override;
/**
* @brief Noramly called repeatedly by loop() to calcluate new values.
* Set new values for speed and rotation in moveControl
*/
void runManualControl();
/**
* @brief Set the min delay between each loop
*
@@ -79,6 +83,11 @@ class ManualControl : public DriveModi {
void setCalibrateCompass(CalibrateCompass* val = nullptr) { this->caliCompass = val; }
void switchInputMode();
void setInputMode(InputMode mode) { this->inputMode = mode; }
InputMode getInputMode() const { return this->inputMode; }
void setDirectionChangeCallback(DirectionChangeWrapper* callback) { this->directionChangeWrapper = callback; }
uint16_t getDutycycleLeft() const { return this->moveControl->getDutycycleLeft(); }
uint16_t getDutycycleRight() const { return this->moveControl->getDutycycleRight(); }
@@ -87,11 +96,21 @@ class ManualControl : public DriveModi {
const ControlPadInput* input;
private:
uint32_t lastMillis = 0;
/**
* @brief Noramly called repeatedly by loop() to calcluate new values.
* Set new values for speed and rotation in moveControl
*/
void analogControl();
void digitalControl();
bool lastLoopTurned = false;
uint8_t delay = 10;
uint32_t lastMillis = 0;
double max_speed = 1;
double max_rotation = 7;
CalibrateCompass* caliCompass = nullptr;
DirectionChangeWrapper* directionChangeWrapper = nullptr;
InputMode inputMode = InputMode::Analog;
};
#endif // MANUAL_CONTROL_H
+19 -31
View File
@@ -22,6 +22,8 @@
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include "Version.h"
#include "driveModi/driveManager.h"
#include "OutputBuf/outputBuf.h"
#include "LcdWrapper.h"
@@ -109,6 +111,8 @@ void setup() {
Network::connectEspNow(receiveCallback, sendCallback);
std::cout << "Welcome to Kleiax-Rover" << std::endl;
std::cout << "Project verion: " << VERSION << std::endl;
std::cout << "Build timestamp: " << BUILD_TIMESTAMP << std::endl;
std::cout << "All actions from the main program run on Core -> " << xPortGetCoreID() << std::endl;
driveManager = new DriveManager(&moveController, spiPort, controlPad->getControlPadDataPtr(), wifiIsActive);
@@ -118,7 +122,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 +235,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);
+2 -2
View File
@@ -187,9 +187,9 @@ void MoveControl::calcTargetWheelSpeed() {
\ 1 -b / \ T / \ Xr / */
// (1 / r) * 1
const static double A = 15.82278481;
constexpr double A = 15.82278481;
// (1 / r) * b
const static double B = 2.096518987;
constexpr double B = 2.096518987;
this->wheelspeed_right_target = (A * this->x_speed + B * this->rotation_speed) * (WHEEL_DIAMETER / 2);
this->wheelspeed_left_target = (A * this->x_speed + (-B) * this->rotation_speed) * (WHEEL_DIAMETER / 2);
+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()) {