RoboidControl-cpp/TrackedObject.cpp
2024-01-02 11:52:02 +01:00

43 lines
1.0 KiB
C++

#include "TrackedObject.h"
#include <math.h>
TrackedObject::TrackedObject(Sensor *sensor, Polar position) {
this->id = 0;
this->confidence = maxConfidence;
this->sensor = sensor;
this->position = position;
}
bool TrackedObject::IsTheSameAs(TrackedObject *otherObj) {
if (id != 0 && id == otherObj->id)
return true;
if (fabsf(position.distance - otherObj->position.distance) > equalityDistance)
return false;
if (fabsf(position.angle - otherObj->position.angle) > equalityAngle)
return false;
return true;
}
bool TrackedObject::DegradeConfidence(float deltaTime) {
unsigned char confidenceDrop =
(unsigned char)((float)confidenceDropSpeed * deltaTime);
// Make sure the confidence always drops
if (confidenceDrop == 0)
confidenceDrop = 1;
if (confidence <= confidenceDrop) {
// object is dead
confidence = 0;
return false;
} else {
confidence -= confidenceDrop;
return true;
}
}
void TrackedObject::Refresh(Polar position) {
this->position = position;
this->confidence = maxConfidence;
}