added more functions for capture route
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
void Navigation::loop() {
|
||||
gps->encode(Serial1.read());
|
||||
Navigation::~Navigation() {
|
||||
delete this->gps;
|
||||
}
|
||||
|
||||
void Navigation::addCurrentPosToRoute() {
|
||||
void Navigation::loop() {
|
||||
while (Serial1.available())
|
||||
gps->encode(Serial1.read());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -15,17 +15,20 @@
|
||||
#include <cstdint>
|
||||
#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 {
|
||||
|
||||
Reference in New Issue
Block a user