diff --git a/doc/PinBelegungen.txt b/doc/PinBelegungen.txt index 7d5b2b0..8d92a95 100644 --- a/doc/PinBelegungen.txt +++ b/doc/PinBelegungen.txt @@ -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 diff --git a/include/route.h b/include/route.h index 95481e3..29f90ac 100644 --- a/include/route.h +++ b/include/route.h @@ -1,58 +1,53 @@ -#ifndef ROUTE_H -#define ROUTE_H +// #ifndef ROUTE_H +// #define ROUTE_H -#include -#include -#include -#include +// #include +// #include +// #include +// #include -#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 points; - std::list::iterator it; - Point currentLocation; +// std::list points; +// std::list::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 \ No newline at end of file +// #endif // ROUTE_H \ No newline at end of file diff --git a/lib/Navigation/coordinate.cpp b/lib/Navigation/coordinate.cpp new file mode 100644 index 0000000..13051f3 --- /dev/null +++ b/lib/Navigation/coordinate.cpp @@ -0,0 +1,2 @@ +#include "coordinate.h" + diff --git a/lib/Navigation/coordinate.h b/lib/Navigation/coordinate.h new file mode 100644 index 0000000..683707b --- /dev/null +++ b/lib/Navigation/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 + +class Coordinate { + public: + Coordinate(/* args */); + ~Coordinate(); + + double getDistance(Coordinate coordinate); + uint16_t getCompassDirection(Coordinate coordinate); + + private: + double lon; + double lat; +}; + + +#endif // COORDINATE_H \ No newline at end of file diff --git a/lib/Navigation/navigation.cpp b/lib/Navigation/navigation.cpp new file mode 100644 index 0000000..a352ad6 --- /dev/null +++ b/lib/Navigation/navigation.cpp @@ -0,0 +1,2 @@ +#include "navigation.h" + diff --git a/lib/Navigation/navigation.h b/lib/Navigation/navigation.h new file mode 100644 index 0000000..68a36b8 --- /dev/null +++ b/lib/Navigation/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 + +#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 \ No newline at end of file diff --git a/src/driveModi/Modi/Autopilot/autopilot.cpp b/src/driveModi/Modi/Autopilot/autopilot.cpp index 4f3da91..55746fd 100644 --- a/src/driveModi/Modi/Autopilot/autopilot.cpp +++ b/src/driveModi/Modi/Autopilot/autopilot.cpp @@ -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() { diff --git a/src/driveModi/Modi/Autopilot/autopilot.h b/src/driveModi/Modi/Autopilot/autopilot.h index 14bde29..f1f0b3c 100644 --- a/src/driveModi/Modi/Autopilot/autopilot.h +++ b/src/driveModi/Modi/Autopilot/autopilot.h @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 0da9e0a..7a407b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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() { diff --git a/src/route.cpp b/src/route.cpp index 4e57246..7516c42 100644 --- a/src/route.cpp +++ b/src/route.cpp @@ -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; -} \ No newline at end of file +// bool Route::nearlySameLocation(Point p1, Point p2) { +// if (this->getDis(p1, p2) < 0.5) +// return true; +// return false; +// } \ No newline at end of file