Start with Capture Route
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
#include "coordinate.h"
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
@@ -1,2 +1,29 @@
|
||||
/**
|
||||
* @file navigation.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-31
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "navigation.h"
|
||||
|
||||
Navigation::Navigation(uint8_t rx, uint8_t tx) {
|
||||
this->gps = new TinyGPSPlus();
|
||||
Serial1.begin(9600, SERIAL_8N1, rx, tx);
|
||||
}
|
||||
|
||||
void Navigation::loop() {
|
||||
gps->encode(Serial1.read());
|
||||
}
|
||||
|
||||
void 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,22 +12,22 @@
|
||||
#ifndef NAVIGATION_H
|
||||
#define NAVIGATION_H
|
||||
|
||||
#include <TinyGPS++.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "coordinate.h"
|
||||
|
||||
#include "route.h"
|
||||
class Navigation {
|
||||
public:
|
||||
Navigation(uint32_t baud, uint8_t rx, uint8_t tx);
|
||||
Navigation(uint8_t rx, uint8_t tx);
|
||||
void loop();
|
||||
|
||||
void addCoordinateToRoute(Coordinate coordinate);
|
||||
void addCurrentCoordinateToRoute();
|
||||
void delRoute();
|
||||
void addCurrentPosToRoute();
|
||||
|
||||
double getDistanceToLastCoordinate();
|
||||
TinyGPSPlus* getGPS() { return this->gps; }
|
||||
|
||||
private:
|
||||
Coordinate *lastCoordinate;
|
||||
TinyGPSPlus* gps;
|
||||
Route* route;
|
||||
};
|
||||
|
||||
#endif // NAVIGATION_H
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @file route.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-31
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "route.h"
|
||||
|
||||
Route::Route() {
|
||||
|
||||
}
|
||||
|
||||
void Route::addPointToRoute(Point point) {
|
||||
this->points.push_back(point);
|
||||
}
|
||||
|
||||
Point Route::startRoute() {
|
||||
*this->it = this->points.begin();
|
||||
return **this->it;
|
||||
}
|
||||
|
||||
Point Route::getNextPoint() {
|
||||
if (*this->it != this->points.end())
|
||||
return **this->it;
|
||||
else
|
||||
return Point(0, 0);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file route.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-31
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ROUTE_H
|
||||
#define ROUTE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
|
||||
|
||||
|
||||
|
||||
class Point{
|
||||
public:
|
||||
Point(double lat, double lon) {this->lat = lat; this->lon = lon;}
|
||||
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();
|
||||
void addPointToRoute(Point point);
|
||||
Point startRoute();
|
||||
Point getNextPoint();
|
||||
|
||||
uint16_t getNumberOfPoints() { return this->count_points; }
|
||||
|
||||
private:
|
||||
uint16_t count_points = 0;
|
||||
|
||||
std::list<Point> points;
|
||||
std::list<Point>::iterator* it;
|
||||
|
||||
};
|
||||
|
||||
#endif // ROUTE_H
|
||||
Reference in New Issue
Block a user