9#include "Math/UnrealMathUtility.h"
30 const float ReceiverSensitivity,
31 const float Frequency,
32 const float combined_antenna_gain,
33 const float path_loss_exponent,
34 const float reference_distance_fspl,
35 const float filter_distance,
36 const bool use_etsi_fading,
37 const float custom_fading_stddev)
71 FVector OtherActorLocation;
73 float ReceivedPower = 0;
77 double tx_height_local = (
mActorOwner->GetSimpleCollisionHalfHeight() * 2.0f) + 2.0;
81 for (
auto &actor_power_pair : ActorList)
89 OtherActorLocation = actor_power_pair.first->GetTransform().GetLocation();
90 double rx_height_local = (actor_power_pair.first->GetSimpleCollisionHalfHeight() * 2.0) + 2.0;
98 double hr = OtherActorLocation.Z + rx_height_local - ref0;
101 source_rel.Z += tx_height_local;
102 FVector dest_rel = OtherActorLocation;
103 dest_rel.Z += rx_height_local;
105 double Distance3d = FVector::Distance(source_rel, dest_rel) / 100.0f;
112 float OtherTransmitPower = actor_power_pair.second;
123 if (ReceivedPower > -1.0 * std::numeric_limits<float>::max())
132 const float OtherTransmitPower,
133 const FVector Source,
134 const FVector Destination,
135 const double Distance3d,
137 const double ht_local,
139 const double hr_local,
140 const double reference_z)
147 FCollisionObjectQueryParams ObjectParams;
149 ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_WorldStatic);
150 ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_PhysicsBody);
151 ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_Vehicle);
152 ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_WorldDynamic);
157 FVector rx = Destination;
162 float loss =
ComputeLoss(OtherActor, Source, Destination, Distance3d, ht, hr, reference_z);
183 if (deltaPercentage < 0.65)
193 else if (deltaPercentage < 0.8)
216 return ReceivedPower;
220 return -1.0 * std::numeric_limits<float>::max();
225 FVector CurrentActorLocation,
230 std::vector<FVector> &vehicle_obstacles)
246 for (
const FHitResult &HitInfo :
HitResult)
265 vehicle_obstacles.emplace_back(location);
281 double V = h * sqrt(2.0 * (d1 + d2) / (
lambda * d1 * d2));
283 double T = std::pow(V - 0.1, 2);
284 return 6.9 + 20.0 * log10(sqrt(T + 1.0) + V - 0.1);
290 const FVector Destination,
291 const double TxHeight,
292 const double RxHeight,
293 const double RxDistance3d,
294 std::vector<FVector> &vehicle_obstacles)
298 FVector pos_tx = Source;
303 FVector pos_rx = Destination;
308 double max_loss = 0.0;
309 for(
auto veh_it = vehicle_obstacles.begin(); veh_it != vehicle_obstacles.end(); veh_it++)
311 double dist_tx_veh = sqrt(std::pow(veh_it->X - pos_tx.X, 2) + std::pow(veh_it->Y - pos_tx.Y, 2));
312 double dist_veh_rx = sqrt(std::pow(pos_rx.X - veh_it->X, 2) + std::pow(pos_rx.Y - veh_it->Y, 2));
314 if(cur_loss >= max_loss)
325 model = path_loss_model;
336 float PathLoss = 0.0;
337 double VehicleBlockageLoss = 0.0;
338 float ShadowFadingLoss = 0.0;
341 std::vector<FVector> vehicle_obstacles;
351 PathLoss = PathLoss +
CalculateNLOSvLoss(Source, Destination, TxHeight, RxHeight, Distance3d, vehicle_obstacles);
370 double free_space_loss = 20.0 * log10(Distance3d) + 20.0 * log10(4.0 * PI /
lambda);
372 PathLoss = free_space_loss +
CalculateNLOSvLoss(Source, Destination, TxHeight, RxHeight, Distance3d, vehicle_obstacles);
378 return PathLoss + ShadowFadingLoss;
386 const AActor *actor = HitInfo.Actor.Get();
388 if (actor !=
nullptr)
405 const AActor *actor = HitInfo.Actor.Get();
406 if (actor !=
nullptr)
412 else if (actor == OtherActor)
426 const AActor *actor = HitInfo.Actor.Get();
428 if (actor !=
nullptr)
437 location = actor->GetTransform().GetLocation();
438 location.Z = location.Z - reference_z + (actor->GetSimpleCollisionHalfHeight() * 2.0) + 2.0;
439 location.Z = location.Z / 100.0f;
441 location.X /= 100.0f;
442 location.Y /= 100.0f;
461 return 36.85f + 30.0f * log10(Distance) + 18.9f * log10(
Frequency_GHz);
467 return 32.4f + 20.0f * log10(Distance) + 20.0f * log10(
Frequency_GHz);
471 return 38.77f + 16.7f * log10(Distance) + 18.2f * log10(
Frequency_GHz);
479 const float Mean = 0.0f;
549 return 40 * log10(Distance3d) - 10 * log10(TxHeight * TxHeight * RxHeight * RxHeight);
556 double d_ground = sqrt(std::pow(Distance3d, 2) - std::pow(TxHeight - RxHeight, 2));
560 double d_refl = sqrt(std::pow(Distance3d, 2) + 4.0 * TxHeight * RxHeight);
563 double sin_theta = (TxHeight + RxHeight) / d_refl;
564 double cos_theta = d_ground / d_refl;
566 double gamma = (sin_theta - sqrt(
epsilon_r - std::pow(cos_theta, 2))) / (sin_theta + sqrt(
epsilon_r - std::pow(cos_theta, 2)));
568 double phi = (2.0 * PI /
lambda * (Distance3d - d_refl));
570 return 20 * log10(4.0 * PI * d_ground /
lambda * 1.0 / sqrt(std::pow(1 + gamma * cos(phi), 2) + std::pow(gamma, 2) * std::pow(sin(phi), 2)));
A registry of all the Carla actors.
FCarlaActor * FindCarlaActor(IdType Id)
A view over an actor and its properties.
ActorType GetActorType() const
float ReceiverSensitivity
float ComputeLoss(AActor *OtherActor, FVector Source, FVector Destination, double Distance3d, double TxHeight, double RxHeight, double reference_z)
Method that allow to preprocess if the rays will be traced.
double CalcVehicleLoss(const double d1, const double d2, const double h)
FVector CurrentActorLocation
static double Frequency_GHz
PathLossModel(URandomEngine *random_engine)
ActorPowerMap GetReceiveActorPowerList()
void Simulate(const std::vector< ActorPowerPair > ActorList, UCarlaEpisode *CarlaEpisode, UWorld *World)
UCarlaEpisode * mCarlaEpisode
void SetScenario(EScenario scenario)
URandomEngine * mRandomEngine
float CalculatePathLoss_WINNER(EPathState state, double Distance)
void SetPathLossModel(const EPathLossModel path_loss_model)
double CalculateTwoRayPathLoss(double Distance3d, double TxHeight, double RxHeight)
static constexpr float c_speedoflight
float custom_fading_stddev
bool GetLocationIfVehicle(const FVector CurrentActorLocation, const FHitResult &HitInfo, const double reference_z, FVector &location)
float CalculateReceivedPower(AActor *OtherActor, const float OtherTransmitPower, const FVector Source, const FVector Destination, const double Distance3d, const double ht, const double ht_local, const double hr, const double hr_local, const double reference_z)
float CalculateTwoRayPathLossSimple(double Distance3d, double TxHeight, double RxHeight)
double CalculateNLOSvLoss(const FVector Source, const FVector Destination, const double TxHeight, const double RxHeight, const double RxDistance3d, std::vector< FVector > &vehicle_obstacles)
void EstimatePathStateAndVehicleObstacles(AActor *OtherActor, FVector Source, double TxHeight, double RxHeight, double reference_z, EPathState &state, std::vector< FVector > &vehicle_obstacles)
void SetParams(const float TransmitPower, const float ReceiverSensitivity, const float Frequency, const float combined_antenna_gain, const float path_loss_exponent, const float reference_distance_fspl, const float filter_distance, const bool use_etsi_fading, const float custom_fading_stddev)
float reference_distance_fspl
ActorPowerMap mReceiveActorPowerList
bool HitIsSelfOrOther(const FHitResult &HitInfo, AActor *OtherActor)
void SetOwner(AActor *Owner)
TArray< FHitResult > HitResult
float combined_antenna_gain
float CalculateShadowFading(EPathState state)
bool IsVehicle(const FHitResult &HitInfo)
const FActorRegistry & GetActorRegistry() const
float GetNormalDistribution(float Mean, float StandardDeviation)