Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCP-5: SensorDetectedObject TMX message definition #628

Merged
merged 13 commits into from
Aug 13, 2024
6 changes: 5 additions & 1 deletion .sonarqube/sonar-scanner.properties
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ sonar.modules= PedestrianPlugin, \
CDASimAdapter, \
RSUHealthMonitorPlugin, \
TelematicBridgePlugin, \
MUSTSensorDriverPlugin
MUSTSensorDriverPlugin, \
Messages



TmxCore.sonar.projectBaseDir =src/tmx/TmxCore
TmxCtl.sonar.projectBaseDir =src/tmx/TmxCtl
TmxTools.sonar.projectBaseDir =src/tmx/TmxTools
TmxUtils.sonar.projectBaseDir =src/tmx/TmxUtils
Messages.sonar.projectBaseDir =src/tmx/Messages
CARMACloudPlugin.sonar.projectBaseDir =src/v2i-hub/CARMACloudPlugin
CommandPlugin.sonar.projectBaseDir =src/v2i-hub/CommandPlugin
CswPlugin.sonar.projectBaseDir =src/v2i-hub/CswPlugin
Expand Down Expand Up @@ -97,6 +99,7 @@ TmxCore.sonar.sources =src
TmxCtl.sonar.sources =src
TmxTools.sonar.sources =src
TmxUtils.sonar.sources =src
Messages.sonar.sources =include
TmxUtils.sonar.exclusions =test/**
MessageLoggerPlugin.sonar.sources =src
CswPlugin.sonar.sources =src
Expand Down Expand Up @@ -132,6 +135,7 @@ MUSTSensorDriverPlugin.sonar.sources =src
# Tests
# Note: For C++ setting this field does not cause test analysis to occur. It only allows the test source code to be evaluated.
TmxUtils.sonar.tests=test
Messages.sonar.tests=test
#TmxCore.sonar.tests=test
#TmxCtl.sonar.tests=test
#TmxTools.sonar.tests=test
Expand Down
15 changes: 15 additions & 0 deletions src/tmx/Messages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ SET (TMXMESSAGES_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
INSTALL (DIRECTORY include
DESTINATION . COMPONENT ${PROJECT_NAME}
FILES_MATCHING PATTERN "*.h*")

#############
## Testing ##
#############
enable_testing()

set(BINARY ${PROJECT_NAME}_test)

file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false test/*.h test/*.cpp)

add_executable(${BINARY} ${TEST_SOURCES})

add_test(NAME ${BINARY} COMMAND ${BINARY})
target_include_directories(${BINARY} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${BINARY} PUBLIC ${TMXAPI_LIBRARIES} gtest)
20 changes: 20 additions & 0 deletions src/tmx/Messages/include/Covariance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include <tmx/messages/message.hpp>
namespace tmx::messages
{
struct Covariance{
double value;
Covariance()=default;
explicit Covariance(double value):value(value){};
static message_tree_type to_tree(const Covariance& cov){
message_tree_type tree;
tree.put("",cov.value);
return tree;
}
static Covariance from_tree(const message_tree_type& tree){
Covariance cov;
cov.value = tree.get<double>("");
return cov;
}
};
}
27 changes: 27 additions & 0 deletions src/tmx/Messages/include/Position.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <tmx/messages/message.hpp>
namespace tmx::messages
{
// Cartesian positiion of object. Assumed to be ENU coordinate frame.
struct Position{
double x;
double y;
double z;
Position()=default;
explicit Position(double x, double y, double z):x(x),y(y),z(z){};
static message_tree_type to_tree(const Position& pos){
message_tree_type tree;
tree.put("x", pos.x);
tree.put("y", pos.y);
tree.put("z", pos.z);
return tree;
}
static Position from_tree(const message_tree_type& tree){
Position pos;
pos.x = tree.get<double>("x");
pos.y = tree.get<double>("y");
pos.z = tree.get<double>("z");
return pos;
}
};
}
95 changes: 51 additions & 44 deletions src/tmx/Messages/include/SensorDetectedObject.h
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
#ifndef INCLUDE_SIMULATED_SensorDetectedObject_H_
#define INCLUDE_SIMULATED_SensorDetectedObject_H_
#pragma once

#include <tmx/messages/message.hpp>
#include <MessageTypes.h>
#include <Vector3d.h>
#include <Point.h>
#include "Position.h"
#include "Covariance.h"
#include "Velocity.h"
#include "Size.h"

namespace tmx
namespace tmx::messages
{
namespace messages
{

/**
* This SensorDetectedObject is used to communicate the sensor detected object information with various applications.
* This message is the generic representation of a sensor detection.
*/
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;
/**
* This SensorDetectedObject is used to communicate the sensor detected object information with various applications.
* This message is the generic representation of a sensor detection.
*/
class SensorDetectedObject : public tmx::message
{
public:
SensorDetectedObject()=default;
explicit SensorDetectedObject(const tmx::message_container_type &contents) : tmx::message(contents) {};
~SensorDetectedObject() override{};
// 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;

// // Message sub type for routing this message through TMX core
static constexpr const char *MessageSubType = MSGSUBTYPE_SENSOR_DETECTED_OBJECT_STRING;
//Flag to indicate whether sensor detected object is simulated.
std_attribute(this->msg, bool, isSimulated, false,);
// Classification of detected object.
std_attribute(this->msg, std::string, type, "",);
// Confidence of type classification
std_attribute(this->msg, double, confidence, 0.0,);
// Unique indentifier of sensor reporting detection.
std_attribute(this->msg, std::string, sensorId, "", );
// String describing projection used to convert cartesian data to WGS84 data.
std_attribute(this->msg, std::string, projString, "", );
// Unique identifier of detected object.
std_attribute(this->msg, int, objectId, 0, );

// TODO: Convert this member variable to std::attributes and handle nested object and arrays. (see [CloudHeartbeatMessage.h](./CloudHearbeatMessage.h) array_attribute )

// Classification of detected object
std::string type = "";
// Confidence of type classification
double confidence = 0.0;
// Unique indentifier of sensor reporting detection
std::string sensorId = "";
// String describing projection used to convert cartesian data to WGS84 data
std::string projString = "";
// Unique identifier of detected object
int objectId = 0;
// Cartesian positiion of object. Assumed to be ENU coordinate frame.
tmx::utils::Point position = tmx::utils::Point();
// Cartesian velocity vector of object. Assumed to be ENU coordinate frame.
tmx::utils::Vector3d velocity = tmx::utils::Vector3d();
// Epoch time in milliseconds
long timestamp = 0;

};

