Extended DistanceSensor

This commit is contained in:
Pascal Serrarens 2023-11-14 17:15:17 +01:00
parent 46142f6e29
commit b5649216df
3 changed files with 57 additions and 19 deletions

34
DistanceSensor.cpp Normal file
View File

@ -0,0 +1,34 @@
#include "DistanceSensor.h"
DistanceSensor::DistanceSensor()
{
isDistanceSensor = true;
}
DistanceSensor::DistanceSensor(float triggerDistance)
{
isDistanceSensor = true;
this->triggerDistance = triggerDistance;
}
float DistanceSensor::GetDistance()
{
return distance;
};
void DistanceSensor::SetDistance(float distance)
{
this->distance = distance;
}; // for simulation purposes
bool DistanceSensor::IsOn()
{
bool isOn = GetDistance() <= triggerDistance;
return isOn;
}
bool DistanceSensor::isOff()
{
bool isOff = GetDistance() > triggerDistance;
return isOff;
}

View File

@ -3,27 +3,31 @@
#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
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; };
void SetDistance(float distance); // { this->distance = distance; }; // for simulation purposes
/// @brief The distance at which ObjectNearby triggers
float triggerDistance = 1;
/// @brief The distance at which ObjectNearby triggers
float triggerDistance = 1;
bool IsOn() {
bool isOn = GetDistance() <= triggerDistance;
return isOn;
}
bool IsOn();
// {
// bool isOn = GetDistance() <= triggerDistance;
// return isOn;
// }
bool isOff();
// {
// bool isOff = GetDistance() > triggerDistance;
// return isOff;
// }
bool isOff() {
bool isOff = GetDistance() > triggerDistance;
return isOff;
}
protected:
float distance = 0;
};

@ -1 +1 @@
Subproject commit bebd097db3c3f3f311b58257719c80ee10237632
Subproject commit 493a3f748907b4fb7e64177f94b7cb98a951af4c