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"
|
||||
|
||||
/// @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
|
Loading…
x
Reference in New Issue
Block a user