begin with gps, can drive now

This commit is contained in:
2022-01-29 20:50:30 +01:00
parent 9c4c82f8b3
commit ab4ceb8b09
12 changed files with 222 additions and 43 deletions
+2 -2
View File
@@ -10,8 +10,8 @@ INTL1 32 GND
INTL2 33 19 SCL
INTB1 25 18
INTB2 26 5
DirL1 27 TX GPS
DirR2 14 RX GPS
DirL1 27 17 GPS TX
DirR2 14 16 GPS RX
DirL2 12 4 SD-Card
GND x
PWML 13 2 SD-Card
+2 -2
View File
@@ -1,6 +1,6 @@
//GPS Serial Pins
#define GPS_RX 16
#define GPS_TX 17
#define GPS_RX 17
#define GPS_TX 16
#define GPS_BAUD 9600
+1 -1
View File
@@ -1,4 +1,4 @@
#define HW1
#define RHEDE
//Network config RHEDE
#ifdef RHEDE
+26 -14
View File
@@ -17,22 +17,36 @@ Menu::Menu() {
void Menu::addEntry(MenuAction* entry) {
this->entrys.push_back(entry);
// TODO: Same shit here. Why I get the first element after an increment.
static uint8_t inc = 0;
inc++;
if (inc == 1) {
if (this->entrys.size() == 2)
this->it = this->entrys.begin();
}
}
void Menu::printMenu() {
std::cout << std::endl;
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
MenuAction* selectedEntry = *(iter);
if (this->it == iter)
std::cout << " " << selectedEntry->getName() << std::endl;
else
std::cout << selectedEntry->getName() << std::endl;
if (this->lcd) {
MenuAction* selectedEntry = *(this->it);
lcd->clear();
lcd->setCursor(0, 0);
lcd->print("-> ");
lcd->print(selectedEntry->getName());
lcd->setCursor(0, 1);
std::list<MenuAction*>::iterator iter = this->it;
iter++;
if (iter != this->entrys.end()) {
selectedEntry = *iter;
lcd->print(selectedEntry->getName());
} else {
selectedEntry = *this->entrys.begin();
lcd->print(selectedEntry->getName());
}
} else {
std::cout << std::endl;
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
MenuAction* selectedEntry = *(iter);
if (this->it == iter)
std::cout << " " << selectedEntry->getName() << std::endl;
else
std::cout << selectedEntry->getName() << std::endl;
}
}
this->inSubmenu = false;
}
@@ -85,8 +99,6 @@ void Menu::right() {
selectedEntry->getMenu()->setParentMenu(this);
}
selectedEntry->runAction();
if (selectedEntry->getIsMenu())
selectedEntry->getMenu()->down();
}
void Menu::left() {
+3 -1
View File
@@ -13,6 +13,7 @@
#define MENU_CONTROLL_H
#include <iostream>
#include <LiquidCrystal_I2C.h>
class MenuControl {
public:
@@ -27,9 +28,10 @@ class MenuControl {
virtual void printMenu();
void setParentMenu(MenuControl* menu) {this->parentMenu = menu;}
void setLcd(LiquidCrystal_I2C* lcd) {this->lcd = lcd;}
protected:
MenuControl* parentMenu = nullptr;
LiquidCrystal_I2C* lcd = nullptr;
};
#endif // MENU_CONTROLL_H
+1
View File
@@ -21,4 +21,5 @@ lib_deps =
mikalhart/TinyGPSPlus@^1.0.2
knolleary/PubSubClient@^2.8
br3ttb/PID@^1.2.1
marcoschwartz/LiquidCrystal_I2C@^1.1.4
upload_port = COM3
+55
View File
@@ -0,0 +1,55 @@
/**
* @file menuGPS.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-01-29
*
* @copyright Copyright (c) 2022
*
*/
#include "menuGPS.h"
MenuGPS::MenuGPS(TinyGPSPlus* gps) {
this->gps = gps;
}
void MenuGPS::right() {
this->printMenu();
}
void MenuGPS::left() {
if (this->parentMenu)
this->parentMenu->printMenu();
}
void MenuGPS::no() {
this->left();
}
void MenuGPS::yes() {
this->printMenu();
}
void MenuGPS::printMenu() {
if (this->lcd) {
lcd->clear();
lcd->setCursor(0, 0);
if (gps->satellites.isValid()) {
lcd->printf("Sats: %3.d", gps->satellites.value());
lcd->setCursor(0, 1);
lcd->printf("HDOP: %f", gps->hdop.hdop());
} else {
lcd->clear();
lcd->setCursor(0, 0);
lcd->printf("Data isn't valid");
}
} else {
if (gps->satellites.isValid())
std::cout << "Sats: " << gps->satellites.value()
<< "HDOP: " << gps->hdop.hdop() << std::endl;
else
std::cout << "Date isn't valid" << std::endl;
}
}
+36
View File
@@ -0,0 +1,36 @@
/**
* @file menuGPS.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-01-29
*
* @copyright Copyright (c) 2022
*
*/
#ifndef MENU_GPS_H
#define MENU_GPS_H
#include <TinyGPS++.h>
#include "menuControl.h"
class MenuGPS : public MenuControl {
public:
MenuGPS(TinyGPSPlus* gps);
void down(){}
void up(){}
void right();
void left();
void no();
void yes();
void printMenu();
private:
TinyGPSPlus* gps;
};
#endif // MENU_GPS_H
+9 -1
View File
@@ -16,5 +16,13 @@ void MenuManualControl::no() {
void MenuManualControl::printMenu() {
this->driveManager->changeModus(Modi::ManualControl);
std::cout << "Jetzt kannst du\n fahren. :-)" << std::endl;
if (this->lcd) {
this->lcd->clear();
this->lcd->setCursor(0, 0);
this->lcd->print("Jetzt kannst");
this->lcd->setCursor(0, 1);
this->lcd->print("du fahren. :-)");
} else
std::cout << "Jetzt kannst du\n fahren. :-)" << std::endl;
}
-4
View File
@@ -18,8 +18,6 @@
// TODO: delete after installtion of display
#include <Arduino.h>
class MenuManualControl : public MenuControl {
public:
MenuManualControl(DriveManager* driveManager);
@@ -35,8 +33,6 @@ class MenuManualControl : public MenuControl {
private:
DriveManager* driveManager;
};
#endif // MENU_MANUAL_DRIVE_H
+14 -4
View File
@@ -62,23 +62,33 @@ void MenuPidSettings::yes() {
}
void MenuPidSettings::printMenu() {
std::cout << " P I D " << std::endl;
char buf[17];
switch (this->curPos) {
case 0:
printf("_%3.d_ %3.d %3.d \n", this->values[0], this->values[1], this->values[2]);
sprintf(buf, "_%3.d_ %3.d %3.d ", this->values[0], this->values[1], this->values[2]);
break;
case 1:
printf(" %3.d _%3.d_ %3.d \n", this->values[0], this->values[1], this->values[2]);
sprintf(buf, " %3.d _%3.d_ %3.d ", this->values[0], this->values[1], this->values[2]);
break;
case 2:
printf(" %3.d %3.d _%3.d_\n", this->values[0], this->values[1], this->values[2]);
sprintf(buf, " %3.d %3.d _%3.d_", this->values[0], this->values[1], this->values[2]);
break;
default:
break;
}
if (this->lcd) {
lcd->clear();
lcd->setCursor(0, 0);
lcd->print(" P I D ");
lcd->setCursor(0, 1);
lcd->print(buf);
} else {
std::cout << " P I D " << std::endl;
std::cout << buf << std::endl;
}
}
+71 -12
View File
@@ -1,6 +1,9 @@
#include <Arduino.h>
#include <Ps3Controller.h>
#include <iostream>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TinyGPS++.h>
#include "config.h"
@@ -14,10 +17,13 @@
#include "menuAction.h"
#include "SpecialMenus/menuPidSettings.h"
#include "SpecialMenus/menuManualDrive.h"
#include "SpecialMenus/menuGPS.h"
MoveControl moveController;
DriveManager driveManager(&moveController);
Menu* main_m;
LiquidCrystal_I2C* lcd;
TinyGPSPlus gps;
// TODO: Platzhalter, muss irgendwann weg
void dummy(){std::cout << "Dummy in Action" <<std::endl;}
@@ -26,13 +32,24 @@ void dummy(){std::cout << "Dummy in Action" <<std::endl;}
void callbackControllerAction();
void callbackControllerConnect();
void controllerPrintBattery();
void i2cScanner();
void exitDriveMode() {driveManager.changeModus(Modi::Off);}
void setup() {
Serial.begin(115200);
Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
std::cout << "Welcome to Kleiax-Rover" << std::endl;
Wire.begin(21, 19);
// i2cScanner();
lcd = new LiquidCrystal_I2C(0x3F,16,2);
lcd->init();
lcd->backlight();
lcd->print("- Kleiax-Rover -");
lcd->setCursor(0, 1);
lcd->print("Press PS-Button");
Network::setIps();
Network::connectWifi();
Network::setupMQTT();
@@ -42,8 +59,6 @@ void setup() {
std::cout << "\nReady to connect a PS3 Controller... \n";
Ps3.begin();
Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
// Create Menu
main_m = new Menu();
Menu* mode_m = new Menu();
@@ -51,10 +66,21 @@ void setup() {
MenuPidSettings* pidl_m = new MenuPidSettings(moveController.getPID(0));
MenuPidSettings* pidr_m = new MenuPidSettings(moveController.getPID(1));
MenuManualControl* man_m = new MenuManualControl(&driveManager);
MenuGPS* gps_m = new MenuGPS(&gps);
// Set Menus on LCD
main_m->setLcd(lcd);
mode_m->setLcd(lcd);
pid_m->setLcd(lcd);
pidl_m->setLcd(lcd);
pidr_m->setLcd(lcd);
man_m->setLcd(lcd);
gps_m->setLcd(lcd);
// Entry for the main menu
MenuAction* mode_e = new MenuAction("Mode", mode_m);
MenuAction* gps_e = new MenuAction("GPS", dummy);
MenuAction* gps_e = new MenuAction("GPS", gps_m);
MenuAction* pid_e = new MenuAction("PID", pid_m);
main_m->addEntry(mode_e);
main_m->addEntry(gps_e);
@@ -83,21 +109,18 @@ void setup() {
void loop() {
Network::checkMQTT();
driveManager.loop();
while (Serial1.available() > 0)
std::cout << "In while von gps in loop in main.cpp" << std::endl;
// Serial.print(Serial1.read());
gps.encode(Serial1.read());
}
bool isDelayReached() {
bool isDelayReached(bool reset = false) {
static uint32_t lastMillis = 0;
const uint16_t delay = 200;
if (reset)
lastMillis = millis();
static const uint16_t delay = 300;
bool res = false;
if (millis() - lastMillis > delay) {
if (millis() - lastMillis > delay)
res = true;
lastMillis = millis();
}
return res;
}
@@ -118,11 +141,16 @@ void callbackControllerAction() {
main_m->no();
else if (Ps3.data.button.ps)
controllerPrintBattery();
isDelayReached(true);
}
}
void callbackControllerConnect() {
std::cout << "Controller connected to ESP32" << std::endl;
// TODO: Display is not functional without this seconde init, first init is in setup()
lcd->init();
main_m->printMenu();
}
@@ -141,3 +169,34 @@ void controllerPrintBattery() {
else if( controller_battery == ps3_status_battery_shutdown ) printf("SHUTDOWN\n");
else printf("UNDEFINED\n");
}
void i2cScanner() {
std::cout << "\nI2C Scanner" << std::endl;
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
nDevices++;
}
else if (error==4) {
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
}