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

Streets MOSAIC integration: CDASimAdapter register with Simulation ambassador and send sensors information #554

Merged
merged 26 commits into from
Jul 27, 2023

Conversation

dan-du-car
Copy link
Collaborator

@dan-du-car dan-du-car commented Jul 25, 2023

PR Details

Description

Update the CDASimAdapter registration message to include the sensors information.
Read the sensors information from local file and store the sensors information in the CDASimAdapter
plugin.

Related Issue

NA

Motivation and Context

CDA research

How Has This Been Tested?

unit test
local integration test

Types of changes

  • Defect fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that cause existing functionality to change)

Checklist:

  • I have added any new packages to the sonar-scanner.properties file
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
    V2XHUB Contributing Guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@@ -24,6 +24,8 @@ services:
- SIM_V2X_PORT=5757
- V2X_PORT=8686
- INFRASTRUCTURE_ID=1
- SENSOR_JSON_FILE_PATH=/var/www/plugins/MAP/sensors.json
- KAFKA_BROKER_ADDRESS=127.0.0.1:9092
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need this configuration parameter. It is captured in the CARMA-Streets Plugin configuration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one? The json file path or the kafka broker?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Kafka broker

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

}
}

Json::Value CDASimConnection::get_sensor_by_id(std::string &sensor_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, is there a reason you opted against making sensor its own data type that handles serialization/deserialization internally. This works to but it seems to be that it may be a cleaner implementation of we keep JSON serialization/deserialization and data type definition separate from this plugin.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create another data type for sensor in JSON representation? This function is to find the sensor Json::Value from the sensors of type Json::Value which is sent for registration using sensor id. As we will need this later to modify the detected object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Json::Value data type is sufficient for this case. It allows more flexibility to modify the sensor JSON, and no overhead defining another strong sensor object type, then implement our own serialization/deserialization logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My issue is that it contaminates our Plugin Logic with the logic for serializing/deserializing/retreiving data from the sensor object. Ideally the entire Infrastructure Registration JSON message would have its own class so we can modify it without directly having to modify our plugin logic. I think this concept is referred to as encapsulation : "the bundling of data, along with the methods that operate on that data, into a single unit". I will leave it to you whether you believe it is worth addressing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are back to our definition of detected object. As we forwarding detected object as JSON string to TMX bus, and subscribe the JSON string as it. I do not think we need strong type and operation here.

/**
* @brief sensors file location
*/
constexpr inline static const char *SENSOR_JSON_FILE_PATH = "SENSOR_JSON_FILE_PATH";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was your reasoning for including this as an environment variable instead of a plugin configuration similar to location. Just curious, I think we need to define a clear line between what we use as environment variables and what ew configure in the plugin. Simulation configurations are good to have in as environment variables because they do not require configuration and can be read easily at startup. They are also unlikely to change dynamically. I think that makes sense for the sensor configuration file as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you answer your own question? Yeah, I agree that the file path for sensors shall not change constantly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah just wanted to bring it up, that we give thought to what is an environment variable and what is a configuration parameter.

populate_json_with_string(ss.str(), sensors_json_v);
}

