ADD: SensorManager with Trackfusion Trackstore and Sensor List wich contains every contact a sensor has

This commit is contained in:
Henry Winkel
2024-02-14 14:11:42 +01:00
parent cfe2aff5ce
commit 2a279f59ec
17 changed files with 678 additions and 425 deletions

View File

@@ -0,0 +1,229 @@
#include "DirectCommunicationClient.hpp"
#include "Entities/SensorControl.hpp"
#include "Entities/SensorManager.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/Position.hpp"
#include "nlohmann/json_fwd.hpp"
#include <kubecontrol/PodController.hpp>
#include <SimCore/Identifier.hpp>
#include <SimCore/SimCore.hpp>
#include <memory>
#include <string>
#include <thread>
#include <utility>
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <Entities/Sensor.hpp>
// SimCore::Identifier OwnID, SimCore::Identifier ParentID, SimCore::SensorKinds SensorKind,std::uint32_t GroundTruthPort, std::uint32_t ParentPort,std::string ParentIPAddress
double fRand(double fMin, double fMax)
{
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
void sendRandomTrack(std::shared_ptr<DirectCommunication::DirectCommunicationClient> client, int number)
{
for (int i = 0; i < number; i++) {
std::string name = "test1-" + std::to_string(i);
SimCore::SimTrack track(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
SimCore::Position pos;
double lat = fRand(-90, 90);
double lon = fRand(-180, 180);
pos.setGeodesicPos( lat, lon, 0);
track.setPosition(pos);
client->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
void sendRandomTracktoManager(std::shared_ptr<Entities::SensorManager> SensorManager_)
{
for (int i = 0; i < 5; i++) {
std::string name = "test1-" + std::to_string(i);
SimCore::SimTrack track(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
SimCore::Position pos;
double lat = fRand(-90, 90);
double lon = fRand(-180, 180);
pos.setGeodesicPos( lat, lon, 0);
track.setPosition(pos);
}
auto id0 = SimCore::Identifier();
LOG_S(INFO)<<id0.getUUID();
auto control = std::make_unique<Sensor::SensorControl>(id0.getUUID(),"Sensor", "127.0.0.1", SimCore::SensorKinds::RADAR);
auto client = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id0.getUUID());
SensorManager_->addSensorLocal(std::move(control));
// sendRandomTrack(client,5);
auto id1 = SimCore::Identifier();
auto control1 = std::make_unique<Sensor::SensorControl>(id1.getUUID(),"Sensor1", "127.0.0.1", SimCore::SensorKinds::RADAR);
auto client1 = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id1.getUUID());
SensorManager_->addSensorLocal(std::move(control1));
// sendRandomTrack(client1,5);
auto id2 = SimCore::Identifier();
auto control2 = std::make_unique<Sensor::SensorControl>(id2.getUUID(),"Sensor2", "127.0.0.1", SimCore::SensorKinds::VISUAL);
auto client2 = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id2.getUUID());
SensorManager_->addSensorLocal(std::move(control2));
// sendRandomTrack(client2,5);
auto id3 = SimCore::Identifier();
auto control3 = std::make_unique<Sensor::SensorControl>(id3.getUUID(),"Sensor3", "127.0.0.1", SimCore::SensorKinds::ESM);
auto client3 = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id3.getUUID());
SensorManager_->addSensorLocal(std::move(control3));
sendRandomTrack(client2,5);
for (int i = 0; i < 3; i++) {
std::string name = "identical-" + std::to_string(i);
SimCore::SimTrack track(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
SimCore::Position pos;
double lat = fRand(-90, 90);
double lon = fRand(-180, 180);
pos.setGeodesicPos( lat, lon, 0);
track.setPosition(pos);
client->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
client1->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
client2->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
client3->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
void startSensors(SimCore::Identifier ownid, std::string GroundTruthAddr_,ushort GroundTruthPort_, ushort SensorPort_ , auto SensorManager_)
{
LOG_S(INFO)<<"__ONLINE__";
std::string SensorUUID_ = xg::newGuid().str();
LOG_S(INFO)<<ownid.getUUID();
auto RadarPod = std::make_shared<kubecontrol::KubePod>(ownid.getUUID(),SensorUUID_,"radar:latest");
RadarPod->setEnvironmentVar("SERVER_IP", SimCore::UtilFunctions::getOwnIP());
nlohmann::json vars;
vars["OWN_SHIP_ID"] = ownid.getUUID();
vars["SENSOR_ID"] = SensorUUID_;
vars["SENSOR_NAME"] = "APAR";
vars["GROUNDTRUTH_PORT"] = std::to_string(GroundTruthPort_);
vars["GROUNDTRUTH_ADDR"] = GroundTruthAddr_;
vars["TRANSMIT_POWER"] = "66";
vars["GAIN_TRANSMIT"] = "40";
vars["GAIN_RECEIVE"] = "40";
vars["TRANSMIT_FREQUENCY"] = "2657";
vars["INSTRUMENTED_RANGE"] = "150000";
vars["MOUNTED_HEIGHT"] = "23";
vars["OWN_SHIP_IP"] = SimCore::UtilFunctions::getOwnIP();
vars["OWN_SHIP_PORT"] = std::to_string(SensorPort_);
RadarPod->setEnvironmentVar("CONFIG", vars.dump());
RadarPod->setComponent("Radar");
SensorManager_->startSensor(RadarPod, SimCore::SensorKinds::RADAR);
}
SCENARIO("Testing the SimCore SensorManager")
{
GIVEN("different Attributes for a Track in different forms")
{
SimCore::Identifier id;
auto PodController_ = std::make_shared<kubecontrol::PodController>("docs/config");
auto SensorManager_ = std::make_shared<Entities::SensorManager>(id, PodController_,5557);
startSensors(id, "239.0.0.1", 7000, 5557, SensorManager_);
WHEN("constructing Track Object with data")
{
THEN("check if Track attributes are correct")
{
REQUIRE(PodController_->getInfoForAllPods().size() == 1);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
SensorManager_->deleteAllSensor();
REQUIRE(PodController_->getInfoForAllPods().size() == 0);
} //THEN
} // WHEN
} // GIVEN
} //SCENARIO
SCENARIO("Testing the SimCore SensorManager with local sensors")
{
GIVEN("different Attributes for a Track in different forms")
{
SimCore::Identifier id;
auto PodController_ = std::make_shared<kubecontrol::PodController>("docs/config");
auto SensorManager_ = std::make_shared<Entities::SensorManager>(id, PodController_,5557);
sendRandomTracktoManager(SensorManager_);
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
WHEN("constructing Track Object with data")
{
std::string tracklist1 = SensorManager_->getTracklistStringBySensor();
std::string tracklist2 = SensorManager_->getTracklistStringFusioned();
LOG_S(INFO)<<tracklist2;
THEN("check if Track attributes are correct")
{
nlohmann::json j = nlohmann::json::parse(tracklist1);
nlohmann::json j2 = nlohmann::json::parse(tracklist2);
REQUIRE( j[0]["Sensors"].size() == 2);
REQUIRE( j[0]["Sensors"][0]["SensorContacts"].size() == 3);
REQUIRE( j[0]["Sensors"][0]["SensorContacts"].size() == j[0]["Sensors"][1]["SensorContacts"].size());
REQUIRE( j[0]["Sensors"][0]["SensorContacts"][0]["id"] == j[0]["Sensors"][1]["SensorContacts"][0]["id"]);
REQUIRE( j[0]["Sensors"][0]["SensorContacts"][0]["id"] == j[1]["Sensors"][0]["SensorContacts"][0]["id"]);
REQUIRE( j2.size() == 8);
REQUIRE(SensorManager_->getSensorCount() == 4);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
} //THEN
} // WHEN
} // GIVEN
} //SCENARIO

View File

@@ -1,6 +1,6 @@
#include "Entities/Tracklist/Tracklist.hpp"
#include "Entities/Tracklist/TracklistItem.hpp"
#include <SimCore/Messages/TracklistItem.hpp>
#include "SimCore/IdentifierMaker.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/Position.hpp"
@@ -36,17 +36,9 @@ SCENARIO("Testing the SimCore Sensor")
track->Course.setValue(course);
TrackList::SensorData Sensor1 =
{
.sensorID = SimCore::Identifier(),
.Sensorname = "ARPA"
};
SimCore::SensorData Sensor1(SimCore::Identifier(),"ARPA","127.0.0.1", SimCore::SensorKinds::RADAR);
TrackList::SensorData Sensor2 =
{
.sensorID = SimCore::Identifier(),
.Sensorname = "SMART-L"
};
SimCore::SensorData Sensor2(SimCore::Identifier(),"SMART","127.0.0.1", SimCore::SensorKinds::RADAR);
@@ -66,8 +58,8 @@ SCENARIO("Testing the SimCore Sensor")
List.addTrack(track);
// REQUIRE(List.getTrack(id)->Course.getValue() == 270);
// REQUIRE(List.getTrack(id)->getSensorCount() == 2);
std::this_thread::sleep_for(std::chrono::milliseconds(5500));
REQUIRE(List.getSize() == 0);
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
REQUIRE(List.getSize() == 1);
// List.stopSanitizer();

View File

@@ -1,79 +0,0 @@
#include "Entities/Tracklist/Tracklist.hpp"
#include "Entities/Tracklist/TracklistItem.hpp"
#include "SimCore/IdentifierMaker.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/Position.hpp"
#include "WHISPER/Messages/Message.hpp"
#include <SimCore/Identifier.hpp>
#include <SimCore/SimCore.hpp>
#include <memory>
#include <thread>
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <loguru.hpp>
SCENARIO("Testing the SimCore Sensor")
{
GIVEN("different Attributes for a Track in different forms")
{
double speed = 10;
double course = 90;
SimCore::Identifier id;
auto track = std::make_shared<SimCore::SimTrack>(id,"Hamburg", SimCore::Kind::EntityKind::SURFACE,SimCore::Side::FRIEND);
SimCore::Position pos;
pos.setGeodesicPos(55, 8, 0);
track->setPosition(pos);
track->Speed.setValue(speed);
track->Course.setValue(course);
TrackList::TracklistItem item(track);
TrackList::SensorData Sensor1 =
{
.sensorID = SimCore::Identifier(),
.Sensorname = "ARPA"
};
TrackList::SensorData Sensor2 =
{
.sensorID = SimCore::Identifier(),
.Sensorname = "SMART-L"
};
item.addSensorDataToSensorList(Sensor1);
WHEN("constructing Track Object with data")
{
track->Course.setValue(270);
item.updateTrack(track,Sensor2);
THEN("check if Track attributes are correct")
{
REQUIRE(item.getPosition().getGeocentricPos() == pos.getGeocentricPos());
REQUIRE(item.Speed.getValue() == speed);
REQUIRE(item.Course.getValue() != course);
REQUIRE(item.isSensorIDKnown(Sensor1.sensorID) == true);
REQUIRE(item.getSensorCount() == 2);
REQUIRE(item.getLastUpdateTimestamp() < std::chrono::steady_clock::now());
} //THEN
} // WHEN
} // GIVEN
} //SCENARIO