Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed Jun 18, 2024
1 parent 31a3b0f commit d2bbdd1
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 62 deletions.
44 changes: 44 additions & 0 deletions src/tmx/Messages/include/SensorDetectedObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef INCLUDE_SIMULATED_SensorDetectedObject_H_
#define INCLUDE_SIMULATED_SensorDetectedObject_H_

#include <tmx/messages/message.hpp>
#include <MessageTypes.h>
#include <Vector3d.h>
#include <Point.h>

namespace tmx
{
namespace messages
{

/**
* This SensorDetectedObject is used to communicate the sensor detected object information with various applications
* including internal infrastructure applications and external road user applications through simulated environment.
* It defines the message type and sub type and all data members.
*/
class SensorDetectedObject : public tmx::message
{
public:
SensorDetectedObject(){};
SensorDetectedObject(const tmx::message_container_type &contents) : tmx::message(contents) {};
~SensorDetectedObject(){};
// Message type for routing this message through TMX core
static constexpr const char *MessageType = MSGTYPE_APPLICATION_STRING;

// // Message sub type for routing this message through TMX core
static constexpr const char *MessageSubType = MSGSUBTYPE_SENSOR_DETECTED_OBJECT_STRING;

std::string type = "";
double confidence = 0.0;
std::string sensorId = "";
std::string projString = "";
int objectId = 0;
tmx::utils::Point position = tmx::utils::Point();
tmx::utils::Vector3d velocity = tmx::utils::Vector3d();
long timestamp = 0;
};

}

}; // namespace tmx
#endif
44 changes: 0 additions & 44 deletions src/tmx/Messages/include/simulation/SensorDetectedObject.h

This file was deleted.

19 changes: 19 additions & 0 deletions src/tmx/TmxUtils/src/Vector3d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

namespace tmx::utils {


/// Three dimensional Vector
typedef struct Vector3d
{
Vector3d() : X(0), Y(0), Z(0) {}

Vector3d(double x, double y, double z = 0.0):
X(x), Y(y), Z(z) { }

double X;
double Y;
double Z;
} Vector3d;

} // namespace tmx::utils
4 changes: 2 additions & 2 deletions src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CARMAStreetsPlugin::CARMAStreetsPlugin(string name) :
AddMessageFilter < tsm2Message > (this, &CARMAStreetsPlugin::HandleMobilityPathMessage);
AddMessageFilter < MapDataMessage > (this, &CARMAStreetsPlugin::HandleMapMessage);
AddMessageFilter < SrmMessage > (this, &CARMAStreetsPlugin::HandleSRMMessage);
AddMessageFilter < simulation::SensorDetectedObject > (this, &CARMAStreetsPlugin::HandleSimulatedSensorDetectedMessage );
AddMessageFilter < SensorDetectedObject > (this, &CARMAStreetsPlugin::HandleSimulatedSensorDetectedMessage );

SubscribeToMessages();
}
Expand Down Expand Up @@ -704,7 +704,7 @@ void CARMAStreetsPlugin::SubscribeSDSMKafkaTopic(){

}

