From c51f3387c35771e9f308f913cc36dda579e21516 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 20 Jun 2024 06:37:41 -0400 Subject: [PATCH] Added methods for coverting classification to string and passing sensorId and projString from configuration --- src/tmx/Messages/include/SensorDetectedObject.h | 1 + .../MUSTSensorDriverPlugin/src/MUSTSensorDetection.cpp | 5 ++++- .../MUSTSensorDriverPlugin/src/MUSTSensorDetection.h | 2 +- .../MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.cpp | 5 ++++- .../MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.h | 4 ++++ .../test/TestMUSTSensorDetection.cpp | 8 ++++++-- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/tmx/Messages/include/SensorDetectedObject.h b/src/tmx/Messages/include/SensorDetectedObject.h index 4df3b3ca6..b87d55543 100644 --- a/src/tmx/Messages/include/SensorDetectedObject.h +++ b/src/tmx/Messages/include/SensorDetectedObject.h @@ -36,6 +36,7 @@ namespace tmx tmx::utils::Point position = tmx::utils::Point(); tmx::utils::Vector3d velocity = tmx::utils::Vector3d(); long timestamp = 0; + }; } diff --git a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.cpp b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.cpp index 77bbe9e1b..07f45ae7b 100644 --- a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.cpp +++ b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.cpp @@ -29,7 +29,7 @@ namespace MUSTSensorDriverPlugin { return detection; } - tmx::messages::SensorDetectedObject mustDectionToSensorDetectedObject(const MUSTSensorDetection &detection) { + tmx::messages::SensorDetectedObject mustDetectionToSensorDetectedObject(const MUSTSensorDetection &detection, const std::string &sensorId, const std::string &projString) { tmx::messages::SensorDetectedObject detectedObject; detectedObject.objectId = detection.trackID; detectedObject.position.X = detection.position_x; @@ -37,6 +37,9 @@ namespace MUSTSensorDriverPlugin { detectedObject.confidence = detection.confidence; detectedObject.timestamp = detection.timestamp; detectedObject.velocity = headingSpeedToVelocity(detection.heading, detection.speed); + detectedObject.type = detectionClassificationToString(detection.cl); + detectedObject.sensorId = sensorId; + detectedObject.projString = projString; return detectedObject; } DetectionClassification fromStringToDetectionClassification(const std::string &str) noexcept { diff --git a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.h b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.h index ddcaa0f32..c5fb00749 100644 --- a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.h +++ b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.h @@ -59,7 +59,7 @@ namespace MUSTSensorDriverPlugin { MUSTSensorDetection csvToDectection(const std::string &csv ); - tmx::messages::SensorDetectedObject mustDectionToSensorDetectedObject(const MUSTSensorDetection &detection); + tmx::messages::SensorDetectedObject mustDetectionToSensorDetectedObject(const MUSTSensorDetection &detection, const std::string &sensorId, const std::string &projString); tmx::utils::Vector3d headingSpeedToVelocity(double heading, double speed); } \ No newline at end of file diff --git a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.cpp b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.cpp index 6a5fe15eb..8e51474ca 100644 --- a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.cpp +++ b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.cpp @@ -36,6 +36,9 @@ namespace MUSTSensorDriverPlugin { // (e.g. using std::atomic, std::mutex, etc.). if (this->IsPluginState(IvpPluginState_registered)) { std::scoped_lock lock(_configMutex); + GetConfigValue("ProjectionString", projString); + GetConfigValue("SensorId", sensorId); + // Setup UDP Server std::string ip_address; unsigned int port; GetConfigValue("DetectionReceiverIP", ip_address); @@ -51,7 +54,7 @@ namespace MUSTSensorDriverPlugin { void MUSTSensorDriverPlugin::processMUSTSensorDetection(){ if (mustSensorPacketReceiver) { MUSTSensorDetection detection = csvToDectection(mustSensorPacketReceiver->stringTimedReceive()); - tmx::messages::SensorDetectedObject msg = mustDectionToSensorDetectedObject(detection); + tmx::messages::SensorDetectedObject msg = mustDetectionToSensorDetectedObject(detection, sensorId, projString); PLOG(logDEBUG1) << "Sending Simulated SensorDetectedObject Message " << msg << std::endl; this->BroadcastMessage(msg, _name, 0 , IvpMsgFlags_None); } diff --git a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.h b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.h index 5caca06ef..66985190d 100644 --- a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.h +++ b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.h @@ -43,6 +43,10 @@ namespace MUSTSensorDriverPlugin std::unique_ptr mustSensorPacketReceiver; std::unique_ptr mustSensorPacketReceiverThread; + + std::string sensorId; + + std::string projString; /** * @brief Callback triggered on configuration updates */ diff --git a/src/v2i-hub/MUSTSensorDriverPlugin/test/TestMUSTSensorDetection.cpp b/src/v2i-hub/MUSTSensorDriverPlugin/test/TestMUSTSensorDetection.cpp index 3c4bb22bd..a1125210f 100644 --- a/src/v2i-hub/MUSTSensorDriverPlugin/test/TestMUSTSensorDetection.cpp +++ b/src/v2i-hub/MUSTSensorDriverPlugin/test/TestMUSTSensorDetection.cpp @@ -46,7 +46,7 @@ TEST(TestMUSTSensorDetection, csvToDectectionEmptyString ){ EXPECT_THROW(csvToDectection(valid_csv_data), std::runtime_error); } -TEST(TestMUSTSensorDetection, mustDectionToSensorDetectedObject ) { +TEST(TestMUSTSensorDetection, mustDetectionToSensorDetectedObject ) { using namespace std::chrono; MUSTSensorDetection detection; @@ -60,7 +60,7 @@ TEST(TestMUSTSensorDetection, mustDectionToSensorDetectedObject ) { detection.trackID = 324; detection.speed = 5; - auto sensorDetectedObject = mustDectionToSensorDetectedObject(detection); + auto sensorDetectedObject = mustDetectionToSensorDetectedObject(detection, "MUSTSensor1", "PROJ String"); EXPECT_EQ(detection.trackID, sensorDetectedObject.objectId); EXPECT_DOUBLE_EQ(detection.confidence, sensorDetectedObject.confidence); @@ -68,6 +68,10 @@ TEST(TestMUSTSensorDetection, mustDectionToSensorDetectedObject ) { EXPECT_DOUBLE_EQ(detection.position_y, sensorDetectedObject.position.Y); EXPECT_NEAR(4.33, sensorDetectedObject.velocity.Y, 0.001); EXPECT_NEAR(2.5, sensorDetectedObject.velocity.X, 0.001); + EXPECT_STRCASEEQ("SEDAN", sensorDetectedObject.type.c_str()); + EXPECT_EQ(detection.timestamp, sensorDetectedObject.timestamp); + EXPECT_EQ("MUSTSensor1", sensorDetectedObject.sensorId); + EXPECT_EQ("PROJ String", sensorDetectedObject.projString); } TEST(TestMUSTSensorDetection, detectionClassificationToString ) {