From b5649216df1d8db550cb3709105598c85dbf280f Mon Sep 17 00:00:00 2001 From: Pascal Serrarens <21057728+passervr@users.noreply.github.com> Date: Tue, 14 Nov 2023 17:15:17 +0100 Subject: [PATCH] Extended DistanceSensor --- DistanceSensor.cpp | 34 ++++++++++++++++++++++++++++++++++ DistanceSensor.h | 40 ++++++++++++++++++++++------------------ VectorAlgebra | 2 +- 3 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 DistanceSensor.cpp diff --git a/DistanceSensor.cpp b/DistanceSensor.cpp new file mode 100644 index 0000000..dacf8cb --- /dev/null +++ b/DistanceSensor.cpp @@ -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; +} diff --git a/DistanceSensor.h b/DistanceSensor.h index b18b30f..8b363a9 100644 --- a/DistanceSensor.h +++ b/DistanceSensor.h @@ -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; }; diff --git a/VectorAlgebra b/VectorAlgebra index bebd097..493a3f7 160000 --- a/VectorAlgebra +++ b/VectorAlgebra @@ -1 +1 @@ -Subproject commit bebd097db3c3f3f311b58257719c80ee10237632 +Subproject commit 493a3f748907b4fb7e64177f94b7cb98a951af4c