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"
Navigation::Navigation(uint8_t rx, uint8_t tx) {
this->gps = new TinyGPSPlus();
this->gps = new TinyGPSPlus;
Serial1.begin(9600, SERIAL_8N1, rx, tx);
}
Navigation::~Navigation() {
delete this->gps;
}
void Navigation::loop() {
while (Serial1.available())
gps->encode(Serial1.read());
}
void Navigation::addCurrentPosToRoute() {
Point 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();
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 <Arduino.h>
#include <iostream>
#include "route.h"
#define MIN_DISTANCE_BETWEEN_POINTS 1
class Navigation {
public:
Navigation(uint8_t rx, uint8_t tx);
~Navigation();
void loop();
void addCurrentPosToRoute();
Point addCurrentPosToRoute();
TinyGPSPlus* getGPS() { return this->gps; }
private:
TinyGPSPlus* gps;
Route* route;
Point lastPoint;
};
#endif // NAVIGATION_H
+6 -3
View File
@@ -16,16 +16,19 @@
#include <list>
class Point{
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 lon = 0;
bool operator==(const Point& rhs) const {
return this->lat == rhs.lat && this->lon == rhs.lon;
}
bool isValid() const { return this->lat + this->lon; }
};
class Route {
+1
View File
@@ -26,6 +26,7 @@ class MenuDriveMode : public MenuControl {
void yes(){}
virtual void printMenu() = 0;
void update(){}
protected:
DriveManager* driveManager;
@@ -7,8 +7,16 @@ CaptureRoute::CaptureRoute(MoveControl* moveControl, Navigation* navigation)
void CaptureRoute::loop() {
ManualControl::loop();
if (millis() - this->last_millis < delay) {
return;
}
this->runCaptureRoute();
this->last_millis = millis();
}
void CaptureRoute::runCaptureRoute() {
if (Ps3.data.button.triangle) {
this->navigation->addCurrentPosToRoute();
}
}
@@ -6,6 +6,7 @@
#include "driveModi/Modi/ManualControl/manualControl.h"
#include "navigation.h"
class CaptureRoute : public ManualControl {
public:
CaptureRoute(MoveControl* moveControl, Navigation* navigation);
@@ -15,6 +16,9 @@ class CaptureRoute : public ManualControl {
private:
Navigation* navigation;
uint32_t last_millis = 0;
uint16_t delay = 200;
};
#endif // CAPTURE_ROUTE_H
@@ -22,12 +22,11 @@ ManualControl::~ManualControl() {
}
void ManualControl::loop() {
static uint32_t last_millis = 0;
if (millis() - last_millis < delay) {
if (millis() - this->last_millis < delay) {
return;
}
this->runManualControl();
last_millis = millis();
this->last_millis = millis();
}
void ManualControl::runManualControl() {
@@ -11,8 +11,6 @@
#ifndef MANUAL_CONTROL_H
#define MANUAL_CONTROL_H
#include <Ps3Controller.h>
#include "moveControl.h"
#include "driveModi/driveModi.h"
@@ -74,6 +72,7 @@ class ManualControl : public DriveModi{
private:
MoveControl *moveControl;
uint32_t last_millis = 0;
uint8_t delay = 10;
double max_speed = 1;
double max_rotation = 7;
+5
View File
@@ -17,6 +17,11 @@ Modi& operator++(Modi& m, int) {
DriveManager::DriveManager(MoveControl *moveControl) {
this->moveControl = moveControl;
this->navigation = new Navigation(17, 16);
}
DriveManager::~DriveManager() {
delete this->navigation;
}
void DriveManager::loop() {
+2 -1
View File
@@ -42,6 +42,7 @@ enum class Modi {
class DriveManager {
public:
DriveManager(MoveControl *moveControl);
~DriveManager();
void loop();
void nextModus();
@@ -54,7 +55,7 @@ class DriveManager {
private:
Modi currentModus = Modi::Off;
MoveControl *moveControl;
DriveModi *currentModusPtr;
DriveModi *currentModusPtr = nullptr;
Navigation* navigation;
};
+2
View File
@@ -12,6 +12,8 @@
#ifndef DRIVEMODI_H
#define DRIVEMODI_H
#include <Ps3Controller.h>
class DriveModi {
public:
DriveModi(){}
+4
View File
@@ -39,6 +39,7 @@ void exitDriveMode() {driveManager.changeModus(Modi::Off);}
void setup() {
Serial.begin(115200);
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);
// i2cScanner();
@@ -146,10 +147,13 @@ void callbackControllerAction() {
isDelayReached(true);
}
// This have to be stand here because it have to be run on the other Core
main_m->update();
}
void callbackControllerConnect() {
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()
lcd->init();