Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-du-car committed Jul 17, 2023
1 parent 639ad08 commit 0963f01
Show file tree
Hide file tree
Showing 16 changed files with 468 additions and 23 deletions.
1 change: 1 addition & 0 deletions .devcontainer/docker-compose-vscode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
- TIME_SYNC_TOPIC=time_sync
- TIME_SYNC_PORT=7575
- SIM_V2X_PORT=5757
- SIM_EXTERNAL_OBJECT_PORT=7576
- V2X_PORT=8686
- INFRASTRUCTURE_ID=1
- KAFKA_BROKER_ADDRESS=127.0.0.1:9092
Expand Down
11 changes: 11 additions & 0 deletions configuration/amd64/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ services:
- db
environment:
- MYSQL_PASSWORD=/run/secrets/mysql_password
- SIMULATION_MODE=true
- SIMULATION_IP=127.0.0.1
- SIMULATION_REGISTRATION_PORT=6767
- LOCAL_IP=127.0.0.1
- TIME_SYNC_TOPIC=time_sync
- TIME_SYNC_PORT=7575
- SIM_V2X_PORT=5757
- SIM_EXTERNAL_OBJECT_PORT=7576
- V2X_PORT=8686
- INFRASTRUCTURE_ID=1
- KAFKA_BROKER_ADDRESS=127.0.0.1:9092
secrets:
- mysql_password
volumes:
Expand Down
2 changes: 2 additions & 0 deletions src/tmx/Messages/include/MessageTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static CONSTEXPR const char *MSGTYPE_VEHICLE_STRING = "Vehicle";
static CONSTEXPR const char *MSGTYPE_PEDESTRIAN_STRING = "Pedestrian";
static CONSTEXPR const char *MSGTYPE_PMM_STRING = "Pmm";
static CONSTEXPR const char *MSGTYPE_RADIO_STRING = "Radio";
static CONSTEXPR const char *MSGTYPE_DETECTED_STRING = "Simulation";

enum MsgSubType
{
Expand Down Expand Up @@ -91,6 +92,7 @@ static CONSTEXPR const char *MSGSUBTYPE_INCOMING_STRING = "Incoming";
static CONSTEXPR const char *MSGSUBTYPE_OUTGOING_STRING = "Outgoing";
static CONSTEXPR const char *MSGSUBTYPE_SHUTDOWN_STRING = "Shutdown";
static CONSTEXPR const char *MSGSUBTYPE_TIMESYNC_STRING = "TimeSync";
static CONSTEXPR const char *MSGSUBTYPE_EXTERNAL_OBJECT_STRING = "ExternalObject";

} /* End namespace messages */

Expand Down
145 changes: 145 additions & 0 deletions src/tmx/Messages/include/simulation/ExternalObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#ifndef INCLUDE_SIMULATED_EXTERNALOBJECT_H_
#define INCLUDE_SIMULATED_EXTERNALOBJECT_H_

#include <tmx/messages/message.hpp>
#include <MessageTypes.h>
// #include <simulation/Header.h>
#include <simulation/PresenceVectorEnumTypes.h>
#include <simulation/ObjectEnumTypes.h>

