clangtidy corrections part 2

This commit is contained in:
2023-10-12 00:44:27 +02:00
parent 23d854a826
commit a43e2db92b
41 changed files with 2274 additions and 2485 deletions
+75 -52
View File
@@ -4,56 +4,72 @@
* @brief Contains the implementation of the class Navigation
* @version 0.1
* @date 2022-01-31
*
*
* @copyright Copyright (c) 2022
*
*
*/
#include "navigation.h"
Navigation::Navigation(const SensorData* sensorData, Route* route) {
this->sensorData = sensorData;
Navigation::Navigation(const SensorData *sensorData, Route *route)
: sensorData{sensorData}
{
this->init(route);
}
void Navigation::init(Route* route) {
if (route)
void Navigation::init(Route *route)
{
if (static_cast<bool>(route))
{
this->route = route;
}
else
{
this->route = new Route();
}
Component::loopDelay = Navigation::loopDelay;
}
Navigation::~Navigation() {
Navigation::~Navigation()
{
delete this->route;
}
void Navigation::run() {}
void Navigation::newRoute() {
if (this->route)
delete this->route;
void Navigation::newRoute()
{
delete this->route;
this->route = new Route();
}
bool Navigation::startNavigation() {
Point newTargetPoint = this->route->startRoute();
bool Navigation::startNavigation()
{
const Point newTargetPoint = this->route->startRoute();
this->navigationStarted = this->setTargetPoint(newTargetPoint);
if (this->navigationStarted)
{
this->navigationFinished = false;
}
return this->navigationStarted;
}
Navigation::Status Navigation::getCourseCorrection(CourseCorrection& correction, bool forceUpdate) {
Navigation::Status Navigation::getCourseCorrection(CourseCorrection &correction, bool forceUpdate)
{
if (this->navigationFinished)
{
return Status::Complete;
}
if (this->currentPosition.getAccuracy() <= this->minAccuracy)
{
return Status::InsufficientAccuracy;
}
if (this->currentPosition.distanceTo(this->lastPointCalcCorrection) < (this->minDistanceToReachPoint / 2.0)
&& !forceUpdate) {
// Check if the Rover has moved, if the Rover hasnt moved this function will be return.
if (this->currentPosition.distanceTo(this->lastPointCalcCorrection) < (this->minDistanceToReachPoint) / 2 && !forceUpdate)
{
correction.correction = this->calculateCourseCorrection(this->lastPointCalcCorrection);
correction.distance = this->lastPointCalcCorrection.distanceTo(this->targetPoint);
return Status::Unchanged;
@@ -62,8 +78,10 @@ Navigation::Status Navigation::getCourseCorrection(CourseCorrection& correction,
double distance = this->currentPosition.distanceTo(this->targetPoint);
// Check if I need a new Point
if (distance < this->minDistanceToReachPoint && this->preventNextPoint == false) {
if (!this->nextPoint()) {
if (distance < this->minDistanceToReachPoint && this->preventNextPoint == false)
{
if (!this->nextPoint())
{
this->navigationFinished = true;
this->navigationStarted = false;
return Status::Complete; // End of navigation
@@ -77,21 +95,25 @@ Navigation::Status Navigation::getCourseCorrection(CourseCorrection& correction,
return Status::Updated;
}
Navigation::Status Navigation::addCurrentPosToRoute() {
Navigation::Status Navigation::addCurrentPosToRoute()
{
if (this->currentPosition.getAccuracy() <= this->minAccuracy)
{
return Status::InsufficientAccuracy;
}
// First Point
if (this->route->getRouteInfo().totalPoints == 0) {
if (this->route->getRouteInfo().totalPoints == 0)
{
this->route->addPointToRoute(this->currentPosition);
this->lastPointRouteInsert = this->currentPosition;
return Status::Updated;
}
// Every Point after the first
double distance = this->currentPosition.distanceTo(this->lastPointRouteInsert);
if (Navigation::minDisBetweenPoints <= distance
&& Navigation::maxDisBetweenPoints >= distance){
const double distance = this->currentPosition.distanceTo(this->lastPointRouteInsert);
if (Navigation::minDisBetweenPoints <= distance && Navigation::maxDisBetweenPoints >= distance)
{
this->route->addPointToRoute(this->currentPosition);
this->lastPointRouteInsert = this->currentPosition;
return Status::Updated;
@@ -99,57 +121,58 @@ Navigation::Status Navigation::addCurrentPosToRoute() {
return Status::Unchanged;
}
// void Navigation::updateCurrentLocation() {
// if (Navigation::ubxUpdateTimeStatic == this->ubxUpdateTime)
// return;
int16_t Navigation::calculateCourseCorrection(Point &point)
{
const int16_t targetCourse = point.courseTo(this->targetPoint);
int16_t correctionCourse = 0;
// this->ubxData = Navigation::ubxDataStatic;
// this->ubxUpdateTime = Navigation::ubxUpdateTimeStatic;
// Point::Coordinates coords;
// coords.lat = this->ubxData->lat / 10000000.0;
// coords.lon = this->ubxData->lon / 10000000.0;
// this->currentPosition = Point(coords, this->ubxData->hAcc);
// }
int16_t Navigation::calculateCourseCorrection(Point& point) {
int16_t targetCourse = point.courseTo(this->targetPoint);
int16_t correctionCourse;
if (this->sensorData->getCalcAzimuthState() == CalcAzimuth::State::Good
|| this->sensorData->getCalcAzimuthState() == CalcAzimuth::State::Super)
if (this->sensorData->getCalcAzimuthState() == CalcAzimuth::State::Good || this->sensorData->getCalcAzimuthState() == CalcAzimuth::State::Super)
{
correctionCourse = targetCourse - this->sensorData->getCalcAzimuth();
this->lastUsedCalcAzimuth = true;
} else {
}
else
{
correctionCourse = targetCourse - this->sensorData->getRealAzimuth();
this->lastUsedCalcAzimuth = false;
}
return Navigation::fixDegree(correctionCourse);
}
bool Navigation::nextPoint() {
bool Navigation::nextPoint()
{
if (!this->navigationStarted)
{
return false;
}
return this->setTargetPoint(this->route->getNextPoint());
}
bool Navigation::setTargetPoint(Point target) {
if (target.isInit()) {
bool Navigation::setTargetPoint(Point target)
{
if (target.isInit())
{
this->targetPoint = target;
return true;
}
return false;
}
int16_t Navigation::fixDegree(int16_t degree) {
while (degree < -180 || degree > 180) {
if (degree > 180)
degree -= 360;
else if (degree < -180)
degree += 360;
int16_t Navigation::fixDegree(int16_t degree)
{
static constexpr uint16_t fullCircle = 360;
while (degree < -fullCircle / 2 || degree > fullCircle / 2)
{
if (degree > fullCircle / 2)
{
degree -= fullCircle;
}
else if (degree < -fullCircle / 2)
{
degree += fullCircle;
}
}
return degree;
}