zwischenstand, ich habe Lust mache jetzt weiter :)
This commit is contained in:
@@ -5,9 +5,9 @@ ESP32 Rover Pinbelegung
|
|||||||
x 22 PWMR
|
x 22 PWMR
|
||||||
x TX PC
|
x TX PC
|
||||||
x RX PC
|
x RX PC
|
||||||
AKKU 35 21
|
AKKU 35 21 SDA
|
||||||
INTL1 32 GND
|
INTL1 32 GND
|
||||||
INTL2 33 19
|
INTL2 33 19 SCL
|
||||||
INTB1 25 18
|
INTB1 25 18
|
||||||
INTB2 26 5
|
INTB2 26 5
|
||||||
DirL1 27 TX GPS
|
DirL1 27 TX GPS
|
||||||
|
|||||||
+39
-44
@@ -1,58 +1,53 @@
|
|||||||
#ifndef ROUTE_H
|
// #ifndef ROUTE_H
|
||||||
#define ROUTE_H
|
// #define ROUTE_H
|
||||||
|
|
||||||
#include <cstdint>
|
// #include <cstdint>
|
||||||
#include <list>
|
// #include <list>
|
||||||
#include <TinyGPS++.h>
|
// #include <TinyGPS++.h>
|
||||||
#include <Arduino.h>
|
// #include <Arduino.h>
|
||||||
|
|
||||||
#include "motorControl.h"
|
// #include "motorControl.h"
|
||||||
#include "speedometer.h"
|
// #include "speedometer.h"
|
||||||
#include "debugMqtt.h"
|
// #include "debugMqtt.h"
|
||||||
#include "config.h"
|
// #include "config.h"
|
||||||
|
|
||||||
struct Point{
|
// struct Point{
|
||||||
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;
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
class Route {
|
// class Route {
|
||||||
public:
|
// public:
|
||||||
Route();
|
// Route();
|
||||||
|
|
||||||
void runRoute();
|
// void runRoute();
|
||||||
|
|
||||||
void addPointToRoute(Point point);
|
// void addPointToRoute(Point point);
|
||||||
void addCurrentLocationToRoute();
|
// void addCurrentLocationToRoute();
|
||||||
void delRoute();
|
// void delRoute();
|
||||||
void resetRoute();
|
// void resetRoute();
|
||||||
|
|
||||||
Point startRoute();
|
// Point startRoute();
|
||||||
Point getNextPoint();
|
// Point getNextPoint();
|
||||||
uint16_t getNumberOfPoints();
|
// uint16_t getNumberOfPoints();
|
||||||
|
|
||||||
static double getDis(Point point_1, Point point_2);
|
// static double getDis(Point point_1, Point point_2);
|
||||||
|
|
||||||
|
|
||||||
private:
|
// private:
|
||||||
bool nearlySameLocation(Point p1, Point p2);
|
// bool nearlySameLocation(Point p1, Point p2);
|
||||||
|
|
||||||
std::list<Point> points;
|
// std::list<Point> points;
|
||||||
std::list<Point>::iterator it;
|
// std::list<Point>::iterator it;
|
||||||
Point currentLocation;
|
// Point currentLocation;
|
||||||
|
|
||||||
uint16_t count_points = 0;
|
// uint16_t count_points = 0;
|
||||||
|
|
||||||
bool route_started = false;
|
// bool route_started = false;
|
||||||
bool route_finished = false;
|
// bool route_finished = false;
|
||||||
|
// };
|
||||||
|
|
||||||
TinyGPSPlus gps;
|
// #endif // ROUTE_H
|
||||||
|
|
||||||
DebugMqtt *debug;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // ROUTE_H
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#include "coordinate.h"
|
||||||
|
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#include "navigation.h"
|
||||||
|
|
||||||
@@ -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,12 +1,9 @@
|
|||||||
#include "driveModi/Modi/Autopilot/autopilot.h"
|
#include "driveModi/Modi/Autopilot/autopilot.h"
|
||||||
|
|
||||||
Autopilot::Autopilot() {
|
Autopilot::Autopilot() {
|
||||||
this->debug = new DebugMqtt("Autopilot");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Autopilot::init(Route *route, MoveControl *moveControl) {
|
void Autopilot::init() {
|
||||||
this->route = route;
|
|
||||||
this->moveControl = moveControl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Autopilot::runAutopilot() {
|
void Autopilot::runAutopilot() {
|
||||||
|
|||||||
@@ -12,13 +12,12 @@ class Autopilot : DriveModi{
|
|||||||
public:
|
public:
|
||||||
Autopilot();
|
Autopilot();
|
||||||
|
|
||||||
void init(Route *route, MoveControl *moveControl);
|
void init();
|
||||||
void loop();
|
void loop();
|
||||||
void runAutopilot();
|
void runAutopilot();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Route *route;
|
|
||||||
MoveControl *moveControl;
|
MoveControl *moveControl;
|
||||||
DebugMqtt *debug;
|
DebugMqtt *debug;
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -18,7 +18,7 @@ DriveManager driveManager(&moveController);
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Welcome...");
|
Serial.println("Welcome to Kleiax-Rover");
|
||||||
|
|
||||||
Network::setIps();
|
Network::setIps();
|
||||||
Network::connectWifi();
|
Network::connectWifi();
|
||||||
@@ -30,11 +30,15 @@ void setup() {
|
|||||||
Ps3.begin();
|
Ps3.begin();
|
||||||
|
|
||||||
driveManager.changeModus(Modi::ManualControl);
|
driveManager.changeModus(Modi::ManualControl);
|
||||||
|
|
||||||
|
Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
Network::checkMQTT();
|
Network::checkMQTT();
|
||||||
driveManager.loop();
|
driveManager.loop();
|
||||||
|
while (Serial1.available() > 0)
|
||||||
|
Serial.print(Serial1.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
void callbackControllerAction() {
|
void callbackControllerAction() {
|
||||||
|
|||||||
+65
-65
@@ -1,80 +1,80 @@
|
|||||||
#include "route.h"
|
// #include "route.h"
|
||||||
#include "config.h"
|
// #include "config.h"
|
||||||
|
|
||||||
Route::Route() {
|
// Route::Route() {
|
||||||
Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
|
// Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
|
||||||
this->debug = new DebugMqtt("Route");
|
// this->debug = new DebugMqtt("Route");
|
||||||
}
|
// }
|
||||||
|
|
||||||
void Route::runRoute() {
|
// void Route::runRoute() {
|
||||||
static uint64_t last_millis = 0;
|
// static uint64_t last_millis = 0;
|
||||||
if (millis() - last_millis < 123456789) {
|
// if (millis() - last_millis < 123456789) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
last_millis = millis();
|
// last_millis = millis();
|
||||||
|
|
||||||
while (Serial1.available() > 0)
|
// while (Serial1.available() > 0)
|
||||||
gps.encode(Serial1.read());
|
// gps.encode(Serial1.read());
|
||||||
|
|
||||||
if (gps.location.isUpdated() && gps.location.isValid()) {
|
// if (gps.location.isUpdated() && gps.location.isValid()) {
|
||||||
this->currentLocation.lat = gps.location.lat();
|
// this->currentLocation.lat = gps.location.lat();
|
||||||
this->currentLocation.lon = gps.location.lng();
|
// this->currentLocation.lon = gps.location.lng();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
void Route::addPointToRoute(Point point) {
|
// void Route::addPointToRoute(Point point) {
|
||||||
this->points.push_back(point);
|
// this->points.push_back(point);
|
||||||
this->count_points++;
|
// this->count_points++;
|
||||||
}
|
// }
|
||||||
|
|
||||||
void Route::addCurrentLocationToRoute() {
|
// void Route::addCurrentLocationToRoute() {
|
||||||
if (*this->points.end() == this->currentLocation &&
|
// if (*this->points.end() == this->currentLocation &&
|
||||||
!this->nearlySameLocation(*this->points.end(), this->currentLocation)) {
|
// !this->nearlySameLocation(*this->points.end(), this->currentLocation)) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
this->addPointToRoute(currentLocation);
|
// this->addPointToRoute(currentLocation);
|
||||||
}
|
// }
|
||||||
|
|
||||||
void Route::delRoute() {
|
// void Route::delRoute() {
|
||||||
this->points.clear();
|
// this->points.clear();
|
||||||
this->count_points = 0;
|
// this->count_points = 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Point Route::startRoute() {
|
// Point Route::startRoute() {
|
||||||
this->route_started = true;
|
// this->route_started = true;
|
||||||
this->route_finished = false;
|
// this->route_finished = false;
|
||||||
|
|
||||||
this->it = this->points.begin();
|
// this->it = this->points.begin();
|
||||||
return *it;
|
// return *it;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Point Route::getNextPoint() {
|
// Point Route::getNextPoint() {
|
||||||
if (this->route_started && !route_finished) {
|
// if (this->route_started && !route_finished) {
|
||||||
it++;
|
// it++;
|
||||||
return *it;
|
// return *it;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (it == this->points.end()) {
|
// if (it == this->points.end()) {
|
||||||
this->route_finished = true;
|
// this->route_finished = true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Point fail;
|
// Point fail;
|
||||||
return fail;
|
// return fail;
|
||||||
}
|
// }
|
||||||
|
|
||||||
uint16_t Route::getNumberOfPoints() {
|
// uint16_t Route::getNumberOfPoints() {
|
||||||
return this->count_points;
|
// return this->count_points;
|
||||||
}
|
// }
|
||||||
|
|
||||||
double Route::getDis(Point point_1, Point point_2) {
|
// double Route::getDis(Point point_1, Point point_2) {
|
||||||
double lat = (point_1.lat + point_2.lat) / 2 * 0.1745;
|
// double lat = (point_1.lat + point_2.lat) / 2 * 0.1745;
|
||||||
double dx = 111.3 * cos(lat) * (point_1.lon - point_2.lon);
|
// double dx = 111.3 * cos(lat) * (point_1.lon - point_2.lon);
|
||||||
double dy = 111.3 * (point_1.lat - point_2.lat);
|
// double dy = 111.3 * (point_1.lat - point_2.lat);
|
||||||
return sqrt(dx * dx + dy * dy);
|
// return sqrt(dx * dx + dy * dy);
|
||||||
}
|
// }
|
||||||
|
|
||||||
bool Route::nearlySameLocation(Point p1, Point p2) {
|
// bool Route::nearlySameLocation(Point p1, Point p2) {
|
||||||
if (this->getDis(p1, p2) < 0.5)
|
// if (this->getDis(p1, p2) < 0.5)
|
||||||
return true;
|
// return true;
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
Reference in New Issue
Block a user