namespace tmx
{
namespace messages
{
namespace simulation
{
/**
* This ExternalObject 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 ExternalObject : public tmx::message
{
public:
ExternalObject(){};
ExternalObject(const tmx::message_container_type &contents) : tmx::message(contents) {}
ExternalObject(PRESENCE_VECTOR_TYPES presenceVector, uint32_t id,
double confidence, OBJECT_TYPES objectType, bool dynamticObj)
{
set_PresenceVector(presenceVector);
set_Id(id);
set_Confidence(confidence);
set_ObjectType(objectType);
set_DynamticObj(dynamticObj);
};
~ExternalObject(){};
// Message type fpr routing this message through TMX core
static constexpr const char *MessageType = MSGTYPE_DETECTED_STRING;

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

/**
*Header contains the frame rest of the fields will use
*/
// sequence ID: consecutively increasing ID
std_attribute(this->msg, uint32_t, HeaderSeq, 0, );
// Two-integer timestamp that is expressed as:
// # * stamp.sec: seconds (stamp_secs) since epoch (in Python the variable is called 'secs')
// # * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs')
// # time-handling sugar is provided by the client library
// The seconds component, valid over all int32 values.
std_attribute(this->msg, uint32_t, HeaderTimeSec, 0, );
// # The nanoseconds component, valid in the range [0, 10e9).
std_attribute(this->msg, uint32_t, HeaderTimeNanoSec, 0, );

// A presence vector, this message is used to describe objects coming from potentially different
// sources. The presence vector is used to determine what items are set by the producer.
std_attribute(this->msg, PRESENCE_VECTOR_TYPES, PresenceVector, PRESENCE_VECTOR_TYPES::OBJECT_TYPE_PRESENCE_VECTOR, );

// Object id. Matching ids on a topic should refer to the same object within some time period, expanded
std_attribute(this->msg, uint32_t, Id, 0, );

// bsm id is of form [0xff, 0xff, 0xff, 0xff]. It is not required.
// uint8[] bsm_id
struct BSMID
{
uint8_t BsmId = 0;

BSMID() {}
BSMID(std::uint8_t bsmId) : BsmId(bsmId) {}

static message_tree_type to_tree(BSMID element)
{
message_tree_type treeElement;
treeElement.put("BsmId", element.BsmId);
return treeElement;
}

static BSMID from_tree(message_tree_type &treeElement)
{
BSMID element;
element.BsmId = treeElement.get<std::uint8_t>("BsmId");
return element;
}
};
array_attribute( BSMID, BsmId);

// Pose of the object within the frame specified in header
// geometry_msgs/PoseWithCovariance pose
// This represents a pose in free space with uncertainty.
std_attribute(this->msg, double, PosePointX, 0, );
std_attribute(this->msg, double, PosePointY, 0, );
std_attribute(this->msg, double, PosePointZ, 0, );

// This represents an orientation in free space in quaternion form.
std_attribute(this->msg, double, PoseQuaternionX, 0, );
std_attribute(this->msg, double, PoseQuaternionY, 0, );
std_attribute(this->msg, double, PoseQuaternionZ, 0, );
std_attribute(this->msg, double, PoseQuaternionW, 0, );

// Row-major representation of the 6x6 covariance matrix
// # The orientation parameters use a fixed-axis representation.
// # In order, the parameters are:
// # (x, y, z, rotation about X axis, rotation about Y axis, rotation about Z axis)
std_attribute(this->msg, double, Covariance, 0, );

// #Average velocity of the object within the frame specified in header
// geometry_msgs/TwistWithCovariance velocity

// #Instantaneous velocity of an object within the frame specified in header
// geometry_msgs/TwistWithCovariance velocity_inst

// #The size of the object aligned along the axis of the object described by the orientation in pose
// #Dimensions are specified in meters
/**
* # This represents a vector in free space.
# It is only meant to represent a direction. Therefore, it does not
# make sense to apply a translation to it (e.g., when applying a
# generic rigid transformation to a Vector3, tf2 will only apply the
# rotation). If you want your data to be translatable too, use the
# geometry_msgs/Point message instead.
*/
// geometry_msgs/Vector3 size
std_attribute(this->msg, double, SizeX, 0, );
std_attribute(this->msg, double, SizeY, 0, );
std_attribute(this->msg, double, SizeZ, 0, );

// #Confidence [0,1]
std_attribute(this->msg, double, Confidence, 0, );

// #describes a general object type as defined in this message
std_attribute(this->msg, OBJECT_TYPES, ObjectType, OBJECT_TYPES::UNKNOWN, );

// # Binary value to show if the object is static or dynamic (1: dynamic, 0: static)
std_attribute(this->msg, bool, DynamticObj, false, );

// Predictions for the object. It is not required.
// carma_perception_msgs/PredictedState[] predictions
};

}
}

}; // namespace tmx
#endif
23 changes: 23 additions & 0 deletions src/tmx/Messages/include/simulation/ObjectEnumTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef INCLUDE_SIMULATED_OBJECT_TYPE_H_
#define INCLUDE_SIMULATED_OBJECT_TYPE_H_

