11#include "Math/UnrealMathUtility.h"
32 const float ReceiverSensitivity,
33 const float Frequency,
34 const float combined_antenna_gain,
35 const float path_loss_exponent,
36 const float reference_distance_fspl,
37 const float filter_distance,
38 const bool use_etsi_fading,
39 const float custom_fading_stddev)
73 FVector OtherActorLocation;
75 float ReceivedPower = 0;
79 double tx_height_local = (
mActorOwner->GetSimpleCollisionHalfHeight() * 2.0f) + 2.0;
83 for (
auto &actor_power_pair : ActorList)
91 OtherActorLocation = actor_power_pair.first->GetTransform().GetLocation();
92 double rx_height_local = (actor_power_pair.first->GetSimpleCollisionHalfHeight() * 2.0) + 2.0;
100 double hr = OtherActorLocation.Z + rx_height_local - ref0;
103 source_rel.Z += tx_height_local;
104 FVector dest_rel = OtherActorLocation;
105 dest_rel.Z += rx_height_local;
107 double Distance3d = FVector::Distance(source_rel, dest_rel) / 100.0f;
114 float OtherTransmitPower = actor_power_pair.second;
125 if (ReceivedPower > -1.0 * std::numeric_limits<float>::max())
134 const float OtherTransmitPower,
135 const FVector Source,
136 const FVector Destination,
137 const double Distance3d,
139 const double ht_local,
141 const double hr_local,
142 const double reference_z)
149 FCollisionObjectQueryParams ObjectParams;
151 ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_WorldStatic);
152 ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_PhysicsBody);
153 ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_Vehicle);
154 ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_WorldDynamic);
159 FVector rx = Destination;
164 float loss =
ComputeLoss(OtherActor, Source, Destination, Distance3d, ht, hr, reference_z);
185 if (deltaPercentage < 0.65)
195 else if (deltaPercentage < 0.8)
218 return ReceivedPower;
222 return -1.0 * std::numeric_limits<float>::max();
227 FVector CurrentActorLocation,
232 std::vector<FVector> &vehicle_obstacles)
248 for (
const FHitResult &HitInfo :
HitResult)
267 vehicle_obstacles.emplace_back(location);
283 double V = h * sqrt(2.0 * (d1 + d2) / (
lambda * d1 * d2));
285 double T = std::pow(V - 0.1, 2);
286 return 6.9 + 20.0 * log10(sqrt(T + 1.0) + V - 0.1);
292 const FVector Destination,
293 const double TxHeight,
294 const double RxHeight,
295 const double RxDistance3d,
296 std::vector<FVector> &vehicle_obstacles)
300 FVector pos_tx = Source;
305 FVector pos_rx = Destination;
310 double max_loss = 0.0;
311 for(
auto veh_it = vehicle_obstacles.begin(); veh_it != vehicle_obstacles.end(); veh_it++)
313 double dist_tx_veh = sqrt(std::pow(veh_it->X - pos_tx.X, 2) + std::pow(veh_it->Y - pos_tx.Y, 2));
314 double dist_veh_rx = sqrt(std::pow(pos_rx.X - veh_it->X, 2) + std::pow(pos_rx.Y - veh_it->Y, 2));
316 if(cur_loss >= max_loss)
327 model = path_loss_model;
338 float PathLoss = 0.0;
339 double VehicleBlockageLoss = 0.0;
340 float ShadowFadingLoss = 0.0;
343 std::vector<FVector> vehicle_obstacles;
353 PathLoss = PathLoss +
CalculateNLOSvLoss(Source, Destination, TxHeight, RxHeight, Distance3d, vehicle_obstacles);
372 double free_space_loss = 20.0 * log10(Distance3d) + 20.0 * log10(4.0 * PI /
lambda);
374 PathLoss = free_space_loss +
CalculateNLOSvLoss(Source, Destination, TxHeight, RxHeight, Distance3d, vehicle_obstacles);
380 return PathLoss + ShadowFadingLoss;
388 const AActor *actor = HitInfo.Actor.Get();
390 if (actor !=
nullptr)
407 const AActor *actor = HitInfo.Actor.Get();
408 if (actor !=
nullptr)
414 else if (actor == OtherActor)
428 const AActor *actor = HitInfo.Actor.Get();
430 if (actor !=
nullptr)
439 location = actor->GetTransform().GetLocation();
440 location.Z = location.Z - reference_z + (actor->GetSimpleCollisionHalfHeight() * 2.0) + 2.0;
441 location.Z = location.Z / 100.0f;
443 location.X /= 100.0f;
444 location.Y /= 100.0f;
463 return 36.85f + 30.0f * log10(Distance) + 18.9f * log10(
Frequency_GHz);
469 return 32.4f + 20.0f * log10(Distance) + 20.0f * log10(
Frequency_GHz);
473 return 38.77f + 16.7f * log10(Distance) + 18.2f * log10(
Frequency_GHz);
481 const float Mean = 0.0f;
551 return 40 * log10(Distance3d) - 10 * log10(TxHeight * TxHeight * RxHeight * RxHeight);
558 double d_ground = sqrt(std::pow(Distance3d, 2) - std::pow(TxHeight - RxHeight, 2));
562 double d_refl = sqrt(std::pow(Distance3d, 2) + 4.0 * TxHeight * RxHeight);
565 double sin_theta = (TxHeight + RxHeight) / d_refl;
566 double cos_theta = d_ground / d_refl;
568 double gamma = (sin_theta - sqrt(
epsilon_r - std::pow(cos_theta, 2))) / (sin_theta + sqrt(
epsilon_r - std::pow(cos_theta, 2)));
570 double phi = (2.0 * PI /
lambda * (Distance3d - d_refl));
572 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)));
TSharedPtr< const FActorInfo > carla::rpc::ActorState UWorld * World
FCarlaActor * FindCarlaActor(IdType Id)
ActorType GetActorType() const
float ReceiverSensitivity
float ComputeLoss(AActor *OtherActor, FVector Source, FVector Destination, double Distance3d, double TxHeight, double RxHeight, double reference_z)
如果要追踪光线,则允许预处理的方法。
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)
float GetNormalDistribution(float Mean, float StandardDeviation)