object_attribute(Position, position);
two_dimension_array_attribute(Covariance, positionCovariance);
//Linear velocity in meter per second
object_attribute(Velocity, velocity);
//Covariance associated with linear velocity.
two_dimension_array_attribute(Covariance, velocityCovariance);
//Angular velocity in radians per second.
object_attribute(Velocity, angularVelocity);
//Covariance associated with angular velocity.
two_dimension_array_attribute(Covariance, angularVelocityCovariance);

}
// Epoch time in milliseconds.
// long timestamp = 0;
std_attribute(this->msg, long, timestamp, 0, );
object_attribute(Size, size);

};

}; // namespace tmx
#endif
}
27 changes: 27 additions & 0 deletions src/tmx/Messages/include/Size.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <tmx/messages/message.hpp>
namespace tmx::messages
{
//Length, width and height of object in meter.
struct Size{
double length;
double width;
double height;
Size()=default;
explicit Size(double length, double width, double height): length(length), width(width), height(height){};
static message_tree_type to_tree(const Size& size){
message_tree_type tree;
tree.put("length", size.length);
tree.put("width", size.width);
tree.put("height", size.height);
return tree;
}
static Size from_tree(const message_tree_type & tree){
Size size;
size.length = tree.get<double>("length");
size.width = tree.get<double>("width");
size.height = tree.get<double>("height");
return size;
}
};
}
27 changes: 27 additions & 0 deletions src/tmx/Messages/include/Velocity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <tmx/messages/message.hpp>
namespace tmx::messages
{
// Cartesian velocity vector of object. Assumed to be ENU coordinate frame.
struct Velocity{
double x;
double y;
double z;
Velocity()=default;
explicit Velocity(double x, double y, double z):x(x),y(y),z(z){};
static message_tree_type to_tree(const Velocity& velocity){
message_tree_type tree;
tree.put("x", velocity.x);
tree.put("y", velocity.y);
tree.put("z", velocity.z);
return tree;
}
static Velocity from_tree(const message_tree_type& tree){
Velocity velocity;
velocity.x = tree.get<double>("x");
velocity.y = tree.get<double>("y");
velocity.z = tree.get<double>("z");
return velocity;
}
};
}
Loading
Loading