RoboidControl-cpp/DistanceSensor.cpp
Pascal Serrarens 047f1dac29 Extended tests
2024-01-17 11:20:39 +01:00

29 lines
624 B
C++

#include "DistanceSensor.h"
#include <math.h>
DistanceSensor::DistanceSensor() {
this->type = Thing::DistanceSensorType;
this->distance = INFINITY;
this->triggerDistance = 1.0F;
}
DistanceSensor::DistanceSensor(float triggerDistance) : DistanceSensor() {
this->triggerDistance = triggerDistance;
}
float DistanceSensor::GetDistance() {
if (distance < minRange || distance > maxRange)
return -1; // invalid distance
return distance;
};
bool DistanceSensor::ObjectNearby() {
if (distance < minRange || distance > maxRange)
return false;
bool isOn = distance <= triggerDistance;
return isOn;
}