new ntrip client

This commit is contained in:
2022-09-21 12:50:01 +02:00
parent af6cb98898
commit a1a976be57
15 changed files with 658 additions and 251 deletions
@@ -13,13 +13,11 @@
MenuTestMode::MenuTestMode(DriveManager* driveManager)
: MenuDriveMode(driveManager) {
// this->testMode = testMode;
this->values[0] = 1;
this->values[1] = 2;
this->values[2] = 3;
// this->values[0] = 0;
// this->values[1] = 0;
strcpy(this->names[0], "Alpha");
strcpy(this->names[1], "Beta");
strcpy(this->names[2], "Gamma");
// strcpy(this->names[0], "Centimeter");
// strcpy(this->names[1], "Degree");
}
MenuTestMode::~MenuTestMode() {
@@ -68,6 +66,7 @@ void MenuTestMode::no() {
}
void MenuTestMode::init() {
this->driveManager->changeModus(Modi::TestMode);
this->testMode = (TestMode*) this->driveManager->getDriveModiPtr();
auto dummy = []() {
@@ -77,40 +76,49 @@ void MenuTestMode::init() {
// 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));
MenuIntInput* drivingMenu = new MenuIntInput(2, new MenuTestModeWrapper(this->testMode, &TestMode::drive));
MenuIntInput* engineLeftMenu = new MenuIntInput(2, new MenuTestModeWrapper(this->testMode, &TestMode::leftEngine));
MenuIntInput* engineRightMenu = new MenuIntInput(2, new MenuTestModeWrapper(this->testMode, &TestMode::rightEngine));
MenuIntInput* engineBothMenu = new MenuIntInput(2, new MenuTestModeWrapper(this->testMode, &TestMode::bothEngine));
// Set menus on LCD
this->mainMenu->setLcd(this->lcd);
engineMenu->setLcd(this->lcd);
engineLeftMenu->setLcd(this->lcd);
engineRightMenu->setLcd(this->lcd);
engineBothMenu->setLcd(this->lcd);
drivingMenu->setLcd(this->lcd);
drivingForwardMenu->setLcd(this->lcd);
drivingBackwardMenu->setLcd(this->lcd);
lightMenu->setLcd(this->lcd);
testInputMenu->setLcd(this->lcd);
// Other menu config
drivingMenu->setEntry(0, "Centimeter", 100);
drivingMenu->setMinMaxSteps(0, -1000, 1000, 25);
drivingMenu->setEntry(1, "Degree");
drivingMenu->setMinMaxSteps(1, -360, 360, 15);
engineLeftMenu->setEntry(0, "Percentage");
engineLeftMenu->setMinMaxSteps(0, -100, 100, 5);
engineLeftMenu->setEntry(1, "Seconds", 10);
engineLeftMenu->setMinMaxSteps(1, 0, 120, 1);
engineRightMenu->setEntry(0, "Percentage");
engineRightMenu->setMinMaxSteps(0, -100, 100, 5);
engineRightMenu->setEntry(1, "Seconds", 10);
engineRightMenu->setMinMaxSteps(1, 0, 120, 1);
engineBothMenu->setEntry(0, "Percentage");
engineBothMenu->setMinMaxSteps(0, -100, 100, 5);
engineBothMenu->setEntry(1, "Seconds", 10);
engineBothMenu->setMinMaxSteps(1, 0, 120, 1);
// Entrys for the menus
MenuAction* engineAction = new MenuAction("Engine", engineMenu);
MenuAction* engineLeftAction = new MenuAction("Left", engineLeftMenu);
MenuAction* engineRightAction = new MenuAction("Right", engineRightMenu);
MenuAction* engineBothAction = new MenuAction("Both", engineBothMenu);
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);
@@ -127,15 +135,7 @@ void MenuTestMode::init() {
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);
engineMenu->addEntry(engineBothAction);
lightMenu->addEntry(lightFlashAction);
lightMenu->addEntry(lightFadeAction);
@@ -145,13 +145,22 @@ void MenuTestMode::init() {
lightMenu->addEntry(lightOffAction);
}
MenuTestModeWrapper::MenuTestModeWrapper(TestMode* testMode) {
MenuTestModeWrapper::MenuTestModeWrapper(TestMode* testMode, TestModeFunctionSingle testModeFunction) {
this->testMode = testMode;
this->testModeFunctionSingle = testModeFunction;
}
MenuTestModeWrapper::MenuTestModeWrapper(TestMode* testMode, TestModeFunctionDouble testModeFunction) {
this->testMode = testMode;
this->testModeFunctionDouble = testModeFunction;
}
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;
// This function calls a member function with a pointer
// Very helpful site:
// https://isocpp.org/wiki/faq/pointers-to-members#fnptr-vs-memfnptr-types
if (length == 2 && this->testModeFunctionDouble)
(this->testMode->*this->testModeFunctionDouble)(values[0], values[1]);
else if (length == 1 && this->testModeFunctionSingle)
(this->testMode->*this->testModeFunctionSingle)(values[0]);
}
@@ -37,20 +37,21 @@ class MenuTestMode : public MenuDriveMode {
Menu* mainMenu;
bool isInit = false;
uint8_t length = 3;
int16_t values[3];
char names[3][MAX_NAME_LENGTH];
};
typedef bool (TestMode::*TestModeFunctionSingle)(int16_t);
typedef bool (TestMode::*TestModeFunctionDouble)(int16_t, int16_t);
class MenuTestModeWrapper : public MenuIntInputWrapper {
public:
MenuTestModeWrapper(TestMode* testMode);
MenuTestModeWrapper(TestMode* testMode, TestModeFunctionSingle testModeFunction);
MenuTestModeWrapper(TestMode* testMode, TestModeFunctionDouble testModeFunction);
void action(int16_t* values, uint8_t length) override;
private:
TestMode* testMode;
TestModeFunctionSingle testModeFunctionSingle = nullptr;
TestModeFunctionDouble testModeFunctionDouble = nullptr;
};
#endif // MENU_TEST_MODE
+85 -69
View File
@@ -12,12 +12,9 @@
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);
}
@@ -27,98 +24,117 @@ void TestMode::loop() {
if (millis() - this->actionStart > this->maneuverTime) {
this->busy = false;
this->moveControl->setSpeed(0);
this->moveControl->setRotationSpeed(0);
this->moveControl->setDrivingStatus(DrivingStatus::stop);
}
}
void TestMode::setSpeed(double speed) {
this->speed = speed;
void TestMode::setSpeed(int16_t speed) {
this->speed = (double) speed / 100.0;
}
void TestMode::setRotationSpeed(double speed) {
this->rotationSpeed = speed;
void TestMode::setRotationSpeed(int16_t speed) {
this->rotationSpeed = (double) speed / 100.0;
}
bool TestMode::driveForward(uint16_t cm) {
bool TestMode::drive(int16_t cm, int16_t degree) {
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;
if (true) {
std::cout << "It works... cm: " << cm << " degree: " << degree << std::endl;
return false;
}
this->actionStart = millis();
this->moveControl->setDrivingStatus(DrivingStatus::drive);
if (cm == 0) {
//Only left or right
this->moveControl->setSpeed(0);
this->busy = true;
return true;
}
if (degree < 0)
this->moveControl->setRotationSpeed(-this->rotationSpeed);
else if (degree > 0)
this->moveControl->setRotationSpeed(this->rotationSpeed);
//TODO: calc this shit
this->maneuverTime = 10;
this->busy = true;
return true;
bool TestMode::driveBackward(uint16_t cm) {
if (this->busy)
return false;
} else if (degree == 0) {
//Only forward or backward
this->moveControl->setRotationSpeed(0);
this->moveControl->setRotationSpeed(0);
this->moveControl->setSpeed(-this->speed);
if (cm < 0)
this->moveControl->setSpeed(-this->speed);
else if (cm > 0)
this->moveControl->setSpeed(this->speed);
this->maneuverTime = (uint32_t) (((double) cm / 100.0) / this->speed) * 1000;
this->busy = true;
return true;
} else {
//forward or backward and left or right
}
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;
this->moveControl->setDrivingStatus(DrivingStatus::stop);
return false;
}
bool TestMode::driveForwardRight(uint16_t cm, uint16_t degree) {
bool TestMode::leftEngine(int16_t powerPercentage, int16_t seconds) {
if (this->busy)
return false;
return false;
if (powerPercentage >= 100 || powerPercentage <= -100)
return false;
if (true) {
std::cout << "It works... %: " << powerPercentage << " s: " << seconds << std::endl;
return false;
}
this->actionStart = millis();
this->moveControl->setDrivingStatus(DrivingStatus::raw);
this->moveControl->setRawPowerLeft(powerPercentage);
this->maneuverTime = seconds * 1000;
this->busy = true;
}
bool TestMode::driveBackwardLeft(uint16_t cm, uint16_t degree) {
bool TestMode::rightEngine(int16_t powerPercentage, int16_t seconds) {
if (this->busy)
return false;
return false;
if (powerPercentage >= 100 || powerPercentage <= -100)
return false;
if (true) {
std::cout << "It works... %: " << powerPercentage << " s: " << seconds << std::endl;
return false;
}
this->actionStart = millis();
this->moveControl->setDrivingStatus(DrivingStatus::raw);
this->moveControl->setRawPowerRight(powerPercentage);
this->maneuverTime = seconds * 1000;
this->busy = true;
}
bool TestMode::driveBackwardRight(uint16_t cm, uint16_t degree) {
bool TestMode::bothEngine(int16_t powerPercentage, int16_t seconds) {
if (this->busy)
return false;
return false;
}
if (powerPercentage >= 100 || powerPercentage <= -100)
return false;
if (true) {
std::cout << "It works... %: " << powerPercentage << " s: " << seconds << std::endl;
return false;
}
this->actionStart = millis();
this->moveControl->setDrivingStatus(DrivingStatus::raw);
this->moveControl->setRawPowerLeft(powerPercentage);
this->moveControl->setRawPowerRight(powerPercentage);
this->maneuverTime = seconds * 1000;
this->busy = true;
}
+6 -11
View File
@@ -21,19 +21,14 @@ class TestMode : public DriveModi {
void loop() override;
void setSpeed(double speed);
void setRotationSpeed(double speed);
void setSpeed(int16_t speed);
void setRotationSpeed(int16_t speed);
bool driveForward(uint16_t cm);
bool driveBackward(uint16_t cm);
bool drive(int16_t cm = 0, int16_t degree = 0);
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);
bool leftEngine(int16_t powerPercentage, int16_t seconds);
bool rightEngine(int16_t powerPercentage, int16_t seconds);
bool bothEngine(int16_t powerPercentage, int16_t seconds);
private:
MoveControl *moveControl;
+2
View File
@@ -20,6 +20,8 @@ DriveManager::DriveManager(MoveControl *moveControl, bool wifi) {
this->navigation = new Navigation();
if (wifi)
this->navigation->initNtrip(NTRIP_HOST, NTRIP_PORT, NTRIP_MOUNT_POINT, NTRIP_USER, NTRIP_PASSWORD);
// if (wifi)
// std::cout << "Wifi is true" << std::endl;
}
DriveManager::~DriveManager() {
+10 -2
View File
@@ -19,6 +19,7 @@
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <BluetoothSerial.h>
#include <ESP32Ping.h>
#include "config.h"
@@ -74,8 +75,16 @@ void setup() {
Network::setIps();
Network::setupMQTT();
wifiIsActive = Network::connectWifi();
driveManager = new DriveManager(&moveController, wifiIsActive);
if (wifiIsActive) {
driveManager = new DriveManager(&moveController, true);
const char* remoteHost = "www.google.com";
std::cout << "Pinging host: " << remoteHost << std::endl;
if (Ping.ping(remoteHost))
std::cout << "Ping successful..." << std::endl;
else
std::cout << "Ping failed. :/" << std::endl;
if (Network::checkMQTT()) {
DebugMqtt::init(Network::getMqttClient(), Loglevel::debug);
std::cout << "Activate additional output via MQTT..." << std::endl;
@@ -85,7 +94,6 @@ void setup() {
outputBuf = new OutputBuf();
wifiIndicator = '-';
} else {
driveManager = new DriveManager(&moveController);
outputBuf = new OutputBuf();
}
std::cout.rdbuf(outputBuf);
+19
View File
@@ -81,6 +81,10 @@ void MoveControl::runMoveControl() {
}
void MoveControl::setDrivingStatus(DrivingStatus status) {
this->setSpeed(0);
this->setRotationSpeed(0);
this->setRawPowerLeft(0);
this->setRawPowerRight(0);
this->driving_status = status;
// switch (this->driving_status) {
// case DrivingStatus::stop :
@@ -111,6 +115,16 @@ void MoveControl::setRotationSpeed(double speed) {
this->rotation_speed = speed;
}
void MoveControl::setRawPowerLeft(int16_t power) {
if (power <= 100 && power >= 100)
this->rawPowerLeft = power;
}
void MoveControl::setRawPowerRight(int16_t power) {
if (power <= 100 && power >= 100)
this->rawPowerRight = power;
}
void MoveControl::setPidTunings(uint8_t side, double p, double i, double d) {
PID* selectedPID = nullptr;
if (side == 0)
@@ -165,6 +179,11 @@ void MoveControl::regulateMotors() {
this->right_motor->setTargetPower( (int8_t) this->right_pid_out);
break;
case DrivingStatus::raw :
this->left_motor->setTargetPower(this->rawPowerLeft);
this->right_motor->setTargetPower(this->rawPowerRight);
break;
default:
Serial.println("Wrong drivingState in MoveControl::regulateMotors");
break;