From 8e7be85ac69ced926d2b144d43d0248579131d75 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sun, 31 Dec 2023 09:52:51 +0100 Subject: [PATCH] Generic Network sync --- NetworkSync.h | 22 ++++++++++++++++++++++ Perception.cpp | 37 +------------------------------------ Roboid.cpp | 2 +- Roboid.h | 4 ++-- 4 files changed, 26 insertions(+), 39 deletions(-) create mode 100644 NetworkSync.h diff --git a/NetworkSync.h b/NetworkSync.h new file mode 100644 index 0000000..6f6e3a3 --- /dev/null +++ b/NetworkSync.h @@ -0,0 +1,22 @@ +#pragma once + +#include "Perception.h" +#include "Roboid.h" + +namespace Passer { +namespace RoboidControl { + +class NetworkSync { +public: + virtual void NetworkUpdate(Roboid *roboid) = 0; + virtual void DestroyObject(PerceivedObject *obj) = 0; + + static const char PoseMsg = 0x10; + static const char Pose_Position = 0x01; + static const char Pose_Orientation = 0x02; + static const char Pose_LinearVelocity = 0x04; + static const char Pose_AngularVelocity = 0x08; +}; + +} // namespace RoboidControl +} // namespace Passer \ No newline at end of file diff --git a/Perception.cpp b/Perception.cpp index 999e64b..6ac70a4 100644 --- a/Perception.cpp +++ b/Perception.cpp @@ -1,7 +1,7 @@ #include "Perception.h" #include "Angle.h" #include "DistanceSensor.h" -#include "RoboidWiFi.h" +#include "NetworkSync.h" #include "Switch.h" #include @@ -46,23 +46,6 @@ float Perception::GetDistance(float direction, float range) { if (range < 0) range = -range; - // for (unsigned int sensorIx = 0; sensorIx < this->sensorCount; sensorIx++) { - // Placement placement = sensorPlacements[sensorIx]; - // // This still needs support for angles wrapping around 180 degrees !!!! - // if (placement.horizontalDirection > direction - range && - // placement.horizontalDirection < direction + range) { - // Thing *thing = placement.thing; - // if (thing == nullptr) - // continue; - - // if (thing->type == Thing::DistanceSensorType) { - // DistanceSensor *distanceSensor = (DistanceSensor *)thing; - // if (distanceSensor != nullptr && distanceSensor->ObjectNearby()) - // minDistance = fmin(minDistance, distanceSensor->GetDistance()); - // } - // } - // } - for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) { PerceivedObject *obj = perceivedObjects[objIx]; if (obj == nullptr) @@ -82,24 +65,6 @@ float Perception::GetDistance(float horizontalDirection, if (range < 0) range = -range; - // for (unsigned int sensorIx = 0; sensorIx < this->sensorCount; sensorIx++) { - // Placement placement = sensorPlacements[sensorIx]; - // // This still needs support for angles wrapping around 180 degrees !!!! - // if (placement.horizontalDirection > horizontalDirection - range && - // placement.horizontalDirection < horizontalDirection + range && - // placement.verticalDirection > verticalDirection - range && - // placement.verticalDirection < verticalDirection + range) { - // Thing *thing = placement.thing; - // if (thing == nullptr) - // continue; - - // if (thing->type == Thing::DistanceSensorType) { - // DistanceSensor *distanceSensor = (DistanceSensor *)thing; - // if (distanceSensor != nullptr && distanceSensor->ObjectNearby()) - // minDistance = fmin(minDistance, distanceSensor->GetDistance()); - // } - // } - // } for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) { PerceivedObject *obj = perceivedObjects[objIx]; if (obj == nullptr) diff --git a/Roboid.cpp b/Roboid.cpp index ace1ed7..6da0535 100644 --- a/Roboid.cpp +++ b/Roboid.cpp @@ -1,6 +1,6 @@ #include "Roboid.h" -#include "RoboidWiFi.h" +#include "NetworkSync.h" Roboid::Roboid() {} diff --git a/Roboid.h b/Roboid.h index 99eef4e..063c3ad 100644 --- a/Roboid.h +++ b/Roboid.h @@ -6,7 +6,7 @@ namespace Passer { namespace RoboidControl { -class RoboidWiFi; +class NetworkSync; /// @brief A Roboid is used to control autonomous robots class Roboid { @@ -28,7 +28,7 @@ public: /// @brief The Propulsion module of this Roboid Propulsion *propulsion; - RoboidWiFi *networkSync = nullptr; + NetworkSync *networkSync = nullptr; }; } // namespace RoboidControl