diff --git a/Arduino/Things/DigitalInput.cpp b/Arduino/Things/DigitalInput.cpp index 4f379cd..e65aa1e 100644 --- a/Arduino/Things/DigitalInput.cpp +++ b/Arduino/Things/DigitalInput.cpp @@ -29,7 +29,7 @@ DigitalInput::TouchSensor::TouchSensor(unsigned char pin, Thing* parent) : RoboidControl::TouchSensor(parent), digitalInput(pin, parent) {} void DigitalInput::TouchSensor::Update(bool recursive) { - this->touchedSomething = digitalInput.isLow; + this->internalTouch = digitalInput.isLow; } #pragma endregion Touch sensor @@ -98,8 +98,8 @@ void DigitalInput::RelativeEncoder::Update(bool recursive) { this->pulseFrequency = pulseCount / timeStep; this->rotationSpeed = pulseFrequency / pulsesPerRevolution; - std::cout << "pulses: " << pulseCount << " per second " << pulseFrequency - << " timestep " << timeStep << std::endl; + // std::cout << "pulses: " << pulseCount << " per second " << pulseFrequency + // << " timestep " << timeStep << std::endl; this->lastUpdateTime = currentTimeMs; } diff --git a/Arduino/Things/UltrasonicSensor.cpp b/Arduino/Things/UltrasonicSensor.cpp index 1ec4db5..338353e 100644 --- a/Arduino/Things/UltrasonicSensor.cpp +++ b/Arduino/Things/UltrasonicSensor.cpp @@ -65,7 +65,7 @@ UltrasonicSensor::TouchSensor::TouchSensor(Configuration config, Thing* parent) void UltrasonicSensor::TouchSensor::Update(bool recursive) { RoboidControl::TouchSensor::Update(recursive); this->ultrasonic.Update(false); - this->touchedSomething |= (this->ultrasonic.distance > 0 && + this->internalTouch |= (this->ultrasonic.distance > 0 && this->ultrasonic.distance <= this->touchDistance); } diff --git a/Things/TouchSensor.cpp b/Things/TouchSensor.cpp index 85d9bbe..9d347db 100644 --- a/Things/TouchSensor.cpp +++ b/Things/TouchSensor.cpp @@ -7,8 +7,12 @@ TouchSensor::TouchSensor(Thing* parent) : Thing(parent) { this->name = "Touch sensor"; } +bool TouchSensor::IsTouching() { + return this->internalTouch || this->externalTouch; +} + void TouchSensor::PrepareForUpdate() { - this->touchedSomething = this->externalTouch; + //this->internalTouch = this->externalTouch; } void TouchSensor::Update(bool recursive) { @@ -16,7 +20,8 @@ void TouchSensor::Update(bool recursive) { } int TouchSensor::GenerateBinary(char* bytes, unsigned char* ix) { - bytes[(*ix)++] = this->touchedSomething ? 1 : 0; + std::cout << "BinaryMsg Touch " << this->internalTouch << std::endl; + bytes[(*ix)++] = this->internalTouch ? 1 : 0; return 1; } diff --git a/Things/TouchSensor.h b/Things/TouchSensor.h index cd7bd73..e8eb2bc 100644 --- a/Things/TouchSensor.h +++ b/Things/TouchSensor.h @@ -16,7 +16,7 @@ class TouchSensor : public Thing { /// @brief Value which is true when the sensor is touching something, false /// otherwise - bool touchedSomething = false; + bool IsTouching(); virtual void PrepareForUpdate() override; virtual void Update(bool recursive) override; @@ -30,6 +30,7 @@ class TouchSensor : public Thing { virtual void ProcessBinary(char* bytes) override; protected: bool externalTouch = false; + bool internalTouch = false; }; } // namespace RoboidControl diff --git a/examples/BB2B.cpp b/examples/BB2B.cpp index b1ab231..8a51d01 100644 --- a/examples/BB2B.cpp +++ b/examples/BB2B.cpp @@ -27,10 +27,10 @@ int main() { while (true) { // The left wheel turns forward when nothing is touched on the right side // and turn backward when the roboid hits something on the right - float leftWheelSpeed = (touchRight.touchedSomething) ? -600.0f : 600.0f; + float leftWheelSpeed = (touchRight.internalTouch) ? -600.0f : 600.0f; // The right wheel does the same, but instead is controlled by // touches on the left side - float rightWheelSpeed = (touchLeft.touchedSomething) ? -600.0f : 600.0f; + float rightWheelSpeed = (touchLeft.internalTouch) ? -600.0f : 600.0f; // When both sides are touching something, both wheels will turn backward // and the roboid will move backwards bb2b.SetWheelVelocity(leftWheelSpeed, rightWheelSpeed);