added more functions for capture route

This commit is contained in:
2022-02-01 18:26:57 +01:00
parent 44be2b2b77
commit 894f3439bd
12 changed files with 59 additions and 15 deletions
+14 -2
View File
@@ -12,18 +12,30 @@
#include "navigation.h" #include "navigation.h"
Navigation::Navigation(uint8_t rx, uint8_t tx) { Navigation::Navigation(uint8_t rx, uint8_t tx) {
this->gps = new TinyGPSPlus(); this->gps = new TinyGPSPlus;
Serial1.begin(9600, SERIAL_8N1, rx, tx); Serial1.begin(9600, SERIAL_8N1, rx, tx);
} }
Navigation::~Navigation() {
delete this->gps;
}
void Navigation::loop() { void Navigation::loop() {
while (Serial1.available())
gps->encode(Serial1.read()); gps->encode(Serial1.read());
} }
void Navigation::addCurrentPosToRoute() { Point Navigation::addCurrentPosToRoute() {
Point p; Point p;
if (this->gps->location.isUpdated() && this->gps->location.isValid()) { if (this->gps->location.isUpdated() && this->gps->location.isValid()) {
p.lat = this->gps->location.lat(); p.lat = this->gps->location.lat();
p.lon = this->gps->location.lng(); p.lon = this->gps->location.lng();
if (MIN_DISTANCE_BETWEEN_POINTS <=
TinyGPSPlus::distanceBetween(p.lat, p.lon, this->lastPoint.lat, this->lastPoint.lon))
this->route->addPointToRoute(p);
} }
return p;
} }
+7 -1
View File
@@ -14,20 +14,26 @@
#include <TinyGPS++.h> #include <TinyGPS++.h>
#include <Arduino.h> #include <Arduino.h>
#include <iostream>
#include "route.h" #include "route.h"
#define MIN_DISTANCE_BETWEEN_POINTS 1
class Navigation { class Navigation {
public: public:
Navigation(uint8_t rx, uint8_t tx); Navigation(uint8_t rx, uint8_t tx);
~Navigation();
void loop(); void loop();
void addCurrentPosToRoute(); Point addCurrentPosToRoute();
TinyGPSPlus* getGPS() { return this->gps; } TinyGPSPlus* getGPS() { return this->gps; }
private: private:
TinyGPSPlus* gps; TinyGPSPlus* gps;
Route* route; Route* route;
Point lastPoint;
}; };
#endif // NAVIGATION_H #endif // NAVIGATION_H
+5 -2
View File
@@ -16,16 +16,19 @@
#include <list> #include <list>
class Point{ class Point{
public: public:
Point(double lat, double lon) { this->lat = lat; this->lon = lon; } Point(double lat, double lon) { this->lat = lat; this->lon = lon; }
Point(){ this->lat = 0; this->lon = 0; }
double lat = 0; double lat = 0;
double lon = 0; double lon = 0;
bool operator==(const Point& rhs) const { bool operator==(const Point& rhs) const {
return this->lat == rhs.lat && this->lon == rhs.lon; return this->lat == rhs.lat && this->lon == rhs.lon;
} }
bool isValid() const { return this->lat + this->lon; }
}; };
class Route { class Route {
+1
View File
@@ -26,6 +26,7 @@ class MenuDriveMode : public MenuControl {
void yes(){} void yes(){}
virtual void printMenu() = 0; virtual void printMenu() = 0;
void update(){}
protected: protected:
DriveManager* driveManager; DriveManager* driveManager;
@@ -7,8 +7,16 @@ CaptureRoute::CaptureRoute(MoveControl* moveControl, Navigation* navigation)
void CaptureRoute::loop() { void CaptureRoute::loop() {
ManualControl::loop(); ManualControl::loop();
if (millis() - this->last_millis < delay) {
return;
}
this->runCaptureRoute();
this->last_millis = millis();
} }
void CaptureRoute::runCaptureRoute() { void CaptureRoute::runCaptureRoute() {
if (Ps3.data.button.triangle) {
this->navigation->addCurrentPosToRoute();
}
} }
@@ -6,6 +6,7 @@
#include "driveModi/Modi/ManualControl/manualControl.h" #include "driveModi/Modi/ManualControl/manualControl.h"
#include "navigation.h" #include "navigation.h"
class CaptureRoute : public ManualControl { class CaptureRoute : public ManualControl {
public: public:
CaptureRoute(MoveControl* moveControl, Navigation* navigation); CaptureRoute(MoveControl* moveControl, Navigation* navigation);
@@ -15,6 +16,9 @@ class CaptureRoute : public ManualControl {
private: private:
Navigation* navigation; Navigation* navigation;
uint32_t last_millis = 0;
uint16_t delay = 200;
}; };
#endif // CAPTURE_ROUTE_H #endif // CAPTURE_ROUTE_H
@@ -22,12 +22,11 @@ ManualControl::~ManualControl() {
} }
void ManualControl::loop() { void ManualControl::loop() {
static uint32_t last_millis = 0; if (millis() - this->last_millis < delay) {
if (millis() - last_millis < delay) {
return; return;
} }
this->runManualControl(); this->runManualControl();
last_millis = millis(); this->last_millis = millis();
} }
void ManualControl::runManualControl() { void ManualControl::runManualControl() {
@@ -11,8 +11,6 @@
#ifndef MANUAL_CONTROL_H #ifndef MANUAL_CONTROL_H
#define MANUAL_CONTROL_H #define MANUAL_CONTROL_H
#include <Ps3Controller.h>
#include "moveControl.h" #include "moveControl.h"
#include "driveModi/driveModi.h" #include "driveModi/driveModi.h"
@@ -74,6 +72,7 @@ class ManualControl : public DriveModi{
private: private:
MoveControl *moveControl; MoveControl *moveControl;
uint32_t last_millis = 0;
uint8_t delay = 10; uint8_t delay = 10;
double max_speed = 1; double max_speed = 1;
double max_rotation = 7; double max_rotation = 7;
+5
View File
@@ -17,6 +17,11 @@ Modi& operator++(Modi& m, int) {
DriveManager::DriveManager(MoveControl *moveControl) { DriveManager::DriveManager(MoveControl *moveControl) {
this->moveControl = moveControl; this->moveControl = moveControl;
this->navigation = new Navigation(17, 16);
}
DriveManager::~DriveManager() {
delete this->navigation;
} }
void DriveManager::loop() { void DriveManager::loop() {
+2 -1
View File
@@ -42,6 +42,7 @@ enum class Modi {
class DriveManager { class DriveManager {
public: public:
DriveManager(MoveControl *moveControl); DriveManager(MoveControl *moveControl);
~DriveManager();
void loop(); void loop();
void nextModus(); void nextModus();
@@ -54,7 +55,7 @@ class DriveManager {
private: private:
Modi currentModus = Modi::Off; Modi currentModus = Modi::Off;
MoveControl *moveControl; MoveControl *moveControl;
DriveModi *currentModusPtr; DriveModi *currentModusPtr = nullptr;
Navigation* navigation; Navigation* navigation;
}; };
+2
View File
@@ -12,6 +12,8 @@
#ifndef DRIVEMODI_H #ifndef DRIVEMODI_H
#define DRIVEMODI_H #define DRIVEMODI_H
#include <Ps3Controller.h>
class DriveModi { class DriveModi {
public: public:
DriveModi(){} DriveModi(){}
+4
View File
@@ -39,6 +39,7 @@ void exitDriveMode() {driveManager.changeModus(Modi::Off);}
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
std::cout << "Welcome to Kleiax-Rover" << std::endl; std::cout << "Welcome to Kleiax-Rover" << std::endl;
std::cout << "All actions from the main programm run on" << xPortGetCoreID() << std::endl;
Wire.begin(21, 19); Wire.begin(21, 19);
// i2cScanner(); // i2cScanner();
@@ -146,10 +147,13 @@ void callbackControllerAction() {
isDelayReached(true); isDelayReached(true);
} }
// This have to be stand here because it have to be run on the other Core
main_m->update();
} }
void callbackControllerConnect() { void callbackControllerConnect() {
std::cout << "Controller connected to ESP32" << std::endl; std::cout << "Controller connected to ESP32" << std::endl;
std::cout << "All actions from the Controller run on" << xPortGetCoreID() << std::endl;
// TODO: Display is not functional without this seconde init, first init is in setup() // TODO: Display is not functional without this seconde init, first init is in setup()
lcd->init(); lcd->init();