void CARMAStreetsPlugin::HandleSimulatedSensorDetectedMessage(simulation::SensorDetectedObject &msg, routeable_message &routeableMsg)
void CARMAStreetsPlugin::HandleSimulatedSensorDetectedMessage(SensorDetectedObject &msg, routeable_message &routeableMsg)
{
// TODO: This is a temporary fix for tmx message container property tree
// serializing all attributes as strings. This issue needs to be fixed but
Expand Down
4 changes: 2 additions & 2 deletions src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <kafka/kafka_client.h>
#include <kafka/kafka_consumer_worker.h>
#include "JsonToJ2735SSMConverter.h"
#include <simulation/SensorDetectedObject.h>
#include <SensorDetectedObject.h>
#include "JsonToJ3224SDSMConverter.h"
#include "J3224ToSDSMJsonConverter.h"
#include "PluginClientClockAware.h"
Expand Down Expand Up @@ -56,7 +56,7 @@ class CARMAStreetsPlugin: public PluginClientClockAware {
* @param msg Detected object received from TMX bus.
* @param routeableMsg routeable_message for detected object.
*/
void HandleSimulatedSensorDetectedMessage(simulation::SensorDetectedObject &msg, routeable_message &routeableMsg);
void HandleSimulatedSensorDetectedMessage(SensorDetectedObject &msg, routeable_message &routeableMsg);
/**
* @brief Overide PluginClientClockAware HandleTimeSyncMessage to producer TimeSyncMessage to kafka for CARMA Streets Time Synchronization.
* @param msg TimeSyncMessage received by plugin when in simulation mode. Message provides current simulation time to all processes.
Expand Down
4 changes: 2 additions & 2 deletions src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ namespace CDASimAdapter{

}

void CDASimAdapter::forward_simulated_detected_message(tmx::messages::simulation::SensorDetectedObject &msg) {
void CDASimAdapter::forward_simulated_detected_message(tmx::messages::SensorDetectedObject &msg) {
PLOG(logDEBUG1) << "Sending Simulated SensorDetectedObject Message " << msg << std::endl;
this->BroadcastMessage<tmx::messages::simulation::SensorDetectedObject>(msg, _name, 0 , IvpMsgFlags_None);
this->BroadcastMessage<tmx::messages::SensorDetectedObject>(msg, _name, 0 , IvpMsgFlags_None);
}

bool CDASimAdapter::connect() {
Expand Down
4 changes: 2 additions & 2 deletions src/v2i-hub/CDASimAdapter/src/CDASimConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ namespace CDASimAdapter{

}

tmx::messages::simulation::SensorDetectedObject CDASimConnection::consume_sensor_detected_object_message() const
tmx::messages::SensorDetectedObject CDASimConnection::consume_sensor_detected_object_message() const
{
tmx::messages::simulation::SensorDetectedObject externalObj;
tmx::messages::SensorDetectedObject externalObj;
externalObj.clear();
if(sensor_detected_object_listener)
{
Expand Down
2 changes: 1 addition & 1 deletion src/v2i-hub/CDASimAdapter/src/include/CDASimAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace CDASimAdapter
* @brief Forward simulated sensor detected object message to TMX message bus for other V2X-Hub Plugin
* @param msg simulation::SensorDetectedObject.
*/
void forward_simulated_detected_message(tmx::messages::simulation::SensorDetectedObject &msg);
void forward_simulated_detected_message(tmx::messages::SensorDetectedObject &msg);
/**
* @brief Method to start thread timer for regular interval actions lauched on seperate thread.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/v2i-hub/CDASimAdapter/src/include/CDASimConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <tmx/tmx.h>
#include <Point.h>
#include <TimeSyncMessage.h>
#include <simulation/SensorDetectedObject.h>
#include <SensorDetectedObject.h>
#include <jsoncpp/json/json.h>
#include <PluginLog.h>
#include <gtest/gtest.h>
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace CDASimAdapter {
* To populate the simulation external object, this JSON string has to follow this specification: https://usdot-carma.atlassian.net/wiki/spaces/CRMSIM/pages/2563899417/Detected+Objects+Specification#CARMA-Street-and-V2xHub
* @return simulation::SensorDetectedObject.
*/
tmx::messages::simulation::SensorDetectedObject consume_sensor_detected_object_message() const;
tmx::messages::SensorDetectedObject consume_sensor_detected_object_message() const;
/**
* @brief Perform handshake with CARMA-Simulation. Will return true on successful handshakes and false if
* unsuccessful. As part of the handshake should set simulation_v2x_port for forwarding v2x messages to simulation,
Expand Down
13 changes: 11 additions & 2 deletions src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ namespace MUSTSensorDriverPlugin {
return detection;
}

tmx::messages::simulation::SensorDetectedObject mustDectionToSensorDetectedObject(const MUSTSensorDetection &detection) {
tmx::messages::simulation::SensorDetectedObject detectedObject;
tmx::messages::SensorDetectedObject mustDectionToSensorDetectedObject(const MUSTSensorDetection &detection) {
tmx::messages::SensorDetectedObject detectedObject;
detectedObject.objectId = detection.trackID;
detectedObject.position.X = detection.position_x;
detectedObject.position.Y = detection.position_y;
detectedObject.confidence = detection.confidence;
detectedObject.timestamp = detection.timestamp;
detectedObject.velocity = headingSpeedToVelocity(detection.heading, detection.speed);
return detectedObject;
}
const DetectionClassification fromStringToDetectionClassification(const std::string &str) noexcept {
Expand All @@ -57,4 +58,12 @@ namespace MUSTSensorDriverPlugin {
return DetectionSize::NA;
}
};

tmx::utils::Vector3d headingSpeedToVelocity(double heading, double speed) {
tmx::utils::Vector3d velocity;
velocity.X = - std::sin(M_PI/180* heading) * speed;
velocity.Y = std::cos(M_PI/180 * heading) * speed;
velocity.Z = 0;
return velocity;
};
}
6 changes: 4 additions & 2 deletions src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#include <string>
#include <unordered_map>
#include <stdexcept> // std::out_of_range
#include <simulation/SensorDetectedObject.h>
#include <SensorDetectedObject.h>
#include <PluginLog.h>
#include <Vector3d.h>

namespace MUSTSensorDriverPlugin {

Expand Down Expand Up @@ -54,6 +55,7 @@ namespace MUSTSensorDriverPlugin {

MUSTSensorDetection csvToDectection(const std::string &csv );

tmx::messages::simulation::SensorDetectedObject mustDectionToSensorDetectedObject(const MUSTSensorDetection &detection);
tmx::messages::SensorDetectedObject mustDectionToSensorDetectedObject(const MUSTSensorDetection &detection);

tmx::utils::Vector3d headingSpeedToVelocity(double heading, double speed);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ namespace MUSTSensorDriverPlugin {
void MUSTSensorDriverPlugin::processMUSTSensorDetection(){
if (mustSensorPacketReceiver) {
MUSTSensorDetection detection = csvToDectection(mustSensorPacketReceiver->stringTimedReceive());
tmx::messages::simulation::SensorDetectedObject msg = mustDectionToSensorDetectedObject(detection);
tmx::messages::SensorDetectedObject msg = mustDectionToSensorDetectedObject(detection);
PLOG(logDEBUG1) << "Sending Simulated SensorDetectedObject Message " << msg << std::endl;
this->BroadcastMessage<tmx::messages::simulation::SensorDetectedObject>(msg, _name, 0 , IvpMsgFlags_None);
this->BroadcastMessage<tmx::messages::SensorDetectedObject>(msg, _name, 0 , IvpMsgFlags_None);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <UdpServer.h>
#include <ThreadWorker.h>
#include <mutex>
#include <simulation/SensorDetectedObject.h>
#include <SensorDetectedObject.h>

#include "MUSTSensorDetection.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>
#include <MUSTSensorDetection.h>
#include <chrono>

using namespace MUSTSensorDriverPlugin;

Expand Down Expand Up @@ -33,4 +34,38 @@ TEST(TestMUSTSensorDetection, csvToDectection ){
EXPECT_DOUBLE_EQ(detection.confidence, 95.1);
EXPECT_EQ(detection.trackID, 1);
EXPECT_EQ(detection.timestamp, 1714374738);
}

TEST(TestMUSTSensorDetection, csvToDectectionInvalidCSV ){
std::string valid_csv_data = "truck,13.3,22.4,30.5,35.8,large,95.1,1,1714374738,20";
EXPECT_THROW(csvToDectection(valid_csv_data), std::runtime_error);
}

TEST(TestMUSTSensorDetection, csvToDectectionEmptyString ){
std::string valid_csv_data = "";
EXPECT_THROW(csvToDectection(valid_csv_data), std::runtime_error);
}

TEST(TestMUSTSensorDetection, mustDectionToSensorDetectedObject ) {
using namespace std::chrono;

MUSTSensorDetection detection;
detection.cl = DetectionClassification::SEDAN;
detection.confidence = 95.5;
detection.heading = 330;
detection.position_x = 10.5;
detection.position_y = -20.3;
detection.size = DetectionSize::SMALL;
detection.timestamp = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
detection.trackID = 324;
detection.speed = 5;

auto sensorDetectedObject = mustDectionToSensorDetectedObject(detection);

EXPECT_EQ(detection.trackID, sensorDetectedObject.objectId);
EXPECT_DOUBLE_EQ(detection.confidence, sensorDetectedObject.confidence);
EXPECT_DOUBLE_EQ(detection.position_x, sensorDetectedObject.position.X);
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);
}

0 comments on commit d2bbdd1

Please sign in to comment.