Finish documention until someone change something
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file navigation.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @brief Contains the implementation of the class Navigation
|
||||
* @version 0.1
|
||||
* @date 2022-01-31
|
||||
*
|
||||
@@ -50,7 +50,7 @@ CourseCorrection Navigation::getCourseCorrection() {
|
||||
|
||||
Point currentPos = this->currentLocation();
|
||||
double targetCourse = Navigation::courseTo(currentPos, this->targetPoint);
|
||||
double distance = Navigation::distanceBetwenn(currentPos, this->targetPoint);
|
||||
double distance = Navigation::distanceBetween(currentPos, this->targetPoint);
|
||||
|
||||
if (targetCourse < 0 || distance < 0 || this->navigationFinished)
|
||||
return courseCorrection;
|
||||
@@ -89,7 +89,7 @@ bool Navigation::addCurrentPosToRoute() {
|
||||
}
|
||||
|
||||
// Ever Point after the first
|
||||
if (MIN_DISTANCE_BETWEEN_POINTS <= this->distanceBetwenn(p, this->lastPoint)) {
|
||||
if (MIN_DISTANCE_BETWEEN_POINTS <= this->distanceBetween(p, this->lastPoint)) {
|
||||
this->route->addPointToRoute(p);
|
||||
this->lastPoint = p;
|
||||
return true;
|
||||
@@ -121,7 +121,7 @@ bool Navigation::setTargetPoint(Point target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double Navigation::distanceBetwenn(Point p1, Point p2) {
|
||||
double Navigation::distanceBetween(Point p1, Point p2) {
|
||||
if (p1.isValid() && p2.isValid())
|
||||
return TinyGPSPlus::distanceBetween(p1.lat, p1.lon, p2.lat, p2.lon);
|
||||
return -1;
|
||||
|
||||
+123
-3
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file navigation.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @brief Contains a class which navigate an object by the given route
|
||||
* @version 0.1
|
||||
* @date 2022-01-10
|
||||
*
|
||||
@@ -18,33 +18,153 @@
|
||||
|
||||
#include "route.h"
|
||||
|
||||
/**
|
||||
* @brief The minimal distance between Points
|
||||
*
|
||||
* This is a very critical option. It have to be
|
||||
* around the half accuracy of the positioning system
|
||||
*
|
||||
*/
|
||||
#define MIN_DISTANCE_BETWEEN_POINTS 1
|
||||
|
||||
/**
|
||||
* @brief This struct inherits the result of the navigation
|
||||
*
|
||||
* The drive get objects of this struct and should
|
||||
* correct the direction in dependency on this.
|
||||
*
|
||||
*/
|
||||
struct CourseCorrection {
|
||||
int16_t correction;
|
||||
double distance;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This class navigate an object
|
||||
*
|
||||
* The class use the given Route and the gps device
|
||||
* to tell the driver in which direction he have to
|
||||
* be drive and the distance to the next checkpoint.
|
||||
*
|
||||
*/
|
||||
class Navigation {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Navigation object
|
||||
*
|
||||
* @param rx pin to the gps device
|
||||
* @param tx pin to the gps device
|
||||
* @param route with which to navigate
|
||||
*/
|
||||
Navigation(uint8_t rx, uint8_t tx, Route* route = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Destroy the Navigation object
|
||||
*
|
||||
*/
|
||||
~Navigation();
|
||||
|
||||
/**
|
||||
* @brief Decodes new GPS information
|
||||
*
|
||||
* Should be called ever main loop.
|
||||
*/
|
||||
void loop();
|
||||
|
||||
/**
|
||||
* @brief creates a new empty route
|
||||
*
|
||||
*/
|
||||
void newRoute();
|
||||
|
||||
/**
|
||||
* @brief Tries to start the route
|
||||
*
|
||||
* For example the route can not be started
|
||||
* if there are no Points or wrong Points.
|
||||
*
|
||||
* @return true route is started
|
||||
* @return false route can not be started
|
||||
*/
|
||||
bool startNavigation();
|
||||
|
||||
/**
|
||||
* @brief Get the Course Correction object
|
||||
*
|
||||
* This should be called by the driver to get new instructions.
|
||||
*
|
||||
* @return CourseCorrection
|
||||
*/
|
||||
CourseCorrection getCourseCorrection();
|
||||
|
||||
/**
|
||||
* @brief Tries to add the current Position to the route
|
||||
*
|
||||
* This can be go wrong if there is no valid GPS signal
|
||||
*
|
||||
* @return true successful added point
|
||||
* @return false no point added to route
|
||||
*/
|
||||
bool addCurrentPosToRoute();
|
||||
|
||||
/**
|
||||
* @brief Returns the GPS object
|
||||
*
|
||||
* @return TinyGPSPlus*
|
||||
*/
|
||||
TinyGPSPlus* getGPS() { return this->gps; }
|
||||
|
||||
/**
|
||||
* @brief Get the Route Info object
|
||||
*
|
||||
* This object contains information about the route.
|
||||
* For example the stored points.
|
||||
*
|
||||
* @return RouteInfo
|
||||
*/
|
||||
RouteInfo getRouteInfo() const { return this->route->getRouteInfo(); }
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Returns the current Location
|
||||
*
|
||||
* @return Point
|
||||
*/
|
||||
Point currentLocation();
|
||||
|
||||
/**
|
||||
* @brief Set the next point as target
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool nextPoint();
|
||||
|
||||
/**
|
||||
* @brief Set the target point
|
||||
*
|
||||
* @param target
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool setTargetPoint(Point target);
|
||||
static double distanceBetwenn(Point p1, Point p2);
|
||||
|
||||
/**
|
||||
* @brief Calculate the distance between to points
|
||||
*
|
||||
* @param p1 point 1
|
||||
* @param p2 point 2
|
||||
* @return double distance in meter
|
||||
*/
|
||||
static double distanceBetween(Point p1, Point p2);
|
||||
|
||||
/**
|
||||
* @brief Calculates the course from point1 to point2
|
||||
*
|
||||
* @param p1 point 1
|
||||
* @param p2 point 2
|
||||
* @return double degree north = 0° west = 270°
|
||||
*/
|
||||
static double courseTo(Point p1, Point p2);
|
||||
|
||||
TinyGPSPlus* gps;
|
||||
@@ -57,4 +177,4 @@ class Navigation {
|
||||
bool navigationFinished = false;
|
||||
};
|
||||
|
||||
#endif // NAVIGATION_H
|
||||
#endif // NAVIGATION_H
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file route.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @brief Implements the class Route
|
||||
* @version 0.1
|
||||
* @date 2022-01-31
|
||||
*
|
||||
@@ -11,9 +11,6 @@
|
||||
|
||||
#include "route.h"
|
||||
|
||||
// TODO: Delete iostream
|
||||
#include <iostream>
|
||||
|
||||
Route::Route() {
|
||||
|
||||
}
|
||||
|
||||
+68
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file route.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @brief Contains a class which hold multiple Points
|
||||
* @version 0.1
|
||||
* @date 2022-01-31
|
||||
*
|
||||
@@ -16,33 +16,100 @@
|
||||
#include <list>
|
||||
|
||||
|
||||
/**
|
||||
* @brief A to handle points on the earth
|
||||
*
|
||||
* The points inherits latidue and longitude as doubles
|
||||
*
|
||||
*/
|
||||
class Point{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Point object
|
||||
*
|
||||
* @param lat latidude
|
||||
* @param lon longitude
|
||||
*/
|
||||
Point(double lat, double lon) { this->lat = lat; this->lon = lon; }
|
||||
Point(){ this->lat = 0; this->lon = 0; }
|
||||
|
||||
double lat = 0;
|
||||
double lon = 0;
|
||||
|
||||
/**
|
||||
* @brief checks if to points are equal
|
||||
*
|
||||
* @param rhs
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool operator==(const Point& rhs) const {
|
||||
return this->lat == rhs.lat && this->lon == rhs.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the Point is valid
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool isValid() const { return this->lat + this->lon; }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Holds some route information
|
||||
*
|
||||
*/
|
||||
struct RouteInfo{
|
||||
/**
|
||||
* @brief Selected number of Points
|
||||
*/
|
||||
uint16_t currentPoint;
|
||||
|
||||
/**
|
||||
* @brief Total points stored in route
|
||||
*/
|
||||
uint16_t totalPoints;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A class to manage multiple points
|
||||
*
|
||||
* The list of point presents a route which can be driven
|
||||
*/
|
||||
class Route {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Route object
|
||||
*/
|
||||
Route();
|
||||
|
||||
/**
|
||||
* @brief Adds a point to the list
|
||||
*
|
||||
* @param point
|
||||
*/
|
||||
void addPointToRoute(Point point);
|
||||
|
||||
/**
|
||||
* @brief Select the first point as target
|
||||
*
|
||||
* @return Point
|
||||
*/
|
||||
Point startRoute();
|
||||
|
||||
/**
|
||||
* @brief Get the next point and set it as target
|
||||
*
|
||||
* @return Point is zero if there are no more Points
|
||||
*/
|
||||
Point getNextPoint();
|
||||
|
||||
/**
|
||||
* @brief Get the Route Info object
|
||||
*
|
||||
* @return RouteInfo
|
||||
*/
|
||||
RouteInfo getRouteInfo();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user