namespace tmx
{
namespace messages
{
namespace simulation
{
// #used for object type
enum OBJECT_TYPES
{
UNKNOWN = 0,
SMALL_VEHICLE = 1,
LARGE_VEHICLE = 2,
MOTORCYCLE = 3,
PEDESTRIAN = 4
};
}
}

}; // namespace tmx
#endif
27 changes: 27 additions & 0 deletions src/tmx/Messages/include/simulation/PresenceVectorEnumTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef INCLUDE_SIMULATED_PRESENCE_VECTOR_H_
#define INCLUDE_SIMULATED_PRESENCE_VECTOR_H_

namespace tmx
{
namespace messages
{
namespace simulation
{
enum PRESENCE_VECTOR_TYPES
{
ID_PRESENCE_VECTOR = 1,
POSE_PRESENCE_VECTOR = 2,
VELOCITY_PRESENCE_VECTOR = 4,
VELOCITY_INST_PRESENCE_VECTOR = 8,
SIZE_PRESENCE_VECTOR = 16,
CONFIDENCE_PRESENCE_VECTOR = 32,
OBJECT_TYPE_PRESENCE_VECTOR = 64,
BSM_ID_PRESENCE_VECTOR = 128,
DYNAMIC_OBJ_PRESENCE = 256,
PREDICTION_PRESENCE_VECTOR = 512
};
}
}

}; // namespace tmx
#endif
5 changes: 5 additions & 0 deletions src/tmx/TmxUtils/src/simulation/SimulationEnvUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ namespace tmx::utils::sim{
* necessary in SIMULATION MODE for CDASim message forwarding.
*/
constexpr inline static const char *SIM_V2X_PORT = "SIM_V2X_PORT";
/**
* @brief Name of environment variable for storing port for forwarding v2x messages to CDASim. Only
* necessary in SIMULATION MODE for CDASim message forwarding.
*/
constexpr inline static const char *SIM_EXTERNAL_OBJECT_PORT = "SIM_EXTERNAL_OBJECT_PORT";
/**
* @brief Name of environment variable for storing port for receiving v2x messages from CDASim. Only
* necessary in SIMULATION MODE for CDASim message forwarding.
Expand Down
8 changes: 8 additions & 0 deletions src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CARMAStreetsPlugin::CARMAStreetsPlugin(string name) :
AddMessageFilter < tsm2Message > (this, &CARMAStreetsPlugin::HandleMobilityPathMessage);
AddMessageFilter < MapDataMessage > (this, &CARMAStreetsPlugin::HandleMapMessage);
AddMessageFilter < SrmMessage > (this, &CARMAStreetsPlugin::HandleSRMMessage);
AddMessageFilter < simulation::ExternalObject> (this, &CARMAStreetsPlugin::HandleSimulatedExternalMessage );

SubscribeToMessages();

Expand Down Expand Up @@ -626,6 +627,13 @@ void CARMAStreetsPlugin::SubscribeSSMKafkaTopic(){
}

}

void CARMAStreetsPlugin::HandleSimulatedExternalMessage(simulation::ExternalObject &msg, routeable_message &routeableMsg)
{
PLOG(logINFO) << "HandleSimulatedExternalMessage called." <<std::endl;
PLOG(logINFO) << msg.to_string()<<std::endl;
}

bool CARMAStreetsPlugin::getEncodedtsm3( tsm3EncodedMessage *tsm3EncodedMsg, Json::Value metadata, Json::Value payload_json )
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <kafka/kafka_client.h>
#include <kafka/kafka_consumer_worker.h>
#include "JsonToJ2735SSMConverter.h"
#include <simulation/ExternalObject.h>



Expand Down Expand Up @@ -48,6 +49,7 @@ class CARMAStreetsPlugin: public PluginClient {
void HandleMobilityOperationMessage(tsm3Message &msg, routeable_message &routeableMsg);
void HandleMobilityPathMessage(tsm2Message &msg, routeable_message &routeableMsg);
void HandleBasicSafetyMessage(BsmMessage &msg, routeable_message &routeableMsg);
void HandleSimulatedExternalMessage(simulation::ExternalObject &msg, routeable_message &routeableMsg);
/**
* @brief Subscribe to MAP message broadcast by the MAPPlugin. This handler will be called automatically whenever the MAPPlugin is broadcasting a J2735 MAP message.
* @param msg The J2735 MAP message received from the internal
Expand Down
Loading

0 comments on commit 0963f01

Please sign in to comment.