zwischenstand, ich habe Lust mache jetzt weiter :)

This commit is contained in:
2022-01-12 15:21:53 +01:00
parent 29a636060c
commit be6f20d96b
10 changed files with 181 additions and 118 deletions
+2 -2
View File
@@ -5,9 +5,9 @@ ESP32 Rover Pinbelegung
x 22 PWMR
x TX PC
x RX PC
AKKU 35 21
AKKU 35 21 SDA
INTL1 32 GND
INTL2 33 19
INTL2 33 19 SCL
INTB1 25 18
INTB2 26 5
DirL1 27 TX GPS
+39 -44
View File
@@ -1,58 +1,53 @@
#ifndef ROUTE_H
#define ROUTE_H
// #ifndef ROUTE_H
// #define ROUTE_H
#include <cstdint>
#include <list>
#include <TinyGPS++.h>
#include <Arduino.h>
// #include <cstdint>
// #include <list>
// #include <TinyGPS++.h>
// #include <Arduino.h>
#include "motorControl.h"
#include "speedometer.h"
#include "debugMqtt.h"
#include "config.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;
}
};
// 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();
// class Route {
// public:
// Route();
void runRoute();
// void runRoute();
void addPointToRoute(Point point);
void addCurrentLocationToRoute();
void delRoute();
void resetRoute();
// void addPointToRoute(Point point);
// void addCurrentLocationToRoute();
// void delRoute();
// void resetRoute();
Point startRoute();
Point getNextPoint();
uint16_t getNumberOfPoints();
// Point startRoute();
// Point getNextPoint();
// uint16_t getNumberOfPoints();
static double getDis(Point point_1, Point point_2);
// static double getDis(Point point_1, Point point_2);
private:
bool nearlySameLocation(Point p1, Point p2);
// private:
// bool nearlySameLocation(Point p1, Point p2);
std::list<Point> points;
std::list<Point>::iterator it;
Point currentLocation;
// std::list<Point> points;
// std::list<Point>::iterator it;
// Point currentLocation;
uint16_t count_points = 0;
// uint16_t count_points = 0;
bool route_started = false;
bool route_finished = false;
// bool route_started = false;
// bool route_finished = false;
// };
TinyGPSPlus gps;
DebugMqtt *debug;
};
#endif // ROUTE_H
// #endif // ROUTE_H
+2
View File
@@ -0,0 +1,2 @@
#include "coordinate.h"
+31
View File
@@ -0,0 +1,31 @@
/**
* @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
+2
View File
@@ -0,0 +1,2 @@
#include "navigation.h"
+33
View File
@@ -0,0 +1,33 @@
/**
* @file navigation.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-01-10
*
* @copyright Copyright (c) 2022
*
*/
#ifndef NAVIGATION_H
#define NAVIGATION_H
#include <Arduino.h>
#include "coordinate.h"
class Navigation {
public:
Navigation(uint32_t baud, uint8_t rx, uint8_t tx);
void addCoordinateToRoute(Coordinate coordinate);
void addCurrentCoordinateToRoute();
void delRoute();
double getDistanceToLastCoordinate();
private:
Coordinate *lastCoordinate;
};
#endif // NAVIGATION_H
+1 -4
View File
@@ -1,12 +1,9 @@
#include "driveModi/Modi/Autopilot/autopilot.h"
Autopilot::Autopilot() {
this->debug = new DebugMqtt("Autopilot");
}
void Autopilot::init(Route *route, MoveControl *moveControl) {
this->route = route;
this->moveControl = moveControl;
void Autopilot::init() {
}
void Autopilot::runAutopilot() {
+1 -2
View File
@@ -12,13 +12,12 @@ class Autopilot : DriveModi{
public:
Autopilot();
void init(Route *route, MoveControl *moveControl);
void init();
void loop();
void runAutopilot();
private:
Route *route;
MoveControl *moveControl;
DebugMqtt *debug;
+5 -1
View File
@@ -18,7 +18,7 @@ DriveManager driveManager(&moveController);
void setup() {
Serial.begin(115200);
Serial.println("Welcome...");
Serial.println("Welcome to Kleiax-Rover");
Network::setIps();
Network::connectWifi();
@@ -30,11 +30,15 @@ void setup() {
Ps3.begin();
driveManager.changeModus(Modi::ManualControl);
Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
}
void loop() {
Network::checkMQTT();
driveManager.loop();
while (Serial1.available() > 0)
Serial.print(Serial1.read());
}
void callbackControllerAction() {
+65 -65
View File
@@ -1,80 +1,80 @@
#include "route.h"
#include "config.h"
// #include "route.h"
// #include "config.h"
Route::Route() {
Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
this->debug = new DebugMqtt("Route");
}
// 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();
// 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());
// 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();
}
}
// 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::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::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;
}
// void Route::delRoute() {
// this->points.clear();
// this->count_points = 0;
// }
Point Route::startRoute() {
this->route_started = true;
this->route_finished = false;
// Point Route::startRoute() {
// this->route_started = true;
// this->route_finished = false;
this->it = this->points.begin();
return *it;
}
// this->it = this->points.begin();
// return *it;
// }
Point Route::getNextPoint() {
if (this->route_started && !route_finished) {
it++;
return *it;
}
// Point Route::getNextPoint() {
// if (this->route_started && !route_finished) {
// it++;
// return *it;
// }
if (it == this->points.end()) {
this->route_finished = true;
}
// if (it == this->points.end()) {
// this->route_finished = true;
// }
Point fail;
return fail;
}
// Point fail;
// return fail;
// }
uint16_t Route::getNumberOfPoints() {
return this->count_points;
}
// 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);
}
// 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;
}
// bool Route::nearlySameLocation(Point p1, Point p2) {
// if (this->getDis(p1, p2) < 0.5)
// return true;
// return false;
// }