clangtidy corrections part 1
This commit is contained in:
@@ -1,114 +1,121 @@
|
||||
/**
|
||||
* @file calcAzimuth.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-09-03
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "calcAzimuth.h"
|
||||
|
||||
CalcAzimuth::CalcAzimuth(Point point) {
|
||||
this->lastChangePoint = point;
|
||||
this->currentPosition = point;
|
||||
this->loopDelay = 50;
|
||||
CalcAzimuth::CalcAzimuth(Point point)
|
||||
: lastChangePoint{point}, currentPosition{point}
|
||||
{
|
||||
Component::loopDelay = CalcAzimuth::loopDelay;
|
||||
}
|
||||
|
||||
void CalcAzimuth::drivingDirectionChange(Point point) {
|
||||
if (point.isInit() && point.isValid()) {
|
||||
void CalcAzimuth::drivingDirectionChange(Point point)
|
||||
{
|
||||
if (point.isInit() && point.isValid())
|
||||
{
|
||||
this->directionChangeMode = true;
|
||||
this->lastChangePoint = point;
|
||||
this->state = State::Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
void CalcAzimuth::updateCurrentPosition(Point point) {
|
||||
void CalcAzimuth::updateCurrentPosition(Point point)
|
||||
{
|
||||
this->currentPosition = point;
|
||||
this->positionChanged = true;
|
||||
}
|
||||
|
||||
String CalcAzimuth::stateToString(State state) {
|
||||
switch (state) {
|
||||
case State::Invalid:
|
||||
return "Invalid";
|
||||
String CalcAzimuth::stateToString(State state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case State::Invalid:
|
||||
return "Invalid";
|
||||
|
||||
case State::Bad:
|
||||
return "Bad";
|
||||
case State::Bad:
|
||||
return "Bad";
|
||||
|
||||
case State::Ok:
|
||||
return "Ok";
|
||||
case State::Ok:
|
||||
return "Ok";
|
||||
|
||||
case State::Good:
|
||||
return "Good";
|
||||
case State::Good:
|
||||
return "Good";
|
||||
|
||||
case State::Super:
|
||||
return "Super";
|
||||
|
||||
default:
|
||||
return "UNKOWN";
|
||||
case State::Super:
|
||||
return "Super";
|
||||
|
||||
default:
|
||||
return "UNKOWN";
|
||||
}
|
||||
}
|
||||
|
||||
void CalcAzimuth::run() {
|
||||
void CalcAzimuth::run()
|
||||
{
|
||||
if (!this->positionChanged)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->positionChanged = false;
|
||||
this->updateAzimuth();
|
||||
}
|
||||
|
||||
void CalcAzimuth::updateAzimuth() {
|
||||
if (!this->directionChangeMode
|
||||
|| this->lastChangePoint.distanceTo(this->currentPosition) < 1.0)
|
||||
void CalcAzimuth::updateAzimuth()
|
||||
{
|
||||
if (!this->directionChangeMode || this->lastChangePoint.distanceTo(this->currentPosition) < 1.0)
|
||||
{
|
||||
this->state = State::Invalid;
|
||||
this->calcAzimuth = 999;
|
||||
this->calcAzimuth = INT16_MIN;
|
||||
return;
|
||||
}
|
||||
|
||||
this->calcAzimuth = this->lastChangePoint.courseTo(this->currentPosition);
|
||||
|
||||
// Map point accuracy to State
|
||||
if (this->lastChangePoint.getAccuracy() == Point::Accuracy::oneDigOfCM
|
||||
|| this->currentPosition.getAccuracy() == Point::Accuracy::oneDigOfCM)
|
||||
if (this->lastChangePoint.getAccuracy() == Point::Accuracy::oneDigOfCM || this->currentPosition.getAccuracy() == Point::Accuracy::oneDigOfCM)
|
||||
{
|
||||
this->state = State::Good;
|
||||
}
|
||||
else if (this->lastChangePoint.getAccuracy() == Point::Accuracy::twoDigOfCM
|
||||
|| this->currentPosition.getAccuracy() == Point::Accuracy::twoDigOfCM)
|
||||
}
|
||||
else if (this->lastChangePoint.getAccuracy() == Point::Accuracy::twoDigOfCM || this->currentPosition.getAccuracy() == Point::Accuracy::twoDigOfCM)
|
||||
{
|
||||
this->state = State::Ok;
|
||||
}
|
||||
else if (this->lastChangePoint.getAccuracy() == Point::Accuracy::threeDigOfCM
|
||||
|| this->currentPosition.getAccuracy() == Point::Accuracy::threeDigOfCM)
|
||||
}
|
||||
else if (this->lastChangePoint.getAccuracy() == Point::Accuracy::threeDigOfCM || this->currentPosition.getAccuracy() == Point::Accuracy::threeDigOfCM)
|
||||
{
|
||||
this->state = State::Bad;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
this->state = State::Invalid;
|
||||
}
|
||||
|
||||
// Upgrade quality if the range grows up
|
||||
if (this->lastChangePoint.distanceTo(this->currentPosition) > 2.0) {
|
||||
switch (this->state) {
|
||||
case State::Bad :
|
||||
this->state = State::Ok;
|
||||
break;
|
||||
|
||||
case State::Ok :
|
||||
this->state = State::Good;
|
||||
break;
|
||||
if (this->lastChangePoint.distanceTo(this->currentPosition) > this->minDistanceForBetterQuality)
|
||||
{
|
||||
switch (this->state)
|
||||
{
|
||||
case State::Bad:
|
||||
this->state = State::Ok;
|
||||
break;
|
||||
|
||||
case State::Good :
|
||||
this->state = State::Super;
|
||||
break;
|
||||
case State::Ok:
|
||||
this->state = State::Good;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
case State::Good:
|
||||
this->state = State::Super;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* @file calcAzimuth.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-09-03
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CALC_AZIMUTH_H
|
||||
@@ -15,38 +15,43 @@
|
||||
#include "component.h"
|
||||
#include "point.h"
|
||||
|
||||
class CalcAzimuth : public Component {
|
||||
public:
|
||||
enum State {
|
||||
Invalid,
|
||||
Bad,
|
||||
Ok,
|
||||
Good,
|
||||
Super
|
||||
};
|
||||
class CalcAzimuth : public Component
|
||||
{
|
||||
public:
|
||||
enum State
|
||||
{
|
||||
Invalid,
|
||||
Bad,
|
||||
Ok,
|
||||
Good,
|
||||
Super
|
||||
};
|
||||
|
||||
CalcAzimuth(Point point);
|
||||
CalcAzimuth(Point point);
|
||||
|
||||
void drivingDirectionChange(Point point);
|
||||
void updateCurrentPosition(Point point);
|
||||
void disableCalcAzimuth() { this->directionChangeMode = false; }
|
||||
void drivingDirectionChange(Point point);
|
||||
void updateCurrentPosition(Point point);
|
||||
void disableCalcAzimuth() { this->directionChangeMode = false; }
|
||||
|
||||
int16_t getAzimuth() const { return this->calcAzimuth; }
|
||||
State getState() const { return this->state; }
|
||||
int16_t getAzimuth() const { return this->calcAzimuth; }
|
||||
State getState() const { return this->state; }
|
||||
|
||||
static String stateToString(State state);
|
||||
static String stateToString(State state);
|
||||
|
||||
private:
|
||||
void run() override;
|
||||
void updateAzimuth();
|
||||
private:
|
||||
void run() override;
|
||||
void updateAzimuth();
|
||||
|
||||
State state = State::Invalid;
|
||||
Point lastChangePoint;
|
||||
Point currentPosition;
|
||||
State state = State::Invalid;
|
||||
Point lastChangePoint;
|
||||
Point currentPosition;
|
||||
|
||||
bool positionChanged = false;
|
||||
bool directionChangeMode = false;
|
||||
int16_t calcAzimuth = INT16_MAX;
|
||||
bool positionChanged = false;
|
||||
bool directionChangeMode = false;
|
||||
int16_t calcAzimuth = INT16_MAX;
|
||||
double minDistanceForBetterQuality = 2;
|
||||
|
||||
static constexpr uint8_t loopDelay = 50;
|
||||
};
|
||||
|
||||
#endif //CALC_AZIMUTH_H
|
||||
#endif // CALC_AZIMUTH_H
|
||||
|
||||
Reference in New Issue
Block a user