Start with Capture Route
This commit is contained in:
+1
-9
@@ -1,10 +1,2 @@
|
|||||||
//GPS Serial Pins
|
|
||||||
#define GPS_RX 17
|
|
||||||
#define GPS_TX 16
|
|
||||||
#define GPS_BAUD 9600
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// PS3 Controller
|
// PS3 Controller
|
||||||
// ESP32 MAC BL 24:62:AB:F2:4B:3A
|
#define CONTROLLER_MAC "24:62:AB:F2:4B:3A"
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
// #ifndef ROUTE_H
|
|
||||||
// #define ROUTE_H
|
|
||||||
|
|
||||||
// #include <cstdint>
|
|
||||||
// #include <list>
|
|
||||||
// #include <TinyGPS++.h>
|
|
||||||
// #include <Arduino.h>
|
|
||||||
|
|
||||||
// #include "motorControl.h"
|
|
||||||
// #include "speedometer.h"
|
|
||||||
// #include "debugMqtt.h"
|
|
||||||
// #include "config.h"
|
|
||||||
|
|
||||||
// struct Point{
|
|
||||||
// double lat = 0;
|
|
||||||
// double lon = 0;
|
|
||||||
// bool operator==(const Point& rhs) const {
|
|
||||||
// return this->lat == rhs.lat && this->lon == rhs.lon;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// class Route {
|
|
||||||
// public:
|
|
||||||
// Route();
|
|
||||||
|
|
||||||
// void runRoute();
|
|
||||||
|
|
||||||
// void addPointToRoute(Point point);
|
|
||||||
// void addCurrentLocationToRoute();
|
|
||||||
// void delRoute();
|
|
||||||
// void resetRoute();
|
|
||||||
|
|
||||||
// Point startRoute();
|
|
||||||
// Point getNextPoint();
|
|
||||||
// uint16_t getNumberOfPoints();
|
|
||||||
|
|
||||||
// static double getDis(Point point_1, Point point_2);
|
|
||||||
|
|
||||||
|
|
||||||
// private:
|
|
||||||
// bool nearlySameLocation(Point p1, Point p2);
|
|
||||||
|
|
||||||
// std::list<Point> points;
|
|
||||||
// std::list<Point>::iterator it;
|
|
||||||
// Point currentLocation;
|
|
||||||
|
|
||||||
// uint16_t count_points = 0;
|
|
||||||
|
|
||||||
// bool route_started = false;
|
|
||||||
// bool route_finished = false;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// #endif // ROUTE_H
|
|
||||||
+15
-28
@@ -23,29 +23,24 @@ void Menu::addEntry(MenuAction* entry) {
|
|||||||
|
|
||||||
void Menu::printMenu() {
|
void Menu::printMenu() {
|
||||||
if (this->lcd) {
|
if (this->lcd) {
|
||||||
MenuAction* selectedEntry = *(this->it);
|
|
||||||
lcd->clear();
|
lcd->clear();
|
||||||
lcd->setCursor(0, 0);
|
lcd->setCursor(0, 0);
|
||||||
lcd->print("-> ");
|
lcd->print("-> ");
|
||||||
lcd->print(selectedEntry->getName());
|
lcd->print((**this->it).getName());
|
||||||
lcd->setCursor(0, 1);
|
lcd->setCursor(0, 1);
|
||||||
std::list<MenuAction*>::iterator iter = this->it;
|
std::list<MenuAction*>::iterator iter = this->it;
|
||||||
iter++;
|
iter++;
|
||||||
if (iter != this->entrys.end()) {
|
if (iter != this->entrys.end()) {
|
||||||
selectedEntry = *iter;
|
lcd->print((**iter).getName());
|
||||||
lcd->print(selectedEntry->getName());
|
} else
|
||||||
} else {
|
lcd->print((*this->entrys.begin())->getName());
|
||||||
selectedEntry = *this->entrys.begin();
|
|
||||||
lcd->print(selectedEntry->getName());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
|
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
|
||||||
MenuAction* selectedEntry = *(iter);
|
|
||||||
if (this->it == iter)
|
if (this->it == iter)
|
||||||
std::cout << " " << selectedEntry->getName() << std::endl;
|
std::cout << " " << (**iter).getName() << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << selectedEntry->getName() << std::endl;
|
std::cout << (**iter).getName() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->inSubmenu = false;
|
this->inSubmenu = false;
|
||||||
@@ -53,8 +48,7 @@ void Menu::printMenu() {
|
|||||||
|
|
||||||
void Menu::down() {
|
void Menu::down() {
|
||||||
if (this->inSubmenu) {
|
if (this->inSubmenu) {
|
||||||
MenuAction* selectedEntry = *(this->it);
|
(**this->it).getMenu()->down();
|
||||||
selectedEntry->getMenu()->down();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +64,7 @@ void Menu::down() {
|
|||||||
|
|
||||||
void Menu::up() {
|
void Menu::up() {
|
||||||
if (this->inSubmenu) {
|
if (this->inSubmenu) {
|
||||||
MenuAction* selectedEntry = *(this->it);
|
(**this->it).getMenu()->up();
|
||||||
selectedEntry->getMenu()->up();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::list<MenuAction*>::iterator iter = this->entrys.end();
|
std::list<MenuAction*>::iterator iter = this->entrys.end();
|
||||||
@@ -86,25 +79,21 @@ void Menu::up() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Menu::right() {
|
void Menu::right() {
|
||||||
// TODO: find out why i cannot call runAction() directly from the iterator
|
|
||||||
MenuAction* selectedEntry = *(this->it);
|
|
||||||
|
|
||||||
if (this->inSubmenu) {
|
if (this->inSubmenu) {
|
||||||
selectedEntry->getMenu()->right();
|
(**this->it).getMenu()->right();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedEntry->getIsMenu()) {
|
if ((**this->it).getIsMenu()) {
|
||||||
this->inSubmenu = true;
|
this->inSubmenu = true;
|
||||||
selectedEntry->getMenu()->setParentMenu(this);
|
(**this->it).getMenu()->setParentMenu(this);
|
||||||
}
|
}
|
||||||
selectedEntry->runAction();
|
(**this->it).runAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::left() {
|
void Menu::left() {
|
||||||
if (this->inSubmenu) {
|
if (this->inSubmenu) {
|
||||||
MenuAction* selectedEntry = *(this->it);
|
(**this->it).getMenu()->left();
|
||||||
selectedEntry->getMenu()->left();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +103,7 @@ void Menu::left() {
|
|||||||
|
|
||||||
void Menu::yes() {
|
void Menu::yes() {
|
||||||
if (this->inSubmenu) {
|
if (this->inSubmenu) {
|
||||||
MenuAction* selectedEntry = *(this->it);
|
(**this->it).getMenu()->yes();
|
||||||
selectedEntry->getMenu()->yes();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,8 +112,7 @@ void Menu::yes() {
|
|||||||
|
|
||||||
void Menu::no() {
|
void Menu::no() {
|
||||||
if (this->inSubmenu) {
|
if (this->inSubmenu) {
|
||||||
MenuAction* selectedEntry = *(this->it);
|
(**this->it).getMenu()->no();
|
||||||
selectedEntry->getMenu()->no();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
#include "coordinate.h"
|
|
||||||
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file coordinate.h
|
|
||||||
* @author Alexander Klein (alex@kleiax.de)
|
|
||||||
* @brief
|
|
||||||
* @version 0.1
|
|
||||||
* @date 2022-01-10
|
|
||||||
*
|
|
||||||
* @copyright Copyright (c) 2022
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef COORDINATE_H
|
|
||||||
#define COORDINATE_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
class Coordinate {
|
|
||||||
public:
|
|
||||||
Coordinate(/* args */);
|
|
||||||
~Coordinate();
|
|
||||||
|
|
||||||
double getDistance(Coordinate coordinate);
|
|
||||||
uint16_t getCompassDirection(Coordinate coordinate);
|
|
||||||
|
|
||||||
private:
|
|
||||||
double lon;
|
|
||||||
double lat;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // COORDINATE_H
|
|
||||||
@@ -1,2 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* @file navigation.cpp
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2022-01-31
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "navigation.h"
|
#include "navigation.h"
|
||||||
|
|
||||||
|
Navigation::Navigation(uint8_t rx, uint8_t tx) {
|
||||||
|
this->gps = new TinyGPSPlus();
|
||||||
|
Serial1.begin(9600, SERIAL_8N1, rx, tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Navigation::loop() {
|
||||||
|
gps->encode(Serial1.read());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Navigation::addCurrentPosToRoute() {
|
||||||
|
Point p;
|
||||||
|
if (this->gps->location.isUpdated() && this->gps->location.isValid()) {
|
||||||
|
p.lat = this->gps->location.lat();
|
||||||
|
p.lon = this->gps->location.lng();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,22 +12,22 @@
|
|||||||
#ifndef NAVIGATION_H
|
#ifndef NAVIGATION_H
|
||||||
#define NAVIGATION_H
|
#define NAVIGATION_H
|
||||||
|
|
||||||
|
#include <TinyGPS++.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "coordinate.h"
|
#include "route.h"
|
||||||
|
|
||||||
class Navigation {
|
class Navigation {
|
||||||
public:
|
public:
|
||||||
Navigation(uint32_t baud, uint8_t rx, uint8_t tx);
|
Navigation(uint8_t rx, uint8_t tx);
|
||||||
|
void loop();
|
||||||
|
|
||||||
void addCoordinateToRoute(Coordinate coordinate);
|
void addCurrentPosToRoute();
|
||||||
void addCurrentCoordinateToRoute();
|
|
||||||
void delRoute();
|
|
||||||
|
|
||||||
double getDistanceToLastCoordinate();
|
TinyGPSPlus* getGPS() { return this->gps; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Coordinate *lastCoordinate;
|
TinyGPSPlus* gps;
|
||||||
|
Route* route;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAVIGATION_H
|
#endif // NAVIGATION_H
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* @file route.cpp
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2022-01-31
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "route.h"
|
||||||
|
|
||||||
|
Route::Route() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Route::addPointToRoute(Point point) {
|
||||||
|
this->points.push_back(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
Point Route::startRoute() {
|
||||||
|
*this->it = this->points.begin();
|
||||||
|
return **this->it;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point Route::getNextPoint() {
|
||||||
|
if (*this->it != this->points.end())
|
||||||
|
return **this->it;
|
||||||
|
else
|
||||||
|
return Point(0, 0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* @file route.h
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2022-01-31
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ROUTE_H
|
||||||
|
#define ROUTE_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Point{
|
||||||
|
public:
|
||||||
|
Point(double lat, double lon) {this->lat = lat; this->lon = lon;}
|
||||||
|
double lat = 0;
|
||||||
|
double lon = 0;
|
||||||
|
bool operator==(const Point& rhs) const {
|
||||||
|
return this->lat == rhs.lat && this->lon == rhs.lon;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Route {
|
||||||
|
public:
|
||||||
|
Route();
|
||||||
|
void addPointToRoute(Point point);
|
||||||
|
Point startRoute();
|
||||||
|
Point getNextPoint();
|
||||||
|
|
||||||
|
uint16_t getNumberOfPoints() { return this->count_points; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint16_t count_points = 0;
|
||||||
|
|
||||||
|
std::list<Point> points;
|
||||||
|
std::list<Point>::iterator* it;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ROUTE_H
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* @file menuCaptureRoute.cpp
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2022-01-31
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "menuCaptureRoute.h"
|
||||||
|
|
||||||
|
void MenuCaptureRoute::printMenu() {
|
||||||
|
this->driveManager->changeModus(Modi::CaptureRoute);
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* @file menuCaptureRoute.h
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2022-01-31
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef MENU_CAPTURE_ROUTE_H
|
||||||
|
#define MENU_MANUAL_DRIVE_H
|
||||||
|
|
||||||
|
#include "menuDriveMode.h"
|
||||||
|
|
||||||
|
class MenuCaptureRoute : public MenuDriveMode {
|
||||||
|
public:
|
||||||
|
MenuCaptureRoute(DriveManager* driveManager) : MenuDriveMode(driveManager) {}
|
||||||
|
void printMenu();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MENU_MANUAL_DRIVE_H
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* @file menuDriveMode.cpp
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2022-01-31
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "menuDriveMode.h"
|
||||||
|
|
||||||
|
MenuDriveMode::MenuDriveMode(DriveManager* driveManager) {
|
||||||
|
this->driveManager = driveManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuDriveMode::left() {
|
||||||
|
this->driveManager->changeModus(Modi::Off);
|
||||||
|
if (parentMenu)
|
||||||
|
this->parentMenu->printMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuDriveMode::no() {
|
||||||
|
this->left();
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* @file menuDriveMode.h
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2022-01-31
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef MENU_DRIVE_MODI_H
|
||||||
|
#define MENU_DRIVE_MODI_H
|
||||||
|
|
||||||
|
#include "menuControl.h"
|
||||||
|
#include "driveModi/driveManager.h"
|
||||||
|
|
||||||
|
class MenuDriveMode : public MenuControl {
|
||||||
|
public:
|
||||||
|
MenuDriveMode(DriveManager* driveManager);
|
||||||
|
|
||||||
|
void down(){}
|
||||||
|
void up(){}
|
||||||
|
void right(){}
|
||||||
|
void left();
|
||||||
|
void no();
|
||||||
|
void yes(){}
|
||||||
|
|
||||||
|
virtual void printMenu() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
DriveManager* driveManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MENU_DRIVE_MODI_H
|
||||||
@@ -36,7 +36,7 @@ void MenuGPS::printMenu() {
|
|||||||
if (this->lcd) {
|
if (this->lcd) {
|
||||||
lcd->clear();
|
lcd->clear();
|
||||||
lcd->setCursor(0, 0);
|
lcd->setCursor(0, 0);
|
||||||
if (gps->satellites.isValid()) {
|
if (gps->satellites.isValid() && gps->satellites.value() > 2) {
|
||||||
lcd->printf("Sats: %3.d", gps->satellites.value());
|
lcd->printf("Sats: %3.d", gps->satellites.value());
|
||||||
lcd->setCursor(0, 1);
|
lcd->setCursor(0, 1);
|
||||||
lcd->printf("HDOP: %f", gps->hdop.hdop());
|
lcd->printf("HDOP: %f", gps->hdop.hdop());
|
||||||
@@ -44,12 +44,14 @@ void MenuGPS::printMenu() {
|
|||||||
lcd->clear();
|
lcd->clear();
|
||||||
lcd->setCursor(0, 0);
|
lcd->setCursor(0, 0);
|
||||||
lcd->printf("Data isn't valid");
|
lcd->printf("Data isn't valid");
|
||||||
|
lcd->setCursor(0, 1);
|
||||||
|
lcd->printf("or no GPS signal");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (gps->satellites.isValid())
|
if (gps->satellites.isValid() && gps->satellites.value() > 2)
|
||||||
std::cout << "Sats: " << gps->satellites.value()
|
std::cout << "Sats: " << gps->satellites.value()
|
||||||
<< "HDOP: " << gps->hdop.hdop() << std::endl;
|
<< "HDOP: " << gps->hdop.hdop() << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << "Date isn't valid" << std::endl;
|
std::cout << "Date isn't valid or no GPS signal" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* @file menuManualDrive.cpp
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2022-01-20
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022
|
||||||
|
*
|
||||||
|
*/
|
||||||
#include "menuManualDrive.h"
|
#include "menuManualDrive.h"
|
||||||
|
|
||||||
MenuManualControl::MenuManualControl(DriveManager* driveManager) {
|
|
||||||
this->driveManager = driveManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuManualControl::left() {
|
|
||||||
this->driveManager->changeModus(Modi::Off);
|
|
||||||
if (parentMenu)
|
|
||||||
this->parentMenu->printMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuManualControl::no() {
|
|
||||||
this->left();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuManualControl::printMenu() {
|
void MenuManualControl::printMenu() {
|
||||||
this->driveManager->changeModus(Modi::ManualControl);
|
this->driveManager->changeModus(Modi::ManualControl);
|
||||||
if (this->lcd) {
|
if (this->lcd) {
|
||||||
|
|||||||
@@ -12,27 +12,12 @@
|
|||||||
#ifndef MENU_MANUAL_DRIVE_H
|
#ifndef MENU_MANUAL_DRIVE_H
|
||||||
#define MENU_MANUAL_DRIVE_H
|
#define MENU_MANUAL_DRIVE_H
|
||||||
|
|
||||||
#include "menuControl.h"
|
#include "menuDriveMode.h"
|
||||||
#include "driveModi/driveManager.h"
|
|
||||||
|
|
||||||
// TODO: delete after installtion of display
|
class MenuManualControl : public MenuDriveMode {
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
class MenuManualControl : public MenuControl {
|
|
||||||
public:
|
public:
|
||||||
MenuManualControl(DriveManager* driveManager);
|
MenuManualControl(DriveManager* driveManager) : MenuDriveMode(driveManager) {}
|
||||||
|
|
||||||
void down(){}
|
|
||||||
void up(){}
|
|
||||||
void right(){}
|
|
||||||
void left();
|
|
||||||
void no();
|
|
||||||
void yes(){}
|
|
||||||
|
|
||||||
void printMenu();
|
void printMenu();
|
||||||
|
|
||||||
private:
|
|
||||||
DriveManager* driveManager;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MENU_MANUAL_DRIVE_H
|
#endif // MENU_MANUAL_DRIVE_H
|
||||||
@@ -1,22 +1,14 @@
|
|||||||
#include "driveModi/Modi/CaptureRoute/captureRoute.h"
|
#include "driveModi/Modi/CaptureRoute/captureRoute.h"
|
||||||
|
|
||||||
CaptureRoute::CaptureRoute() {
|
CaptureRoute::CaptureRoute(MoveControl* moveControl, Navigation* navigation)
|
||||||
|
: ManualControl(moveControl) {
|
||||||
|
this->navigation = navigation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CaptureRoute::init() {
|
void CaptureRoute::loop() {
|
||||||
|
ManualControl::loop();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CaptureRoute::runCaptureRoute() {
|
void CaptureRoute::runCaptureRoute() {
|
||||||
// this->runManualControl();
|
|
||||||
|
|
||||||
// static uint64_t last_millis = 0;
|
|
||||||
// if (millis() - last_millis < RUN_CAPTuRE_ROUTE_DELAY) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// last_millis = millis();
|
|
||||||
|
|
||||||
//Add Point to route
|
|
||||||
// this->route->addCurrentLocationToRoute();
|
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,20 @@
|
|||||||
#ifndef CAPTURE_ROUTE_H
|
#ifndef CAPTURE_ROUTE_H
|
||||||
#define CAPTURE_ROUTE_H
|
#define CAPTURE_ROUTE_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "driveModi/Modi/ManualControl/manualControl.h"
|
#include "driveModi/Modi/ManualControl/manualControl.h"
|
||||||
// #include "route.h"
|
#include "navigation.h"
|
||||||
|
|
||||||
#include "config.h"
|
class CaptureRoute : public ManualControl {
|
||||||
|
|
||||||
class CaptureRoute : ManualControl {
|
|
||||||
public:
|
public:
|
||||||
CaptureRoute();
|
CaptureRoute(MoveControl* moveControl, Navigation* navigation);
|
||||||
|
|
||||||
void init();
|
void loop();
|
||||||
void runCaptureRoute();
|
void runCaptureRoute();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Route *route;
|
Navigation* navigation;
|
||||||
// DebugMqtt *debug;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CAPTURE_ROUTE_H
|
#endif // CAPTURE_ROUTE_H
|
||||||
@@ -10,7 +10,10 @@
|
|||||||
*/
|
*/
|
||||||
#include "manualControl.h"
|
#include "manualControl.h"
|
||||||
|
|
||||||
ManualControl::ManualControl() { }
|
ManualControl::ManualControl(MoveControl *moveControl) {
|
||||||
|
this->moveControl = moveControl;
|
||||||
|
this->moveControl->setDrivingStatus(DrivingStatus::drive);
|
||||||
|
}
|
||||||
|
|
||||||
ManualControl::~ManualControl() {
|
ManualControl::~ManualControl() {
|
||||||
this->moveControl->setSpeed(0);
|
this->moveControl->setSpeed(0);
|
||||||
@@ -18,11 +21,6 @@ ManualControl::~ManualControl() {
|
|||||||
this->moveControl->setDrivingStatus(DrivingStatus::stop);
|
this->moveControl->setDrivingStatus(DrivingStatus::stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManualControl::init(MoveControl *moveControl) {
|
|
||||||
this->moveControl = moveControl;
|
|
||||||
this->moveControl->setDrivingStatus(DrivingStatus::drive);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ManualControl::loop() {
|
void ManualControl::loop() {
|
||||||
static uint32_t last_millis = 0;
|
static uint32_t last_millis = 0;
|
||||||
if (millis() - last_millis < delay) {
|
if (millis() - last_millis < delay) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
class ManualControl : public DriveModi{
|
class ManualControl : public DriveModi{
|
||||||
public:
|
public:
|
||||||
ManualControl();
|
ManualControl(MoveControl *moveControl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy the Manual Control object
|
* @brief Destroy the Manual Control object
|
||||||
@@ -34,15 +34,6 @@ class ManualControl : public DriveModi{
|
|||||||
*/
|
*/
|
||||||
~ManualControl();
|
~ManualControl();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initalize ManualControl
|
|
||||||
*
|
|
||||||
* set DrivingStatus::drive
|
|
||||||
*
|
|
||||||
* @param moveControl
|
|
||||||
*/
|
|
||||||
void init(MoveControl *moveControl);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calls runManualControl() to update all values.
|
* @brief Calls runManualControl() to update all values.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -11,28 +11,30 @@
|
|||||||
|
|
||||||
#include "driveModi/driveManager.h"
|
#include "driveModi/driveManager.h"
|
||||||
|
|
||||||
|
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) {
|
||||||
this->moveControl = moveControl;
|
this->moveControl = moveControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DriveManager::loop() {
|
void DriveManager::loop() {
|
||||||
this->moveControl->loop();
|
this->moveControl->loop();
|
||||||
if (currentModus)
|
this->navigation->loop();
|
||||||
this->currentModus->loop();
|
if (currentModusPtr)
|
||||||
}
|
this->currentModusPtr->loop();
|
||||||
|
|
||||||
void DriveManager::runDriveManager() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DriveManager::nextModus() {
|
void DriveManager::nextModus() {
|
||||||
|
changeModus(this->currentModus++);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DriveManager::changeModus(Modi modus) {
|
void DriveManager::changeModus(Modi modus) {
|
||||||
|
this->currentModus = modus;
|
||||||
|
|
||||||
//Set moveControl to a safe state
|
//Set moveControl to a safe state
|
||||||
delete this->currentModus;
|
delete this->currentModusPtr;
|
||||||
|
|
||||||
this->moveControl->setSpeed(0);
|
this->moveControl->setSpeed(0);
|
||||||
this->moveControl->setRotationspeed(0);
|
this->moveControl->setRotationspeed(0);
|
||||||
@@ -40,34 +42,33 @@ void DriveManager::changeModus(Modi modus) {
|
|||||||
|
|
||||||
switch (modus) {
|
switch (modus) {
|
||||||
case Modi::Off:
|
case Modi::Off:
|
||||||
this->currentModus = nullptr;
|
this->currentModusPtr = nullptr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::ManualControl: {
|
case Modi::ManualControl: {
|
||||||
ManualControl *ptr = new ManualControl;
|
this->currentModusPtr = new ManualControl(this->moveControl);
|
||||||
ptr->init(this->moveControl);
|
|
||||||
this->currentModus = ptr;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::CaptureRoute:
|
case Modi::CaptureRoute: {
|
||||||
this->currentModus = nullptr;
|
this->currentModusPtr = new CaptureRoute(this->moveControl, this->navigation);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::Autopilot:
|
case Modi::Autopilot:
|
||||||
this->currentModus = nullptr;
|
this->currentModusPtr = nullptr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::ConsolControl:
|
case Modi::ConsolControl:
|
||||||
this->currentModus = nullptr;
|
this->currentModusPtr = nullptr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::TestMode:
|
case Modi::TestMode:
|
||||||
this->currentModus = nullptr;
|
this->currentModusPtr = nullptr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this->currentModus = nullptr;
|
this->currentModusPtr = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,16 @@
|
|||||||
#ifndef DRIVE_MANAGER_H
|
#ifndef DRIVE_MANAGER_H
|
||||||
#define DRIVE_MANAGER_H
|
#define DRIVE_MANAGER_H
|
||||||
|
|
||||||
|
//GPS Serial Pins
|
||||||
|
#define GPS_RX 17
|
||||||
|
#define GPS_TX 16
|
||||||
|
#define GPS_BAUD 9600
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "moveControl.h"
|
#include "moveControl.h"
|
||||||
#include "driveModi/driveModi.h"
|
#include "driveModi/driveModi.h"
|
||||||
|
#include "navigation.h"
|
||||||
|
|
||||||
// All Drive Modi
|
// All Drive Modi
|
||||||
#include "driveModi/Modi/ManualControl/manualControl.h"
|
#include "driveModi/Modi/ManualControl/manualControl.h"
|
||||||
@@ -29,22 +37,25 @@ enum class Modi {
|
|||||||
Autopilot,
|
Autopilot,
|
||||||
ConsolControl,
|
ConsolControl,
|
||||||
TestMode
|
TestMode
|
||||||
};
|
};
|
||||||
|
|
||||||
class DriveManager {
|
class DriveManager {
|
||||||
public:
|
public:
|
||||||
DriveManager(MoveControl *moveControl);
|
DriveManager(MoveControl *moveControl);
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
void runDriveManager();
|
|
||||||
|
|
||||||
void nextModus();
|
void nextModus();
|
||||||
void changeModus(Modi modus);
|
void changeModus(Modi modus);
|
||||||
|
|
||||||
private:
|
Navigation* getNavigation() {return this->navigation;}
|
||||||
MoveControl *moveControl;
|
DriveModi* getDriveModiPtr() { return this->currentModusPtr; }
|
||||||
DriveModi *currentModus;
|
Modi getDriveModi() { return this->currentModus; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Modi currentModus = Modi::Off;
|
||||||
|
MoveControl *moveControl;
|
||||||
|
DriveModi *currentModusPtr;
|
||||||
|
Navigation* navigation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+13
-7
@@ -3,7 +3,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <LiquidCrystal_I2C.h>
|
#include <LiquidCrystal_I2C.h>
|
||||||
#include <TinyGPS++.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
@@ -17,13 +16,13 @@
|
|||||||
#include "menuAction.h"
|
#include "menuAction.h"
|
||||||
#include "SpecialMenus/menuPidSettings.h"
|
#include "SpecialMenus/menuPidSettings.h"
|
||||||
#include "SpecialMenus/menuManualDrive.h"
|
#include "SpecialMenus/menuManualDrive.h"
|
||||||
|
#include "SpecialMenus/menuCaptureRoute.h"
|
||||||
#include "SpecialMenus/menuGPS.h"
|
#include "SpecialMenus/menuGPS.h"
|
||||||
|
|
||||||
MoveControl moveController;
|
MoveControl moveController;
|
||||||
DriveManager driveManager(&moveController);
|
DriveManager driveManager(&moveController);
|
||||||
Menu* main_m;
|
Menu* main_m;
|
||||||
LiquidCrystal_I2C* lcd;
|
LiquidCrystal_I2C* lcd;
|
||||||
TinyGPSPlus gps;
|
|
||||||
|
|
||||||
// TODO: Platzhalter, muss irgendwann weg
|
// TODO: Platzhalter, muss irgendwann weg
|
||||||
void dummy(){std::cout << "Dummy in Action" <<std::endl;}
|
void dummy(){std::cout << "Dummy in Action" <<std::endl;}
|
||||||
@@ -33,12 +32,12 @@ void callbackControllerAction();
|
|||||||
void callbackControllerConnect();
|
void callbackControllerConnect();
|
||||||
void controllerPrintBattery();
|
void controllerPrintBattery();
|
||||||
void i2cScanner();
|
void i2cScanner();
|
||||||
|
void restart();
|
||||||
|
|
||||||
void exitDriveMode() {driveManager.changeModus(Modi::Off);}
|
void exitDriveMode() {driveManager.changeModus(Modi::Off);}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
|
|
||||||
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
||||||
|
|
||||||
Wire.begin(21, 19);
|
Wire.begin(21, 19);
|
||||||
@@ -57,7 +56,7 @@ void setup() {
|
|||||||
Ps3.attach(callbackControllerAction);
|
Ps3.attach(callbackControllerAction);
|
||||||
Ps3.attachOnConnect(callbackControllerConnect);
|
Ps3.attachOnConnect(callbackControllerConnect);
|
||||||
std::cout << "\nReady to connect a PS3 Controller... \n";
|
std::cout << "\nReady to connect a PS3 Controller... \n";
|
||||||
Ps3.begin();
|
Ps3.begin(CONTROLLER_MAC);
|
||||||
|
|
||||||
// Create Menu
|
// Create Menu
|
||||||
main_m = new Menu();
|
main_m = new Menu();
|
||||||
@@ -66,7 +65,8 @@ void setup() {
|
|||||||
MenuPidSettings* pidl_m = new MenuPidSettings(moveController.getPID(0));
|
MenuPidSettings* pidl_m = new MenuPidSettings(moveController.getPID(0));
|
||||||
MenuPidSettings* pidr_m = new MenuPidSettings(moveController.getPID(1));
|
MenuPidSettings* pidr_m = new MenuPidSettings(moveController.getPID(1));
|
||||||
MenuManualControl* man_m = new MenuManualControl(&driveManager);
|
MenuManualControl* man_m = new MenuManualControl(&driveManager);
|
||||||
MenuGPS* gps_m = new MenuGPS(&gps);
|
MenuCaptureRoute* cap_m = new MenuCaptureRoute(&driveManager);
|
||||||
|
MenuGPS* gps_m = new MenuGPS(driveManager.getNavigation()->getGPS());
|
||||||
|
|
||||||
// Set Menus on LCD
|
// Set Menus on LCD
|
||||||
main_m->setLcd(lcd);
|
main_m->setLcd(lcd);
|
||||||
@@ -75,6 +75,7 @@ void setup() {
|
|||||||
pidl_m->setLcd(lcd);
|
pidl_m->setLcd(lcd);
|
||||||
pidr_m->setLcd(lcd);
|
pidr_m->setLcd(lcd);
|
||||||
man_m->setLcd(lcd);
|
man_m->setLcd(lcd);
|
||||||
|
cap_m->setLcd(lcd);
|
||||||
gps_m->setLcd(lcd);
|
gps_m->setLcd(lcd);
|
||||||
|
|
||||||
|
|
||||||
@@ -82,13 +83,15 @@ void setup() {
|
|||||||
MenuAction* mode_e = new MenuAction("Mode", mode_m);
|
MenuAction* mode_e = new MenuAction("Mode", mode_m);
|
||||||
MenuAction* gps_e = new MenuAction("GPS", gps_m);
|
MenuAction* gps_e = new MenuAction("GPS", gps_m);
|
||||||
MenuAction* pid_e = new MenuAction("PID", pid_m);
|
MenuAction* pid_e = new MenuAction("PID", pid_m);
|
||||||
|
MenuAction* restart_e = new MenuAction("Restart", restart);
|
||||||
main_m->addEntry(mode_e);
|
main_m->addEntry(mode_e);
|
||||||
main_m->addEntry(gps_e);
|
main_m->addEntry(gps_e);
|
||||||
main_m->addEntry(pid_e);
|
main_m->addEntry(pid_e);
|
||||||
|
main_m->addEntry(restart_e);
|
||||||
|
|
||||||
// Entry for the mode Menu
|
// Entry for the mode Menu
|
||||||
MenuAction* autopilot_e = new MenuAction("Autopilot", dummy);
|
MenuAction* autopilot_e = new MenuAction("Autopilot", dummy);
|
||||||
MenuAction* captureRoute_e = new MenuAction("Capture Route", dummy);
|
MenuAction* captureRoute_e = new MenuAction("Capture Route", cap_m);
|
||||||
MenuAction* consolControl_e = new MenuAction("Consol Control", dummy);
|
MenuAction* consolControl_e = new MenuAction("Consol Control", dummy);
|
||||||
MenuAction* manualControl_e = new MenuAction("Manual Control", man_m);
|
MenuAction* manualControl_e = new MenuAction("Manual Control", man_m);
|
||||||
MenuAction* testMode_e = new MenuAction("Test Mode", dummy);
|
MenuAction* testMode_e = new MenuAction("Test Mode", dummy);
|
||||||
@@ -109,7 +112,6 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
Network::checkMQTT();
|
Network::checkMQTT();
|
||||||
driveManager.loop();
|
driveManager.loop();
|
||||||
gps.encode(Serial1.read());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isDelayReached(bool reset = false) {
|
bool isDelayReached(bool reset = false) {
|
||||||
@@ -200,3 +202,7 @@ void i2cScanner() {
|
|||||||
else
|
else
|
||||||
Serial.println("done\n");
|
Serial.println("done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void restart() {
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
// #include "route.h"
|
|
||||||
// #include "config.h"
|
|
||||||
|
|
||||||
// Route::Route() {
|
|
||||||
// Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
|
|
||||||
// this->debug = new DebugMqtt("Route");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void Route::runRoute() {
|
|
||||||
// static uint64_t last_millis = 0;
|
|
||||||
// if (millis() - last_millis < 123456789) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// last_millis = millis();
|
|
||||||
|
|
||||||
// while (Serial1.available() > 0)
|
|
||||||
// gps.encode(Serial1.read());
|
|
||||||
|
|
||||||
// if (gps.location.isUpdated() && gps.location.isValid()) {
|
|
||||||
// this->currentLocation.lat = gps.location.lat();
|
|
||||||
// this->currentLocation.lon = gps.location.lng();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void Route::addPointToRoute(Point point) {
|
|
||||||
// this->points.push_back(point);
|
|
||||||
// this->count_points++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void Route::addCurrentLocationToRoute() {
|
|
||||||
// if (*this->points.end() == this->currentLocation &&
|
|
||||||
// !this->nearlySameLocation(*this->points.end(), this->currentLocation)) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// this->addPointToRoute(currentLocation);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void Route::delRoute() {
|
|
||||||
// this->points.clear();
|
|
||||||
// this->count_points = 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Point Route::startRoute() {
|
|
||||||
// this->route_started = true;
|
|
||||||
// this->route_finished = false;
|
|
||||||
|
|
||||||
// this->it = this->points.begin();
|
|
||||||
// return *it;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Point Route::getNextPoint() {
|
|
||||||
// if (this->route_started && !route_finished) {
|
|
||||||
// it++;
|
|
||||||
// return *it;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (it == this->points.end()) {
|
|
||||||
// this->route_finished = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Point fail;
|
|
||||||
// return fail;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// uint16_t Route::getNumberOfPoints() {
|
|
||||||
// return this->count_points;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// double Route::getDis(Point point_1, Point point_2) {
|
|
||||||
// double lat = (point_1.lat + point_2.lat) / 2 * 0.1745;
|
|
||||||
// double dx = 111.3 * cos(lat) * (point_1.lon - point_2.lon);
|
|
||||||
// double dy = 111.3 * (point_1.lat - point_2.lat);
|
|
||||||
// return sqrt(dx * dx + dy * dy);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// bool Route::nearlySameLocation(Point p1, Point p2) {
|
|
||||||
// if (this->getDis(p1, p2) < 0.5)
|
|
||||||
// return true;
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
Reference in New Issue
Block a user