Extended DistanceSensor
This commit is contained in:
parent
46142f6e29
commit
b5649216df
34
DistanceSensor.cpp
Normal file
34
DistanceSensor.cpp
Normal 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;
|
||||||
|
}
|
@ -3,27 +3,31 @@
|
|||||||
#include "Sensor.h"
|
#include "Sensor.h"
|
||||||
|
|
||||||
/// @brief A sensor which can measure the distance the the nearest object
|
/// @brief A sensor which can measure the distance the the nearest object
|
||||||
class DistanceSensor : public Sensor {
|
class DistanceSensor : public Sensor
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
DistanceSensor() { isDistanceSensor = true; }
|
DistanceSensor(); // { isDistanceSensor = true; }
|
||||||
DistanceSensor(float triggerDistance) { isDistanceSensor = true; this->triggerDistance = triggerDistance; }
|
DistanceSensor(float triggerDistance); // { isDistanceSensor = true; this->triggerDistance = triggerDistance; }
|
||||||
/// @brief Determine the distance to the nearest object
|
/// @brief Determine the distance to the nearest object
|
||||||
/// @return the measured distance in meters to the nearest object
|
/// @return the measured distance in meters to the nearest object
|
||||||
virtual float GetDistance() { return distance; };
|
virtual float GetDistance(); // { return distance; };
|
||||||
virtual void SetDistance(float distance) { this->distance = distance; }; // for simulation purposes
|
void SetDistance(float distance); // { this->distance = distance; }; // for simulation purposes
|
||||||
|
|
||||||
/// @brief The distance at which ObjectNearby triggers
|
/// @brief The distance at which ObjectNearby triggers
|
||||||
float triggerDistance = 1;
|
float triggerDistance = 1;
|
||||||
|
|
||||||
bool IsOn() {
|
bool IsOn();
|
||||||
bool isOn = GetDistance() <= triggerDistance;
|
// {
|
||||||
return isOn;
|
// bool isOn = GetDistance() <= triggerDistance;
|
||||||
}
|
// return isOn;
|
||||||
|
// }
|
||||||
|
|
||||||
|
bool isOff();
|
||||||
|
// {
|
||||||
|
// bool isOff = GetDistance() > triggerDistance;
|
||||||
|
// return isOff;
|
||||||
|
// }
|
||||||
|
|
||||||
bool isOff() {
|
|
||||||
bool isOff = GetDistance() > triggerDistance;
|
|
||||||
return isOff;
|
|
||||||
}
|
|
||||||
protected:
|
protected:
|
||||||
float distance = 0;
|
float distance = 0;
|
||||||
};
|
};
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit bebd097db3c3f3f311b58257719c80ee10237632
|
Subproject commit 493a3f748907b4fb7e64177f94b7cb98a951af4c
|
Loading…
x
Reference in New Issue
Block a user