void CDASimConnection::populate_json_with_string(const std::string& json_str, Json::Value& json_v){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above about using void return by reference. What is your reasoning here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop the execution flow and return the control to the caller

@@ -142,6 +163,9 @@ namespace CDASimAdapter {
uint _v2x_port;
tmx::utils::Point _location;
bool _connected = false;
std::string _sensor_json_file_path;
//Global variable to store the sensors information
Json::Value _sensors_json_v;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make a sensor class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Json::Value is sufficient for this. Do you have specific reason that we need a sensor class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be against handling any JSON object directly especially if we plan to used the stored data. There is no indication in the code of what structure the JSON has to have, additionally if we pass this JSON anywhere else in the code there will be not structure defined there either.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add comments to refer to the sensors.json, so we know what json structure we are expecting if that helps to indicate the sensor Json message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@@ -0,0 +1,32 @@
[
{
"id": "SomeID",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to be sensorId. I think id conflicts with Interaction (MOSIAC RTI) Id field.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sensorId instead of sensor_id to be consistant with naming convention.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

if(in_strm.is_open())
{
ASSERT_EQ(connection->get_handshake_json("4566", "127.0.0.1", 4567, 4568, location),
"{\n \"infrastructureId\" : \"4566\",\n \"location\" : {\n \"x\" : 1000.0,\n \"y\" : 38.954999999999998,\n \"z\" : -77.149000000000001\n },\n \"rxMessageIpAddress\" : \"127.0.0.1\",\n \"rxMessagePort\" : 4568,\n \"sensors\" : [\n {\n \"location\" : {\n \"x\" : 0.0,\n \"y\" : 0.0,\n \"z\" : 0.0\n },\n \"orientation\" : {\n \"x\" : 0.0,\n \"y\" : 0.0,\n \"z\" : 0.0\n },\n \"sensor_id\" : \"SomeID\",\n \"type\" : \"SematicLidar\"\n },\n {\n \"location\" : {\n \"x\" : 1.0,\n \"y\" : 2.0,\n \"z\" : 0.0\n },\n \"orientation\" : {\n \"x\" : 23.0,\n \"y\" : 0.0,\n \"z\" : 0.0\n },\n \"sensor_id\" : \"SomeID2\",\n \"type\" : \"LIDAR\"\n }\n ],\n \"timeSyncPort\" : 4567\n}\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"sensorId" instance of "sensor_id" so we are consistent with naming convention

@paulbourelly999
Copy link
Contributor

If you fix the sensorId field this looks good to me. Looking into the code smells now.

@@ -21,15 +22,16 @@ namespace CDASimAdapter {
class TestCARMASimulationConnection : public ::testing::Test {
protected:
void SetUp() override {
// Initialize CARMA Simulation connection with (0,0,0) location.
// Initialize CARMA Simulation connection with (0,0,0) location and mock kafka producer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small issue but there is no mock kafka producer here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -0,0 +1,12 @@
import socket

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add small commented about what script is for and how to use it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a UDP server script to launch a server for testing the CDASimAdapter plugin registration. Run this script first, then start the CDASimAdapter plugin, this server shall print out the registration message.

if(in_strm.is_open())
{
ASSERT_EQ(connection->get_handshake_json("4566", "127.0.0.1", 4567, 4568, location),
"{\n \"infrastructureId\" : \"4566\",\n \"location\" : {\n \"x\" : 1000.0,\n \"y\" : 38.954999999999998,\n \"z\" : -77.149000000000001\n },\n \"rxMessageIpAddress\" : \"127.0.0.1\",\n \"rxMessagePort\" : 4568,\n \"sensors\" : [\n {\n \"location\" : {\n \"x\" : 0.0,\n \"y\" : 0.0,\n \"z\" : 0.0\n },\n \"orientation\" : {\n \"x\" : 0.0,\n \"y\" : 0.0,\n \"z\" : 0.0\n },\n \"sensorId\" : \"SomeID\",\n \"type\" : \"SematicLidar\"\n },\n {\n \"location\" : {\n \"x\" : 1.0,\n \"y\" : 2.0,\n \"z\" : 0.0\n },\n \"orientation\" : {\n \"x\" : 23.0,\n \"y\" : 0.0,\n \"z\" : 0.0\n },\n \"sensorId\" : \"SomeID2\",\n \"type\" : \"LIDAR\"\n }\n ],\n \"timeSyncPort\" : 4567\n}\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lastly orientation should be

{
    "yaw":0.0,
    "pitch":0.0,
    "roll":0.0

"z": 0.0
},
"orientation": {
"x": 0.0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment about about yaw, pitch, roll

},
{
"sensorId": "SomeID2",
"type": "LIDAR",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will only support SemanticLidar type for right now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@paulbourelly999 paulbourelly999 merged commit 678784c into develop Jul 27, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants