30 lines
910 B
C++
30 lines
910 B
C++
#pragma once
|
|
|
|
#include "Sensor.h"
|
|
|
|
/// @brief A sensor which can measure the distance the the nearest object
|
|
class DistanceSensor : public Sensor {
|
|
public:
|
|
DistanceSensor() { isDistanceSensor = true; }
|
|
DistanceSensor(float triggerDistance) { isDistanceSensor = true; this->triggerDistance = triggerDistance; }
|
|
/// @brief Determine the distance to the nearest object
|
|
/// @return the measured distance in meters to the nearest object
|
|
virtual float GetDistance() { return distance; };
|
|
virtual void SetDistance(float distance) { this->distance = distance; }; // for simulation purposes
|
|
|
|
/// @brief The distance at which ObjectNearby triggers
|
|
float triggerDistance = 1;
|
|
|
|
bool IsOn() {
|
|
bool isOn = GetDistance() <= triggerDistance;
|
|
return isOn;
|
|
}
|
|
|
|
bool isOff() {
|
|
bool isOff = GetDistance() > triggerDistance;
|
|
return isOff;
|
|
}
|
|
protected:
|
|
float distance = 0;
|
|
};
|