ntrip, testMode, zed9 gnss modul

This commit is contained in:
2022-09-13 20:31:52 +02:00
parent c7cb0d3895
commit af6cb98898
43 changed files with 907 additions and 262 deletions
+2 -2
View File
@@ -61,9 +61,9 @@ void MenuAkku::printMenu() {
}
void MenuAkku::update() {
if (millis() - this->last_millis < this->delay) {
if (millis() - this->lastMillis < this->delay) {
return;
}
this->printMenu();
this->last_millis = millis();
this->lastMillis = millis();
}
+1 -1
View File
@@ -55,7 +55,7 @@ class MenuAkku : public MenuControl {
private:
const uint16_t delay = 15000;
uint32_t last_millis = 0;
uint32_t lastMillis = 0;
Battery* mainBattery;
+74 -64
View File
@@ -13,7 +13,7 @@
MenuGPS::MenuGPS(SFE_UBLOX_GNSS* gps) {
this->gps = gps;
this->last_millis = millis();
this->lastMillis = millis();
}
void MenuGPS::up() {
@@ -54,76 +54,86 @@ void MenuGPS::printMenu() {
}
void MenuGPS::update() {
if (millis() - this->last_millis < this->delay) {
if (millis() - this->lastMillis < this->delay) {
return;
}
this->printMenu();
this->last_millis = millis();
this->lastMillis = millis();
}
void MenuGPS::printPage(uint8_t page) const {
//FIXME: new gpslib
// switch (this->currentPage) {
// case 0:
// if (this->lcd) {
// lcd->clear();
// lcd->setCursor(0, 0);
// if (gps->satellites.isValid() && gps->satellites.value() > 2) {
// lcd->printf("Sats: %3.d", gps->satellites.value());
// lcd->setCursor(0, 1);
// lcd->printf("HDOP: %f", gps->hdop.hdop());
// } else {
// lcd->printf("Data isn't valid");
// lcd->setCursor(0, 1);
// lcd->printf("or no GPS signal");
// }
// }
// if (gps->satellites.isValid() && gps->satellites.value() > 2)
// std::cout << "Sats: " << gps->satellites.value()
// << "HDOP: " << gps->hdop.hdop() << std::endl;
// else
// std::cout << "Data isn't valid or no GPS signal" << std::endl;
// break;
uint8_t fixType = gps->getFixType();
switch (this->currentPage) {
case 0: {
uint8_t siv = gps->getSIV();
uint16_t hdop = gps->getHorizontalDOP();
if (this->lcd) {
lcd->clear();
lcd->setCursor(0, 0);
if (fixType) {
lcd->printf("Sats: %3.u", siv);
lcd->setCursor(0, 1);
lcd->printf("HDOP: %u", hdop);
} else {
lcd->printf("Data isn't valid");
lcd->setCursor(0, 1);
lcd->printf("or no GPS signal");
}
}
if (fixType)
std::cout << "Sats: " << (int) siv
<< "HDOP: " << (int) hdop << std::endl;
else
std::cout << "Data isn't valid or no GPS signal" << std::endl;
}
break;
// case 1:
// if (this->lcd) {
// lcd->clear();
// lcd->setCursor(0, 0);
// if (gps->location.isValid() && gps->satellites.value() > 2) {
// lcd->printf("Lat: %9.6f", gps->location.lat());
// lcd->setCursor(0, 1);
// lcd->printf("Lng: %9.6f", gps->location.lng());
// } else {
// lcd->printf("Data isn't valid");
// lcd->setCursor(0, 1);
// lcd->printf("or NO GPS signal");
// }
// }
// if (gps->satellites.isValid() && gps->satellites.value() > 2)
// std::cout << "Lat: " << gps->location.lat()
// << "Lng: " << gps->location.lng() << std::endl;
// else
// std::cout << "Data isn't valid or NO GPS signal" << std::endl;
// break;
case 1: {
int32_t lat = gps->getLatitude();
int32_t lng = gps->getLongitude();
if (this->lcd) {
lcd->clear();
lcd->setCursor(0, 0);
if (fixType) {
lcd->printf("Lat: %d", lat);
lcd->setCursor(0, 1);
lcd->printf("Lng: %d", lng);
} else {
lcd->printf("Data isn't valid");
lcd->setCursor(0, 1);
lcd->printf("or NO GPS signal");
}
}
if (fixType)
std::cout << "Lat: " << lat
<< "Lng: " << lng << std::endl;
else
std::cout << "Data isn't valid or NO GPS signal" << std::endl;
}
break;
// case 2:
// if (this->lcd) {
// lcd->clear();
// lcd->setCursor(0, 0);
// lcd->printf("Chars processed");
// lcd->setCursor(0, 1);
// lcd->printf("-> %u", gps->charsProcessed());
// }
// std::cout << "Chars processed: " << gps->charsProcessed() << std::endl;
// break;
case 2: {
uint32_t unixEpoch = gps->getUnixEpoch();
if (this->lcd) {
lcd->clear();
lcd->setCursor(0, 0);
lcd->printf("Unix Epoch");
lcd->setCursor(0, 1);
lcd->printf("-> %u", unixEpoch);
}
std::cout << "Unix Epoch: " << (int) unixEpoch << std::endl;
}
break;
// default:
// if (this->lcd) {
// lcd->clear();
// lcd->setCursor(0, 0);
// lcd->printf("Page: %u", page);
// }
// std::cout << "Page: " << (int) page << std::endl;
// break;
// }
default:
if (this->lcd) {
lcd->clear();
lcd->setCursor(0, 0);
lcd->printf("Page: %u", page);
}
std::cout << "Page: " << (int) page << std::endl;
break;
}
}
+1 -1
View File
@@ -82,7 +82,7 @@ class MenuGPS : public MenuControl {
SFE_UBLOX_GNSS* gps;
const uint16_t delay = 5000;
uint32_t last_millis = 0;
uint32_t lastMillis = 0;
};
#endif // MENU_GPS_H
@@ -74,9 +74,9 @@ void MenuAutopilot::printMenu() {
}
void MenuAutopilot::update() {
if (millis() - this->last_millis < this->minDelay)
if (millis() - this->lastMillis < this->minDelay)
return;
this->last_millis = millis();
this->lastMillis = millis();
if (!this->autopilot->shouldUpdate())
return;
@@ -49,7 +49,7 @@ class MenuAutopilot : public MenuDriveMode {
Autopilot* autopilot;
RouteInfo routeInfo;
uint32_t last_millis = 0;
uint32_t lastMillis = 0;
uint16_t minDelay = 1500;
};
@@ -0,0 +1,157 @@
/**
* @file menuTestMode.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-09-08
*
* @copyright Copyright (c) 2022
*
*/
#include "menuTestMode.h"
MenuTestMode::MenuTestMode(DriveManager* driveManager)
: MenuDriveMode(driveManager) {
// this->testMode = testMode;
this->values[0] = 1;
this->values[1] = 2;
this->values[2] = 3;
strcpy(this->names[0], "Alpha");
strcpy(this->names[1], "Beta");
strcpy(this->names[2], "Gamma");
}
MenuTestMode::~MenuTestMode() {
if (isInit) {
delete this->mainMenu;
}
}
void MenuTestMode::printMenu() {
if (!this->isInit) {
this->isInit = true;
this->init();
}
this->mainMenu->printMenu();
}
void MenuTestMode::down() {
this->mainMenu->down();
}
void MenuTestMode::up() {
this->mainMenu->up();
}
void MenuTestMode::right() {
this->mainMenu->right();
}
void MenuTestMode::left() {
if (this->mainMenu->isInSubmenu())
this->mainMenu->left();
else
this->parentMenu->printMenu();
}
void MenuTestMode::yes() {
this->mainMenu->yes();
}
void MenuTestMode::no() {
if (this->mainMenu->isInSubmenu())
this->mainMenu->no();
else
this->left();
}
void MenuTestMode::init() {
this->testMode = (TestMode*) this->driveManager->getDriveModiPtr();
auto dummy = []() {
std::cout << "Dummy in Action" <<std::endl;
};
// Create menu
this->mainMenu = new Menu;
Menu* engineMenu = new Menu;
Menu* engineLeftMenu = new Menu;
Menu* engineRightMenu = new Menu;
Menu* drivingMenu = new Menu;
Menu* drivingForwardMenu = new Menu;
Menu* drivingBackwardMenu = new Menu;
Menu* lightMenu = new Menu;
MenuIntInput* testInputMenu = new MenuIntInput(values, (char *)names, length, new MenuTestModeWrapper(this->testMode));
// Set menus on LCD
this->mainMenu->setLcd(this->lcd);
engineMenu->setLcd(this->lcd);
engineLeftMenu->setLcd(this->lcd);
engineRightMenu->setLcd(this->lcd);
drivingMenu->setLcd(this->lcd);
drivingForwardMenu->setLcd(this->lcd);
drivingBackwardMenu->setLcd(this->lcd);
lightMenu->setLcd(this->lcd);
testInputMenu->setLcd(this->lcd);
// Entrys for the menus
MenuAction* engineAction = new MenuAction("Engine", engineMenu);
MenuAction* engineLeftAction = new MenuAction("Left", engineLeftMenu);
MenuAction* engineRightAction = new MenuAction("Right", engineRightMenu);
MenuAction* drivingAction = new MenuAction("Driving", drivingMenu);
MenuAction* drivingForwardAction = new MenuAction("Forward", drivingForwardMenu);
MenuAction* drivingForwardLeftAction = new MenuAction("Left", testInputMenu);
MenuAction* drivingForwardStraightAction = new MenuAction("Straight", dummy);
MenuAction* drivingForwardRightAction = new MenuAction("Right", dummy);
MenuAction* drivingBackwardAction = new MenuAction("Backward", drivingBackwardMenu);
MenuAction* drivingBackwardLeftAction = new MenuAction("Left", dummy);
MenuAction* drivingBackwardStraightAction = new MenuAction("Straight", dummy);
MenuAction* drivingBackwardRightAction = new MenuAction("Right", dummy);
MenuAction* lightAction = new MenuAction("Light", lightMenu);
MenuAction* lightFlashAction = new MenuAction("Flash", dummy);
MenuAction* lightFadeAction = new MenuAction("Fade", dummy);
MenuAction* lightRedAction = new MenuAction("Red", dummy);
MenuAction* lightGreenAction = new MenuAction("Green", dummy);
MenuAction* lightBlueAction = new MenuAction("Blue", dummy);
MenuAction* lightOffAction = new MenuAction("Off", dummy);
// Add entrys to the menus
this->mainMenu->addEntry(engineAction);
this->mainMenu->addEntry(drivingAction);
this->mainMenu->addEntry(lightAction);
engineMenu->addEntry(engineLeftAction);
engineMenu->addEntry(engineRightAction);
drivingMenu->addEntry(drivingForwardAction);
drivingMenu->addEntry(drivingBackwardAction);
drivingForwardMenu->addEntry(drivingForwardLeftAction);
drivingForwardMenu->addEntry(drivingForwardStraightAction);
drivingForwardMenu->addEntry(drivingForwardRightAction);
drivingBackwardMenu->addEntry(drivingBackwardLeftAction);
drivingBackwardMenu->addEntry(drivingBackwardStraightAction);
drivingBackwardMenu->addEntry(drivingBackwardRightAction);
lightMenu->addEntry(lightFlashAction);
lightMenu->addEntry(lightFadeAction);
lightMenu->addEntry(lightRedAction);
lightMenu->addEntry(lightGreenAction);
lightMenu->addEntry(lightBlueAction);
lightMenu->addEntry(lightOffAction);
}
MenuTestModeWrapper::MenuTestModeWrapper(TestMode* testMode) {
this->testMode = testMode;
}
void MenuTestModeWrapper::action(int16_t* values, uint8_t length) {
if (length > 2)
std::cout << "Dummy in Action" << values[0] << values[1] << values[2] << std::endl;
else
std::cout << "Dummy in Action kene dre values" << std::endl;
}
@@ -0,0 +1,56 @@
/**
* @file menuTestMode.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-09-08
*
* @copyright Copyright (c) 2022
*
*/
#ifndef MENU_TEST_MODE
#define MENU_TEST_MODE
#include "SpecialMenus/driveModi/menuDriveMode.h"
#include "driveModi/Modi/TestMode/testMode.h"
#include "menu.h"
#include "menuAction.h"
#include "menuIntInput.h"
class MenuTestMode : public MenuDriveMode {
public:
MenuTestMode(DriveManager *driveManager);
~MenuTestMode();
void printMenu();
void down() override;
void up() override;
void right() override;
void left() override;
void yes() override;
void no() override;
private:
void init();
TestMode* testMode;
Menu* mainMenu;
bool isInit = false;
uint8_t length = 3;
int16_t values[3];
char names[3][MAX_NAME_LENGTH];
};
class MenuTestModeWrapper : public MenuIntInputWrapper {
public:
MenuTestModeWrapper(TestMode* testMode);
void action(int16_t* values, uint8_t length) override;
private:
TestMode* testMode;
};
#endif // MENU_TEST_MODE
+5 -5
View File
@@ -25,11 +25,11 @@ void Autopilot::loop() {
if (!this->selfDriving && this->navigationStarted)
ManualControl::loop();
if (millis() - this->last_millis < delay)
if (millis() - this->lastMillis < delay)
return;
this->runAutopilot();
this->last_millis = millis();
this->lastMillis = millis();
}
void Autopilot::runAutopilot() {
@@ -76,7 +76,7 @@ void Autopilot::setSelfDriving(bool val) {
this->selfDriving = val;
this->moveControl->setSpeed(0);
this->moveControl->setRotationspeed(0);
this->moveControl->setRotationSpeed(0);
}
void Autopilot::setSpeedInRelToDistance(double distance) {
@@ -97,7 +97,7 @@ void Autopilot::setRotInRelToDistance(int16_t course) {
steps = 1;
if (course == 0)
this->moveControl->setRotationspeed(0);
this->moveControl->setRotationSpeed(0);
else
this->moveControl->setRotationspeed(steps);
this->moveControl->setRotationSpeed(steps);
}
+1 -1
View File
@@ -127,7 +127,7 @@ class Autopilot : public ManualControl {
bool selfDrivingAvailable = false;
bool updateDisplay = false;
uint16_t last_millis = 0;
uint16_t lastMillis = 0;
uint8_t delay = 40;
};
@@ -47,7 +47,7 @@
/**
* @brief Course correction factor
* This value is used by the setRotInRelToDistance function and is used to calculate
* the value for setRotationspeed.
* the value for setRotationSpeed.
*/
#define COURSE_CORRECTION_FACTOR 30
@@ -20,11 +20,11 @@ CaptureRoute::CaptureRoute(MoveControl* moveControl, Navigation* navigation)
void CaptureRoute::loop() {
ManualControl::loop();
if (millis() - this->last_millis < delay) {
if (millis() - this->lastMillis < delay) {
return;
}
this->runCaptureRoute();
this->last_millis = millis();
this->lastMillis = millis();
}
void CaptureRoute::runCaptureRoute() {
@@ -75,7 +75,7 @@ class CaptureRoute : public ManualControl {
Navigation* navigation;
RouteInfo routeInfo;
uint32_t last_millis = 0;
uint32_t lastMillis = 0;
uint16_t delay = 200;
bool updateDisplay = false;
@@ -17,16 +17,16 @@ ManualControl::ManualControl(MoveControl *moveControl) {
ManualControl::~ManualControl() {
this->moveControl->setSpeed(0);
this->moveControl->setRotationspeed(0);
this->moveControl->setRotationSpeed(0);
this->moveControl->setDrivingStatus(DrivingStatus::stop);
}
void ManualControl::loop() {
if (millis() - this->last_millis < delay) {
if (millis() - this->lastMillis < delay) {
return;
}
this->runManualControl();
this->last_millis = millis();
this->lastMillis = millis();
}
void ManualControl::runManualControl() {
@@ -37,5 +37,5 @@ void ManualControl::runManualControl() {
this->moveControl->setSpeed((y * -1) * value_per_step);
value_per_step = this->max_rotation * 2 / 256;
this->moveControl->setRotationspeed(-x * value_per_step);
}
this->moveControl->setRotationSpeed(-x * value_per_step);
}
@@ -22,7 +22,7 @@
*
* @see MoveControl
*/
class ManualControl : public DriveModi{
class ManualControl : public DriveModi {
public:
ManualControl(MoveControl *moveControl);
@@ -40,7 +40,7 @@ class ManualControl : public DriveModi{
* @see runSpeedometer()
* @see setDelay()
*/
void loop();
void loop() override;
/**
* @brief Noramly called repeatedly by loop() to calcluate new values.
@@ -73,7 +73,7 @@ class ManualControl : public DriveModi{
MoveControl *moveControl;
private:
uint32_t last_millis = 0;
uint32_t lastMillis = 0;
uint8_t delay = 10;
double max_speed = 1;
double max_rotation = 7;
View File
+124
View File
@@ -0,0 +1,124 @@
/**
* @file testMode.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-09-08
*
* @copyright Copyright (c) 2022
*
*/
#include "testMode.h"
TestMode::TestMode(MoveControl *moveControl) {
this->moveControl = moveControl;
this->moveControl->setDrivingStatus(DrivingStatus::drive);
}
TestMode::~TestMode() {
this->moveControl->setSpeed(0);
this->moveControl->setRotationSpeed(0);
this->moveControl->setDrivingStatus(DrivingStatus::stop);
}
void TestMode::loop() {
if (millis() - this->lastMillis < this->delay)
return;
if (millis() - this->actionStart > this->maneuverTime) {
this->busy = false;
this->moveControl->setSpeed(0);
this->moveControl->setRotationSpeed(0);
}
}
void TestMode::setSpeed(double speed) {
this->speed = speed;
}
void TestMode::setRotationSpeed(double speed) {
this->rotationSpeed = speed;
}
bool TestMode::driveForward(uint16_t cm) {
if (this->busy)
return false;
this->moveControl->setRotationSpeed(0);
this->moveControl->setSpeed(this->speed);
this->maneuverTime = (uint32_t) (((double) cm / 100.0) / this->speed) * 1000;
this->actionStart = millis();
this->busy = true;
return true;
}
bool TestMode::driveBackward(uint16_t cm) {
if (this->busy)
return false;
this->moveControl->setRotationSpeed(0);
this->moveControl->setSpeed(-this->speed);
this->maneuverTime = (uint32_t) (((double) cm / 100.0) / this->speed) * 1000;
this->actionStart = millis();
this->busy = true;
return true;
}
bool TestMode::turnLeft(uint16_t degree) {
if (this->busy)
return false;
this->moveControl->setSpeed(0);
this->moveControl->setRotationSpeed(this->rotationSpeed);
//TODO: calc this shit
this->maneuverTime = 10;
this->actionStart = millis();
this->busy = true;
return true;
}
bool TestMode::turnRight(uint16_t degree) {
if (this->busy)
return false;
this->moveControl->setSpeed(0);
this->moveControl->setRotationSpeed(this->rotationSpeed);
//TODO: calc this shit
this->maneuverTime = 10;
this->actionStart = millis();
this->busy = true;
return true;
}
bool TestMode::driveForwardLeft(uint16_t cm, uint16_t degree) {
if (this->busy)
return false;
return false;
}
bool TestMode::driveForwardRight(uint16_t cm, uint16_t degree) {
if (this->busy)
return false;
return false;
}
bool TestMode::driveBackwardLeft(uint16_t cm, uint16_t degree) {
if (this->busy)
return false;
return false;
}
bool TestMode::driveBackwardRight(uint16_t cm, uint16_t degree) {
if (this->busy)
return false;
return false;
}
+54
View File
@@ -0,0 +1,54 @@
/**
* @file testMode.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-09-08
*
* @copyright Copyright (c) 2022
*
*/
#ifndef TEST_MODE_H
#define TEST_MODE_H
#include "moveControl.h"
#include "driveModi/driveModi.h"
class TestMode : public DriveModi {
public:
TestMode(MoveControl *MoveControl);
~TestMode();
void loop() override;
void setSpeed(double speed);
void setRotationSpeed(double speed);
bool driveForward(uint16_t cm);
bool driveBackward(uint16_t cm);
bool turnLeft(uint16_t degree);
bool turnRight(uint16_t degree);
bool driveForwardLeft(uint16_t cm, uint16_t degree);
bool driveForwardRight(uint16_t cm, uint16_t degree);
bool driveBackwardLeft(uint16_t cm, uint16_t degree);
bool driveBackwardRight(uint16_t cm, uint16_t degree);
private:
MoveControl *moveControl;
double speed = 0;
double rotationSpeed = 0;
bool busy = false;
uint8_t delay = 10;
uint32_t maneuverTime = 0;
uint32_t lastMillis = 0;
uint32_t actionStart = 0;
};
#endif // TEST_MODE_H
+8 -5
View File
@@ -1,7 +1,7 @@
/**
* @file driveManager.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief Implemention of the class DriveManager
* @brief Implementation of the class DriveManager
* @version 0.1
* @date 2021-12-14
*
@@ -15,9 +15,11 @@ Modi& operator++(Modi& m, int) {
return m = (m == Modi::TestMode) ? Modi::Off : static_cast<Modi>(static_cast<int>(m)+1);
}
DriveManager::DriveManager(MoveControl *moveControl) {
DriveManager::DriveManager(MoveControl *moveControl, bool wifi) {
this->moveControl = moveControl;
this->navigation = new Navigation();
if (wifi)
this->navigation->initNtrip(NTRIP_HOST, NTRIP_PORT, NTRIP_MOUNT_POINT, NTRIP_USER, NTRIP_PASSWORD);
}
DriveManager::~DriveManager() {
@@ -42,7 +44,7 @@ void DriveManager::changeModus(Modi modus) {
delete this->currentModusPtr;
this->moveControl->setSpeed(0);
this->moveControl->setRotationspeed(0);
this->moveControl->setRotationSpeed(0);
this->moveControl->setDrivingStatus(DrivingStatus::stop);
switch (modus) {
@@ -69,8 +71,9 @@ void DriveManager::changeModus(Modi modus) {
this->currentModusPtr = nullptr;
break;
case Modi::TestMode:
this->currentModusPtr = nullptr;
case Modi::TestMode: {
this->currentModusPtr = new TestMode(this->moveControl);
}
break;
default:
+2 -1
View File
@@ -22,6 +22,7 @@
#include "moveControl.h"
#include "driveModi/driveModi.h"
#include "navigation.h"
#include "networkConfig.h"
// All Drive Modi
#include "driveModi/Modi/ManualControl/manualControl.h"
@@ -52,7 +53,7 @@ class DriveManager {
*
* @param moveControl
*/
DriveManager(MoveControl *moveControl);
DriveManager(MoveControl *moveControl, bool wifi = false);
/**
* @brief Destroy the Drive Manager object
+23 -14
View File
@@ -34,12 +34,13 @@
#include "SpecialMenus/driveModi/ManualDrive/menuManualDrive.h"
#include "SpecialMenus/driveModi/CaptureRoute/menuCaptureRoute.h"
#include "SpecialMenus/driveModi/Autopilot/menuAutopilot.h"
#include "SpecialMenus/driveModi/TestMode/menuTestMode.h"
#include "SpecialMenus/PID/menuPidSettings.h"
#include "SpecialMenus/GPS/menuGPS.h"
#include "SpecialMenus/Akku/menuAkku.h"
MoveControl moveController;
DriveManager driveManager(&moveController);
DriveManager* driveManager;
Menu* main_m;
LiquidCrystal_I2C* lcd;
OutputBuf* outputBuf;
@@ -63,6 +64,7 @@ void setup() {
mainBattery = new Battery(35, 692000, 218500);
Wire.begin(21, 19);
Wire.setClock(400000);
i2cScanner();
lcd = new LiquidCrystal_I2C(0x3F,16,2);
lcd->init();
@@ -73,14 +75,19 @@ void setup() {
Network::setupMQTT();
wifiIsActive = Network::connectWifi();
if (wifiIsActive) {
Network::checkMQTT();
DebugMqtt::init(Network::getMqttClient(), Loglevel::debug);
std::cout << "Activate additional output via MQTT..." << std::endl;
debugMqtt = new DebugMqtt("Console");
outputBuf = new OutputBuf(debugMqtt);
driveManager = new DriveManager(&moveController, true);
if (Network::checkMQTT()) {
DebugMqtt::init(Network::getMqttClient(), Loglevel::debug);
std::cout << "Activate additional output via MQTT..." << std::endl;
debugMqtt = new DebugMqtt("Console");
outputBuf = new OutputBuf(debugMqtt);
} else
outputBuf = new OutputBuf();
wifiIndicator = '-';
} else
} else {
driveManager = new DriveManager(&moveController);
outputBuf = new OutputBuf();
}
std::cout.rdbuf(outputBuf);
std::cout << "Welcome to Kleiax-Rover" << std::endl;
@@ -114,7 +121,7 @@ void loop() {
Network::checkMQTT();
}
driveManager.loop();
driveManager->loop();
mainBattery->loop();
// static uint32_t lastMillis = 0;
@@ -228,10 +235,11 @@ void makeMenu() {
Menu* pid_m = new Menu();
MenuPidSettings* pidl_m = new MenuPidSettings(moveController.getPID(0));
MenuPidSettings* pidr_m = new MenuPidSettings(moveController.getPID(1));
MenuManualControl* man_m = new MenuManualControl(&driveManager);
MenuCaptureRoute* cap_m = new MenuCaptureRoute(&driveManager);
MenuAutopilot* auto_m = new MenuAutopilot(&driveManager);
MenuGPS* gps_m = new MenuGPS(driveManager.getNavigation()->getGPS());
MenuManualControl* man_m = new MenuManualControl(driveManager);
MenuCaptureRoute* cap_m = new MenuCaptureRoute(driveManager);
MenuAutopilot* auto_m = new MenuAutopilot(driveManager);
MenuTestMode* test_m = new MenuTestMode(driveManager);
MenuGPS* gps_m = new MenuGPS(driveManager->getNavigation()->getGPS());
MenuAkku* akku_m = new MenuAkku(mainBattery);
// Set Menus on LCD
@@ -243,6 +251,7 @@ void makeMenu() {
man_m->setLcd(lcd);
cap_m->setLcd(lcd);
auto_m->setLcd(lcd);
test_m->setLcd(lcd);
gps_m->setLcd(lcd);
akku_m->setLcd(lcd);
@@ -252,7 +261,7 @@ void makeMenu() {
MenuAction* gps_e = new MenuAction("GPS", gps_m);
MenuAction* pid_e = new MenuAction("PID", pid_m);
MenuAction* restart_e = new MenuAction("Restart", restart);
MenuAction* akku_e = new MenuAction("Akku", akku_m);
MenuAction* akku_e = new MenuAction("Battery", akku_m);
MenuAction* contr_e = new MenuAction("Remove PS3", disconnectController);
main_m->addEntry(mode_e);
main_m->addEntry(gps_e);
@@ -266,7 +275,7 @@ void makeMenu() {
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", dummy);
MenuAction* testMode_e = new MenuAction("Test Mode", test_m);
mode_m->addEntry(autopilot_e);
mode_m->addEntry(captureRoute_e);
mode_m->addEntry(manualControl_e);
+4 -4
View File
@@ -62,12 +62,12 @@ void MoveControl::loop() {
std::cout << buf;
}
static uint64_t last_millis = 0;
if (millis() - last_millis < delay)
static uint64_t lastMillis = 0;
if (millis() - lastMillis < delay)
return;
this->runMoveControl();
last_millis = millis();
lastMillis = millis();
}
void MoveControl::runMoveControl() {
@@ -104,7 +104,7 @@ void MoveControl::setSpeed(double speed) {
this->x_speed = speed;
}
void MoveControl::setRotationspeed(double speed) {
void MoveControl::setRotationSpeed(double speed) {
if (speed < 0.7 && speed > -0.7)
this->rotation_speed = 0;
else
+12 -6
View File
@@ -15,6 +15,7 @@ IPAddress Network::local_IP;
IPAddress Network::gateway;
IPAddress Network::subnet;
IPAddress Network::mqtt_server;
IPAddress Network::dnsServer;
WiFiClient Network::wifi_client;
PubSubClient* Network::mqtt_client;
@@ -24,17 +25,20 @@ void Network::setIps() {
gateway.fromString(WLAN_GATEWAY);
subnet.fromString(WLAN_SUBNETMASK);
mqtt_server.fromString(MQTT_SERVER);
dnsServer.fromString(WLAN_DNS_SERVER);
}
void Network::setupMQTT() {
Network::mqtt_client = new PubSubClient(wifi_client);
// mqtt_client->setServer(mqtt_server, MQTT_PORT);
Network::mqtt_client->setServer(MQTT_SERVER, MQTT_PORT);
Network::mqtt_client->setSocketTimeout(1);
// Network::connectMQTT();
}
bool Network::connectMQTT() {
#ifndef MQTT
return false;
#endif
// Create a random client ID
String clientId = "ESP32Rover-";
clientId += String(random(0xffff), HEX);
@@ -54,7 +58,7 @@ bool Network::connectMQTT() {
}
bool Network::connectWifi() {
// Configures static IP address
if (!WiFi.config(local_IP, gateway, subnet))
if (!WiFi.config(local_IP, gateway, subnet, dnsServer))
std::cout << "STA Failed to configure" << std::endl;
// Connect to Wi-Fi network with SSID and password
@@ -80,18 +84,20 @@ bool Network::connectWifi() {
return true;
}
void Network::checkMQTT() {
bool Network::checkMQTT() {
static uint64_t lastReconnectAttempt = 0;
if (!mqtt_client->connected()) {
long now = millis();
if (now - lastReconnectAttempt > MQTT_TIME_RECONNECT) {
lastReconnectAttempt = now;
// Attempt to reconnect
if (connectMQTT())
if (connectMQTT())
lastReconnectAttempt = 0;
}
} else
return false;
}
mqtt_client->loop();
return true;
}
void Network::checkWiFi() {