CARLA
Loading...
Searching...
No Matches
PathLossModel.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "Engine/EngineTypes.h"
11
12#include <map>
13#include <vector>
14
15class AActor;
16class UCarlaEpisode;
17class URandomEngine;
18class UWorld;
19
20using ActorPowerMap = std::map<AActor *, float>;
21using ActorPowerPair = std::pair<AActor *, float>;
22
29
35
42
44{
45public:
46 PathLossModel(URandomEngine *random_engine, AActor *Owner);
48 void Simulate(const std::vector<ActorPowerPair> ActorList, UCarlaEpisode *CarlaEpisode, UWorld *World);
50 void SetParams(const float TransmitPower,
51 const float ReceiverSensitivity,
52 const float Frequency,
53 const float combined_antenna_gain,
54 const float path_loss_exponent,
55 const float reference_distance_fspl,
56 const float filter_distance,
57 const bool use_etsi_fading,
58 const float custom_fading_stddev);
59 float GetTransmitPower() { return TransmitPower; }
60 void SetPathLossModel(const EPathLossModel path_loss_model);
61
62private:
63 // diffraction for NLOSv
64 double CalcVehicleLoss(const double d1, const double d2, const double h);
65 // powers
66 float CalculateReceivedPower(AActor *OtherActor,
67 const float OtherTransmitPower,
68 const FVector Source,
69 const FVector Destination,
70 const double Distance3d,
71 const double ht,
72 const double hr,
73 const double reference_z);
74 void EstimatePathStateAndVehicleObstacles(AActor *OtherActor, FVector Source, double TxHeight, double RxHeight, double reference_z, EPathState &state, std::vector<FVector> &vehicle_obstacles);
75 double MakeVehicleBlockageLoss(double TxHeight, double RxHeight, double obj_height, double obj_distance);
76 // variables
79 UWorld *mWorld;
81
84
85 // constants
86 constexpr static float c_speedoflight = 299792458.0; // m/s
87
88 // full two ray path loss
89 const double epsilon_r = 1.02;
90
91 // params
92 // Per-instance so that two V2X / CustomV2X sensors configured with different
93 // frequencies do not clobber each other (these were previously static, which
94 // made the last SetParams win globally and corrupted the path-loss math for
95 // every sensor).
96 double Frequency_GHz{5.9}; // 5.9 GHz
97 double Frequency{5.9 * 1e9}; // Frequency_GHz * 1e9
98 double lambda{c_speedoflight / (5.9 * 1e9)}; // c_speedoflight / Frequency
100 float TransmitPower; // dBm
103 float path_loss_exponent; // no unit, default 2.7;
104 float filter_distance; // in meters default 500.0
108 float combined_antenna_gain; // 10.0 dBi
109
110 // dependent params that are precalculated on setting of params
112
113protected:
114 /// Method that allow to preprocess if the rays will be traced.
115
116 float ComputeLoss(AActor *OtherActor, FVector Source, FVector Destination, double Distance3d, double TxHeight, double RxHeight, double reference_z);
117 bool IsVehicle(const FHitResult &HitInfo);
118 bool GetLocationIfVehicle(const FVector CurrentActorLocation, const FHitResult &HitInfo, const double reference_z, FVector &location);
119 bool HitIsSelfOrOther(const FHitResult &HitInfo, AActor *OtherActor);
120 float CalculatePathLoss_WINNER(EPathState state, double Distance);
121 double CalculateNLOSvLoss(const FVector Source, const FVector Destination, const double TxHeight, const double RxHeight, const double RxDistance3d, std::vector<FVector> &vehicle_obstacles);
122
124
125 // full two ray model
126 double CalculateTwoRayPathLoss(double Distance3d, double TxHeight, double RxHeight);
127 // simplified two ray model
128 float CalculateTwoRayPathLossSimple(double Distance3d, double TxHeight, double RxHeight);
129
130 // functions for precalculation
131 void CalculateFSPL_d0();
132 TArray<FHitResult> HitResult;
133};
std::pair< AActor *, float > ActorPowerPair
EPathState
@ NLOSb
@ NLOSv
@ LOS
std::map< AActor *, float > ActorPowerMap
EScenario
@ Rural
@ Urban
@ Highway
EPathLossModel
@ Winner
@ Geometric
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)
UWorld * mWorld
FVector CurrentActorLocation
double Frequency_GHz
ActorPowerMap GetReceiveActorPowerList()
void Simulate(const std::vector< ActorPowerPair > ActorList, UCarlaEpisode *CarlaEpisode, UWorld *World)
EPathLossModel model
UCarlaEpisode * mCarlaEpisode
float path_loss_exponent
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
EScenario scenario
float custom_fading_stddev
bool GetLocationIfVehicle(const FVector CurrentActorLocation, const FHitResult &HitInfo, const double reference_z, FVector &location)
float CalculateTwoRayPathLossSimple(double Distance3d, double TxHeight, double RxHeight)
float CalculateReceivedPower(AActor *OtherActor, const float OtherTransmitPower, const FVector Source, const FVector Destination, const double Distance3d, const double ht, const double hr, const double reference_z)
double CalculateNLOSvLoss(const FVector Source, const FVector Destination, const double TxHeight, const double RxHeight, const double RxDistance3d, std::vector< FVector > &vehicle_obstacles)
double MakeVehicleBlockageLoss(double TxHeight, double RxHeight, double obj_height, double obj_distance)
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)
AActor * mActorOwner
float reference_distance_fspl
ActorPowerMap mReceiveActorPowerList
float GetTransmitPower()
bool HitIsSelfOrOther(const FHitResult &HitInfo, AActor *OtherActor)
TArray< FHitResult > HitResult
float combined_antenna_gain
const double epsilon_r
float CalculateShadowFading(EPathState state)
bool IsVehicle(const FHitResult &HitInfo)
A simulation episode.