From dd6588d4f03f1a6bc365c92000427642731cfaa5 Mon Sep 17 00:00:00 2001 From: adrian Date: Sat, 26 Nov 2011 18:51:33 +0200 Subject: [PATCH 01/11] Use landcover to determine ground clutter path loss for LOS modified: src/Radio/itm.cpp modified: src/Radio/radio.cxx modified: src/Radio/radio.hxx --- src/Radio/itm.cpp | 32 +++++-- src/Radio/radio.cxx | 223 ++++++++++++++++++++++++++++++++++++++++++-- src/Radio/radio.hxx | 8 +- 3 files changed, 248 insertions(+), 15 deletions(-) diff --git a/src/Radio/itm.cpp b/src/Radio/itm.cpp index 9c2f010fc..79360a201 100644 --- a/src/Radio/itm.cpp +++ b/src/Radio/itm.cpp @@ -1519,6 +1519,8 @@ void point_to_point(double elev[], double rel, // 0.01 .. .99, Fractions of time double &dbloss, char *strmode, + int &p_mode, // propagation mode selector + double (&horizons)[2], // horizon distances int &errnum) { // radio_climate: 1-Equatorial, 2-Continental Subtropical, 3-Maritime Tropical, @@ -1568,22 +1570,38 @@ void point_to_point(double elev[], fs = 32.45 + 20.0 * log10(frq_mhz) + 20.0 * log10(prop.d / 1000.0); q = prop.d - prop.d_L; + horizons[0] = 0.0; + horizons[1] = 0.0; if (int(q) < 0.0) { strcpy(strmode, "Line-Of-Sight Mode"); + p_mode = 0; } else { - if (int(q) == 0.0) + if (int(q) == 0.0) { strcpy(strmode, "Single Horizon"); + horizons[0] = prop.d_Lj[0]; + p_mode = 1; + } - else - if (int(q) > 0.0) + else { + if (int(q) > 0.0) { strcpy(strmode, "Double Horizon"); + horizons[0] = prop.d_Lj[0]; + horizons[1] = prop.d_Lj[1]; + p_mode = 1; + } + } - if (prop.d <= prop.d_Ls || prop.d <= prop.dx) + if (prop.d <= prop.d_Ls || prop.d <= prop.dx) { strcat(strmode, ", Diffraction Dominant"); + p_mode = 1; + } - else - if (prop.d > prop.dx) - strcat(strmode, ", Troposcatter Dominant"); + else { + if (prop.d > prop.dx) { + strcat(strmode, ", Troposcatter Dominant"); + p_mode = 2; + } + } } dbloss = avar(zr, 0.0, zc, prop, propv) + fs; diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index fb73dffed..72fdb15d8 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -26,6 +26,7 @@ #include #include #include "radio.hxx" +#include #include #define WITH_POINT_TO_POINT 1 @@ -213,8 +214,11 @@ double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmiss double rel = 0.90; double dbloss; char strmode[150]; + int p_mode = 0; // propgation mode selector: 0 LOS, 1 diffraction dominant, 2 troposcatter + double horizons[2]; int errnum; + double clutter_loss; // loss due to vegetation and urban double tx_pow = _transmitter_power; double ant_gain = _antenna_gain; double signal = 0.0; @@ -278,6 +282,8 @@ double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmiss double max_points = distance_m / point_distance; deque _elevations; + deque materials; + double elevation_under_pilot = 0.0; if (scenery->get_elevation_m( max_own_pos, elevation_under_pilot, NULL )) { @@ -306,23 +312,39 @@ double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmiss while (_elevations.size() <= e_size) { probe_distance += point_distance; SGGeod probe = SGGeod::fromGeoc(center.advanceRadM( course, probe_distance )); - + const SGMaterial *mat = 0; double elevation_m = 0.0; - if (scenery->get_elevation_m( probe, elevation_m, NULL )) { + if (scenery->get_elevation_m( probe, elevation_m, &mat )) { if((transmission_type == 3) || (transmission_type == 4)) { _elevations.push_back(elevation_m); + if(mat) { + const std::vector mat_names = mat->get_names(); + materials.push_back(mat_names[0]); + } + else { + materials.push_back("None"); + } } else { _elevations.push_front(elevation_m); + if(mat) { + const std::vector mat_names = mat->get_names(); + materials.push_front(mat_names[0]); + } + else { + materials.push_front("None"); + } } } else { if((transmission_type == 3) || (transmission_type == 4)) { - _elevations.push_back(elevation_m); + _elevations.push_back(0.0); + materials.push_back("None"); } else { - _elevations.push_front(0.0); + _elevations.push_front(0.0); + materials.push_front("None"); } } } @@ -367,25 +389,205 @@ double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmiss // the sender and receiver roles are switched point_to_point(itm_elev, receiver_height, transmitter_height, eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate, - pol, conf, rel, dbloss, strmode, errnum); + pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum); } else { point_to_point(itm_elev, transmitter_height, receiver_height, eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate, - pol, conf, rel, dbloss, strmode, errnum); + pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum); } SG_LOG(SG_GENERAL, SG_BULK, "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum); cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl; + clutterLoss(frq_mhz, distance_m, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss); + cerr << "Clutter loss: " << clutter_loss << endl; //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used // return -1; - signal = link_budget - dbloss; + signal = link_budget - dbloss - clutter_loss; return signal; } +/*** Calculate losses due to vegetation and urban clutter (WIP) +* We are only worried about clutter loss, terrain influence +* on the first Fresnel zone is calculated in the ITM functions +***/ +void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deque materials, + double transmitter_height, double receiver_height, int p_mode, + double horizons[], double &clutter_loss) { + + if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone + int j=1; // first point is TX elevation, last is RX elevation + for (int k=3;k < (int)itm_elev[0];k++) { + + double clutter_height = 0.0; // clutter height hard-coded to 15 for now + double clutter_density = 0.0; // percent of reflected wave + get_material_properties(materials[j-1], clutter_height, clutter_density); + //cerr << "Clutter:: material: " << materials[j-1] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; + // First Fresnel radius + double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) ); + //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 + + double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); + double d1 = j * itm_elev[1]; + if (fabs(min_elev - itm_elev[2]) <= 0.0001) + d1 = (itm_elev[0] - j) * itm_elev[1]; + double ray_height = (grad * d1) + min_elev; + //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad; + double intrusion = fabs(clearance); + //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { + clutter_loss +=0.0; + } + else if (clearance < 0 && (intrusion < clutter_height)) { + + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + } + else if (clearance < 0 && (intrusion > clutter_height)) { + clutter_loss += clutter_density * (clutter_height / (frs_rad *2 ) ) * freq/100; + } + else { + clutter_loss += 0.0; + } + j++; + } + + } + else if (p_mode == 1) { // diffraction + + if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point + + } + else { // double horizon: same as single horizon, except there are 3 segments + + } + } + else if (p_mode == 2) { // troposcatter: use the first smooth earth horizon as mid point + + } + +} + +/*** Material properties database +* height: median clutter height +* density: radiowave attenuation factor +***/ +void FGRadio::get_material_properties(string mat_name, double &height, double &density) { + + if(mat_name == "Landmass") { + height = 15.0; + density = 0.2; + } + + else if(mat_name == "SomeSort") { + height = 15.0; + density = 0.2; + } + + else if(mat_name == "Island") { + height = 15.0; + density = 0.2; + } + else if(mat_name == "Default") { + height = 15.0; + density = 0.2; + } + else if(mat_name == "EvergreenBroadCover") { + height = 20.0; + density = 0.2; + } + else if(mat_name == "EvergreenForest") { + height = 20.0; + density = 0.2; + } + else if(mat_name == "DeciduousBroadCover") { + height = 15.0; + density = 0.3; + } + else if(mat_name == "DeciduousForest") { + height = 15.0; + density = 0.3; + } + else if(mat_name == "MixedForestCover") { + height = 20.0; + density = 0.25; + } + else if(mat_name == "MixedForest") { + height = 15.0; + density = 0.25; + } + else if(mat_name == "RainForest") { + height = 25.0; + density = 0.55; + } + else if(mat_name == "EvergreenNeedleCover") { + height = 15.0; + density = 0.2; + } + else if(mat_name == "WoodedTundraCover") { + height = 5.0; + density = 0.15; + } + else if(mat_name == "DeciduousNeedleCover") { + height = 5.0; + density = 0.2; + } + else if(mat_name == "ScrubCover") { + height = 3.0; + density = 0.15; + } + else if(mat_name == "BuiltUpCover") { + height = 30.0; + density = 0.7; + } + else if(mat_name == "Urban") { + height = 30.0; + density = 0.7; + } + else if(mat_name == "Construction") { + height = 30.0; + density = 0.7; + } + else if(mat_name == "Industrial") { + height = 30.0; + density = 0.7; + } + else if(mat_name == "Port") { + height = 30.0; + density = 0.7; + } + else if(mat_name == "Town") { + height = 10.0; + density = 0.5; + } + else if(mat_name == "SubUrban") { + height = 10.0; + density = 0.5; + } + else if(mat_name == "CropWoodCover") { + height = 10.0; + density = 0.1; + } + else if(mat_name == "CropWood") { + height = 10.0; + density = 0.1; + } + else if(mat_name == "AgroForest") { + height = 10.0; + density = 0.1; + } + else { + height = 0.0; + density = 0.0; + } + +} + /*** implement simple LOS propagation model (WIP) ***/ double FGRadio::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) { @@ -453,3 +655,10 @@ double FGRadio::LOS_calculate_attenuation(SGGeod pos, double freq, int transmiss return signal; } + +/*** Material properties database +***/ +void FGRadio::set_material_properties() { + + +} diff --git a/src/Radio/radio.hxx b/src/Radio/radio.hxx index 6f37a5201..d6cc77e82 100644 --- a/src/Radio/radio.hxx +++ b/src/Radio/radio.hxx @@ -23,7 +23,7 @@ #include #include - +#include #include
#include @@ -43,10 +43,16 @@ private: double _receiver_sensitivity; double _transmitter_power; double _antenna_gain; + std::map _mat_database; int _propagation_model; /// 0 none, 1 round Earth, 2 ITM double ITM_calculate_attenuation(SGGeod tx_pos, double freq, int ground_to_air); double LOS_calculate_attenuation(SGGeod tx_pos, double freq, int ground_to_air); + void clutterLoss(double freq, double distance_m, double itm_elev[], std::deque materials, + double transmitter_height, double receiver_height, int p_mode, + double horizons[], double &clutter_loss); + void set_material_properties(); + void get_material_properties(string mat_name, double &height, double &density); public: From 6b24aa0c14f92d268faead3cfe1dc3fd601898dd Mon Sep 17 00:00:00 2001 From: adrian Date: Sun, 27 Nov 2011 12:53:30 +0200 Subject: [PATCH 02/11] Add clutter loss for single horizon diffraction --- src/Radio/radio.cxx | 108 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 14 deletions(-) diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index 72fdb15d8..314e40c63 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -376,15 +376,6 @@ double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmiss //cerr << "ITM:: itm_elev: " << _elevations[i] << endl; } - - /** first Fresnel zone radius - frequency in the middle of the bandplan, more accuracy is not necessary - */ - double fz_clr= 8.657 * sqrt(distance_m / 0.125); - - // TODO: If we clear the first Fresnel zone, we are into line of sight territory - - // else we need to calculate point to point link loss if((transmission_type == 3) || (transmission_type == 4)) { // the sender and receiver roles are switched point_to_point(itm_elev, receiver_height, transmitter_height, @@ -422,23 +413,25 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq int j=1; // first point is TX elevation, last is RX elevation for (int k=3;k < (int)itm_elev[0];k++) { - double clutter_height = 0.0; // clutter height hard-coded to 15 for now + double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[j-1], clutter_height, clutter_density); //cerr << "Clutter:: material: " << materials[j-1] << " height: " << clutter_height << ", density: " << clutter_density << endl; double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) ); + //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); double d1 = j * itm_elev[1]; - if (fabs(min_elev - itm_elev[2]) <= 0.0001) + if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) { d1 = (itm_elev[0] - j) * itm_elev[1]; + } double ray_height = (grad * d1) + min_elev; - //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; - double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad; + cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; double intrusion = fabs(clearance); //cerr << "Clutter:: clearance: " << clearance << endl; if (clearance >= 0) { @@ -449,7 +442,7 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; } else if (clearance < 0 && (intrusion > clutter_height)) { - clutter_loss += clutter_density * (clutter_height / (frs_rad *2 ) ) * freq/100; + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; } else { clutter_loss += 0.0; @@ -461,6 +454,93 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq else if (p_mode == 1) { // diffraction if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point + int num_points_1st = (int)floor( horizons[1] * (double)itm_elev[0] / distance_m ); + int num_points_2nd = (int)floor( (distance_m - horizons[1]) * (double)itm_elev[0] / distance_m ); + int last = 1; + /** perform the first pass */ + + int j=1; // first point is TX elevation, last is obstruction elevation + for (int k=3;k < num_points_1st ;k++) { + + double clutter_height = 0.0; // mean clutter height for a certain terrain type + double clutter_density = 0.0; // percent of reflected wave + get_material_properties(materials[j-1], clutter_height, clutter_density); + //cerr << "Clutter:: material: " << materials[j-1] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m; + // First Fresnel radius + double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); + + //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 + + double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height); + double d1 = j * itm_elev[1]; + if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) { + d1 = (num_points_1st - j) * itm_elev[1]; + } + double ray_height = (grad * d1) + min_elev; + //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; + double intrusion = fabs(clearance); + //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { + clutter_loss +=0.0; + } + else if (clearance < 0 && (intrusion < clutter_height)) { + + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + } + else if (clearance < 0 && (intrusion > clutter_height)) { + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + } + else { + clutter_loss += 0.0; + } + j++; + last = k+1; + } + + /** and the second pass */ + + int l =1; + for (int k=last;k < num_points_2nd ;k++) { + + double clutter_height = 0.0; // mean clutter height for a certain terrain type + double clutter_density = 0.0; // percent of reflected wave + get_material_properties(materials[j-1], clutter_height, clutter_density); + //cerr << "Clutter:: material: " << materials[j-1] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[last] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; + // First Fresnel radius + double frs_rad = 548 * sqrt( (l * itm_elev[1] * (num_points_2nd - l) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); + + //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 + + double min_elev = SGMiscd::min(itm_elev[last] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); + double d1 = l * itm_elev[1]; + if ( (itm_elev[last] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) { + d1 = (num_points_2nd - l) * itm_elev[1]; + } + double ray_height = (grad * d1) + min_elev; + //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; + double intrusion = fabs(clearance); + //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { + clutter_loss +=0.0; + } + else if (clearance < 0 && (intrusion < clutter_height)) { + + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + } + else if (clearance < 0 && (intrusion > clutter_height)) { + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + } + else { + clutter_loss += 0.0; + } + j++; + } } else { // double horizon: same as single horizon, except there are 3 segments From 4c0c79fa4cb6a86d765382186b05542888a03b19 Mon Sep 17 00:00:00 2001 From: adrian Date: Mon, 28 Nov 2011 07:37:37 +0200 Subject: [PATCH 03/11] Decouple material index from other variables --- src/Radio/radio.cxx | 210 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 176 insertions(+), 34 deletions(-) diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index 314e40c63..6f7a7601f 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -218,7 +218,7 @@ double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmiss double horizons[2]; int errnum; - double clutter_loss; // loss due to vegetation and urban + double clutter_loss = 0.0; // loss due to vegetation and urban double tx_pow = _transmitter_power; double ant_gain = _antenna_gain; double signal = 0.0; @@ -305,7 +305,7 @@ double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmiss SG_LOG(SG_GENERAL, SG_BULK, "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters"); - //cerr << "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters" << endl; + cerr << "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters" << endl; unsigned int e_size = (deque::size_type)max_points; @@ -410,32 +410,33 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq double horizons[], double &clutter_loss) { if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone + int mat = 0; int j=1; // first point is TX elevation, last is RX elevation for (int k=3;k < (int)itm_elev[0];k++) { double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave - get_material_properties(materials[j-1], clutter_height, clutter_density); - //cerr << "Clutter:: material: " << materials[j-1] << " height: " << clutter_height << ", density: " << clutter_density << endl; - double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; + get_material_properties(materials[mat], clutter_height, clutter_density); + //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 1] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) ); //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 - double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); + double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 1] + receiver_height); double d1 = j * itm_elev[1]; - if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) { + if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 1] + receiver_height) ) { d1 = (itm_elev[0] - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; - cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; double intrusion = fabs(clearance); //cerr << "Clutter:: clearance: " << clearance << endl; if (clearance >= 0) { - clutter_loss +=0.0; + // no losses } else if (clearance < 0 && (intrusion < clutter_height)) { @@ -445,37 +446,38 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; } else { - clutter_loss += 0.0; + // no losses } j++; + mat++; } } else if (p_mode == 1) { // diffraction if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point - int num_points_1st = (int)floor( horizons[1] * (double)itm_elev[0] / distance_m ); - int num_points_2nd = (int)floor( (distance_m - horizons[1]) * (double)itm_elev[0] / distance_m ); + int num_points_1st = (int)floor( horizons[0] * (double)itm_elev[0] / distance_m ); + int num_points_2nd = (int)floor( (distance_m - horizons[0]) * (double)itm_elev[0] / distance_m ); int last = 1; /** perform the first pass */ - - int j=1; // first point is TX elevation, last is obstruction elevation + int mat = 0; + int j=1; // first point is TX elevation, 2nd is obstruction elevation for (int k=3;k < num_points_1st ;k++) { double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave - get_material_properties(materials[j-1], clutter_height, clutter_density); - //cerr << "Clutter:: material: " << materials[j-1] << " height: " << clutter_height << ", density: " << clutter_density << endl; - double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m; + get_material_properties(materials[mat], clutter_height, clutter_density); + //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 1] + clutter_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 - double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height); + double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 1] + clutter_height); double d1 = j * itm_elev[1]; - if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) { + if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 1] + clutter_height) ) { d1 = (num_points_1st - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; @@ -484,7 +486,7 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq double intrusion = fabs(clearance); //cerr << "Clutter:: clearance: " << clearance << endl; if (clearance >= 0) { - clutter_loss +=0.0; + // no losses } else if (clearance < 0 && (intrusion < clutter_height)) { @@ -494,31 +496,32 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; } else { - clutter_loss += 0.0; + // no losses } j++; - last = k+1; + mat++; + last = k; } /** and the second pass */ - int l =1; - for (int k=last;k < num_points_2nd ;k++) { + int l =1; // first point is diffraction edge, 2nd the RX elevation + for (int k=last+1;k < num_points_2nd ;k++) { double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave - get_material_properties(materials[j-1], clutter_height, clutter_density); - //cerr << "Clutter:: material: " << materials[j-1] << " height: " << clutter_height << ", density: " << clutter_density << endl; - double grad = fabs(itm_elev[last] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; + get_material_properties(materials[mat], clutter_height, clutter_density); + //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[last] + clutter_height - itm_elev[(int)itm_elev[0] + 1] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (l * itm_elev[1] * (num_points_2nd - l) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 - double min_elev = SGMiscd::min(itm_elev[last] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); + double min_elev = SGMiscd::min(itm_elev[last] + clutter_height, itm_elev[(int)itm_elev[0] + 1] + receiver_height); double d1 = l * itm_elev[1]; - if ( (itm_elev[last] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) { + if ( (itm_elev[last] + clutter_height) > (itm_elev[(int)itm_elev[0] + 1] + receiver_height) ) { d1 = (num_points_2nd - l) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; @@ -527,7 +530,7 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq double intrusion = fabs(clearance); //cerr << "Clutter:: clearance: " << clearance << endl; if (clearance >= 0) { - clutter_loss +=0.0; + // no losses } else if (clearance < 0 && (intrusion < clutter_height)) { @@ -537,23 +540,162 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; } else { - clutter_loss += 0.0; + // no losses } j++; + l++; + mat++; } } else { // double horizon: same as single horizon, except there are 3 segments + int num_points_1st = (int)floor( horizons[0] * (double)itm_elev[0] / distance_m ); + int num_points_2nd = (int)floor( (horizons[1] - horizons[0]) * (double)itm_elev[0] / distance_m ); + int num_points_3rd = (int)floor( (distance_m - horizons[1]) * (double)itm_elev[0] / distance_m ); + int last = 1; + /** perform the first pass */ + int mat = 0; + int j=1; // first point is TX elevation, 2nd is obstruction elevation + for (int k=3;k < num_points_1st ;k++) { + + double clutter_height = 0.0; // mean clutter height for a certain terrain type + double clutter_density = 0.0; // percent of reflected wave + get_material_properties(materials[mat], clutter_height, clutter_density); + //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 1] + clutter_height) / distance_m; + // First Fresnel radius + double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); + + //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 + + double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 1] + clutter_height); + double d1 = j * itm_elev[1]; + if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 1] + clutter_height) ) { + d1 = (num_points_1st - j) * itm_elev[1]; + } + double ray_height = (grad * d1) + min_elev; + //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; + double intrusion = fabs(clearance); + //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { + // no losses + } + else if (clearance < 0 && (intrusion < clutter_height)) { + + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + } + else if (clearance < 0 && (intrusion > clutter_height)) { + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + } + else { + // no losses + } + j++; + last = k; + } + + /** and the second pass */ + + int l =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation + for (int k=last;k < num_points_2nd ;k++) { + + double clutter_height = 0.0; // mean clutter height for a certain terrain type + double clutter_density = 0.0; // percent of reflected wave + get_material_properties(materials[mat], clutter_height, clutter_density); + //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[last] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 1] + clutter_height) / distance_m; + // First Fresnel radius + double frs_rad = 548 * sqrt( (l * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); + + //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 + + double min_elev = SGMiscd::min(itm_elev[last] + clutter_height, itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height); + double d1 = l * itm_elev[1]; + if ( (itm_elev[last] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 1] + clutter_height) ) { + d1 = (num_points_2nd - l) * itm_elev[1]; + } + double ray_height = (grad * d1) + min_elev; + //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; + double intrusion = fabs(clearance); + //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { + // no losses + } + else if (clearance < 0 && (intrusion < clutter_height)) { + + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + } + else if (clearance < 0 && (intrusion > clutter_height)) { + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + } + else { + // no losses + } + j++; + l++; + mat++; + last = k; + } + + /** third and final pass */ + + int m =1; // first point is 2nd obstruction elevation, 3rd is RX elevation + for (int k=last;k < num_points_3rd ;k++) { + + double clutter_height = 0.0; // mean clutter height for a certain terrain type + double clutter_density = 0.0; // percent of reflected wave + get_material_properties(materials[mat], clutter_height, clutter_density); + //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[last] + clutter_height - itm_elev[(int)itm_elev[0] + 1] + receiver_height) / distance_m; + // First Fresnel radius + double frs_rad = 548 * sqrt( (m * itm_elev[1] * (num_points_3rd - m) * itm_elev[1] / 1000000) / ( num_points_3rd * itm_elev[1] * freq / 1000) ); + + //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 + + double min_elev = SGMiscd::min(itm_elev[last] + clutter_height, itm_elev[(int)itm_elev[0] + 1] + receiver_height); + double d1 = m * itm_elev[1]; + if ( (itm_elev[last] + clutter_height) > (itm_elev[(int)itm_elev[0] + 1] + receiver_height) ) { + d1 = (num_points_3rd - m) * itm_elev[1]; + } + double ray_height = (grad * d1) + min_elev; + //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; + double intrusion = fabs(clearance); + //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { + // no losses + } + else if (clearance < 0 && (intrusion < clutter_height)) { + + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + } + else if (clearance < 0 && (intrusion > clutter_height)) { + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + } + else { + // no losses + } + j++; + m++; + mat++; + last = k+1; + } + } } - else if (p_mode == 2) { // troposcatter: use the first smooth earth horizon as mid point - + else if (p_mode == 2) { // troposcatter: ignore ground clutter for now... + clutter_loss = 0.0; } } -/*** Material properties database +/*** Temporary material properties database * height: median clutter height * density: radiowave attenuation factor ***/ From d23fbc3c134b8d417056ca7abaf6f950a194a964 Mon Sep 17 00:00:00 2001 From: adrian Date: Mon, 28 Nov 2011 08:31:04 +0200 Subject: [PATCH 04/11] make clutter loss calculations switchable via property --- src/Radio/radio.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index 6f7a7601f..f9b415067 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -381,18 +381,20 @@ double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmiss point_to_point(itm_elev, receiver_height, transmitter_height, eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate, pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum); - + if( fgGetBool( "/sim/radio/use-clutter-attenuation", false ) ) + clutterLoss(frq_mhz, distance_m, itm_elev, materials, receiver_height, transmitter_height, p_mode, horizons, clutter_loss); } else { point_to_point(itm_elev, transmitter_height, receiver_height, eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate, pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum); + if( fgGetBool( "/sim/radio/use-clutter-attenuation", false ) ) + clutterLoss(frq_mhz, distance_m, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss); } SG_LOG(SG_GENERAL, SG_BULK, "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum); cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl; - clutterLoss(frq_mhz, distance_m, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss); cerr << "Clutter loss: " << clutter_loss << endl; //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used // return -1; From 6be68f475daad1e663396dc199950a82357e9f16 Mon Sep 17 00:00:00 2001 From: adrian Date: Mon, 28 Nov 2011 08:36:56 +0200 Subject: [PATCH 05/11] remove unnecessary function --- src/Radio/radio.cxx | 7 +------ src/Radio/radio.hxx | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index f9b415067..6f056a297 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -880,9 +880,4 @@ double FGRadio::LOS_calculate_attenuation(SGGeod pos, double freq, int transmiss } -/*** Material properties database -***/ -void FGRadio::set_material_properties() { - - -} + diff --git a/src/Radio/radio.hxx b/src/Radio/radio.hxx index d6cc77e82..2e67c5aef 100644 --- a/src/Radio/radio.hxx +++ b/src/Radio/radio.hxx @@ -51,7 +51,6 @@ private: void clutterLoss(double freq, double distance_m, double itm_elev[], std::deque materials, double transmitter_height, double receiver_height, int p_mode, double horizons[], double &clutter_loss); - void set_material_properties(); void get_material_properties(string mat_name, double &height, double &density); public: From a6b9beca9d9770c7589d4e1415afb750ce30c514 Mon Sep 17 00:00:00 2001 From: adrian Date: Mon, 28 Nov 2011 10:38:58 +0200 Subject: [PATCH 06/11] rename FGRadio to FGRadioTransmission, add RX and TX antenna heights --- src/ATC/trafficcontrol.cxx | 2 +- src/Radio/radio.cxx | 22 +++++++++++++--------- src/Radio/radio.hxx | 7 ++++++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index cf0b16f31..e42def60d 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -746,7 +746,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent, if( fgGetBool( "/sim/radio/use-itm-attenuation", false ) ) { //cerr << "Using ITM radio propagation" << endl; - FGRadio* radio = new FGRadio(); + FGRadioTransmission* radio = new FGRadioTransmission(); SGGeod sender_pos; double sender_alt_ft, sender_alt; if(ground_to_air) { diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index 6f056a297..ac278bf2f 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -33,7 +33,7 @@ #include "itm.cpp" -FGRadio::FGRadio() { +FGRadioTransmission::FGRadioTransmission() { /** radio parameters (which should probably be set for each radio) */ @@ -53,6 +53,10 @@ FGRadio::FGRadio() { **/ _transmitter_power = 43.0; + _tx_antenna_height = 2.0; // TX antenna height above ground level + + _rx_antenna_height = 2.0; // RX antenna height above ground level + /** pilot plane's antenna gain + AI aircraft antenna gain * real-life gain for conventional monopole/dipole antenna **/ @@ -66,7 +70,7 @@ FGRadio::~FGRadio() } -double FGRadio::getFrequency(int radio) { +double FGRadioTransmission::getFrequency(int radio) { double freq = 118.0; switch (radio) { case 1: @@ -84,13 +88,13 @@ double FGRadio::getFrequency(int radio) { /*** TODO: receive multiplayer chat message and voice ***/ -void FGRadio::receiveChat(SGGeod tx_pos, double freq, string text, int ground_to_air) { +void FGRadioTransmission::receiveChat(SGGeod tx_pos, double freq, string text, int ground_to_air) { } /*** TODO: receive navaid ***/ -double FGRadio::receiveNav(SGGeod tx_pos, double freq, int transmission_type) { +double FGRadioTransmission::receiveNav(SGGeod tx_pos, double freq, int transmission_type) { // typical VOR/LOC transmitter power appears to be 200 Watt ~ 53 dBm // vor/loc typical sensitivity between -107 and -101 dBm @@ -108,7 +112,7 @@ double FGRadio::receiveNav(SGGeod tx_pos, double freq, int transmission_type) { /*** Receive ATC radio communication as text ***/ -void FGRadio::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_air) { +void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_air) { double comm1 = getFrequency(1); @@ -193,7 +197,7 @@ void FGRadio::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_ /*** Implement radio attenuation based on the Longley-Rice propagation model ***/ -double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmission_type) { +double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, int transmission_type) { @@ -407,7 +411,7 @@ double FGRadio::ITM_calculate_attenuation(SGGeod pos, double freq, int transmiss * We are only worried about clutter loss, terrain influence * on the first Fresnel zone is calculated in the ITM functions ***/ -void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deque materials, +void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm_elev[], deque materials, double transmitter_height, double receiver_height, int p_mode, double horizons[], double &clutter_loss) { @@ -701,7 +705,7 @@ void FGRadio::clutterLoss(double freq, double distance_m, double itm_elev[], deq * height: median clutter height * density: radiowave attenuation factor ***/ -void FGRadio::get_material_properties(string mat_name, double &height, double &density) { +void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) { if(mat_name == "Landmass") { height = 15.0; @@ -814,7 +818,7 @@ void FGRadio::get_material_properties(string mat_name, double &height, double &d /*** implement simple LOS propagation model (WIP) ***/ -double FGRadio::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) { +double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) { double frq_mhz; if( (freq < 118.0) || (freq > 137.0) ) frq_mhz = 125.0; // sane value, middle of bandplan diff --git a/src/Radio/radio.hxx b/src/Radio/radio.hxx index 2e67c5aef..25d4144cf 100644 --- a/src/Radio/radio.hxx +++ b/src/Radio/radio.hxx @@ -33,7 +33,7 @@ using std::string; -class FGRadio +class FGRadioTransmission { private: bool isOperable() const @@ -42,6 +42,8 @@ private: double _receiver_sensitivity; double _transmitter_power; + double _tx_antenna_height; + double _rx_antenna_height; double _antenna_gain; std::map _mat_database; @@ -62,6 +64,9 @@ public: void setFrequency(double freq, int radio); double getFrequency(int radio); void setTxPower(double txpower) { _transmitter_power = txpower; }; + void setRxSensitivity(double sensitivity) { _receiver_sensitivity = sensitivity; }; + void setTxAntennaHeight(double tx_antenna_height) { _tx_antenna_height = tx_antenna_height; }; + void setRxAntennaHeight(double rx_antenna_height) { _rx_antenna_height = rx_antenna_height; }; void setPropagationModel(int model) { _propagation_model = model; }; // transmission_type: 0 for air to ground 1 for ground to air, 2 for air to air, 3 for pilot to ground, 4 for pilot to air void receiveATC(SGGeod tx_pos, double freq, string text, int transmission_type); From d988e4c4ad2366a8eb6354d8a4973f8f12ea0fbe Mon Sep 17 00:00:00 2001 From: adrian Date: Mon, 28 Nov 2011 10:49:05 +0200 Subject: [PATCH 07/11] forgot about constructor and destructor --- src/Radio/radio.cxx | 2 +- src/Radio/radio.hxx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index ac278bf2f..62e023178 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -65,7 +65,7 @@ FGRadioTransmission::FGRadioTransmission() { } -FGRadio::~FGRadio() +FGRadioTransmission::~FGRadioTransmission() { } diff --git a/src/Radio/radio.hxx b/src/Radio/radio.hxx index 25d4144cf..da84313fc 100644 --- a/src/Radio/radio.hxx +++ b/src/Radio/radio.hxx @@ -57,8 +57,8 @@ private: public: - FGRadio(); - ~FGRadio(); + FGRadioTransmission(); + ~FGRadioTransmission(); void setFrequency(double freq, int radio); From dcc915e5bd8bfe0272182c0084bcc321467d19cf Mon Sep 17 00:00:00 2001 From: adrian Date: Tue, 29 Nov 2011 15:00:49 +0200 Subject: [PATCH 08/11] Add separate fields for receiver and transmitter: - antenna gain and cable losses will be set individualy - Fix the calculations of the number of elevation points - Improve clutter loss calculations to yield sane results --- src/Radio/radio.cxx | 155 +++++++++++++++++++++++++------------------- src/Radio/radio.hxx | 5 ++ 2 files changed, 92 insertions(+), 68 deletions(-) diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index 62e023178..3ea219ff7 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -23,6 +23,7 @@ #endif #include +#include #include #include #include "radio.hxx" @@ -61,8 +62,15 @@ FGRadioTransmission::FGRadioTransmission() { * real-life gain for conventional monopole/dipole antenna **/ _antenna_gain = 2.0; - _propagation_model = 2; // choose between models via option: realistic radio on/off + _rx_antenna_gain = 1.0; + _tx_antenna_gain = 1.0; + + _rx_line_losses = 2.0; // to be configured for each station + _tx_line_losses = 2.0; + + _propagation_model = 2; // choose between models via option: realistic radio on/off + _terrain_sampling_distance = 90.0; // regular SRTM is 90 meters } FGRadioTransmission::~FGRadioTransmission() @@ -266,7 +274,7 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i SGGeoc sender_pos_c = SGGeoc::fromGeod( sender_pos ); //cerr << "ITM:: sender Lat: " << parent->getLatitude() << ", Lon: " << parent->getLongitude() << ", Alt: " << sender_alt << endl; - double point_distance= 90.0; // regular SRTM is 90 meters + double point_distance= _terrain_sampling_distance; double course = SGGeodesy::courseRad(own_pos_c, sender_pos_c); double distance_m = SGGeodesy::distanceM(own_pos, sender_pos); double probe_distance = 0.0; @@ -284,7 +292,9 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i } - double max_points = distance_m / point_distance; + int max_points = (int)floor(distance_m / point_distance); + double delta_last = fmod(distance_m, point_distance); + deque _elevations; deque materials; @@ -354,11 +364,13 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i } if((transmission_type == 3) || (transmission_type == 4)) { _elevations.push_front(elevation_under_pilot); - _elevations.push_back(elevation_under_sender); + if (delta_last > (point_distance / 2) ) // only add last point if it's farther than half point_distance + _elevations.push_back(elevation_under_sender); } else { _elevations.push_back(elevation_under_pilot); - _elevations.push_front(elevation_under_sender); + if (delta_last > (point_distance / 2) ) + _elevations.push_front(elevation_under_sender); } @@ -415,25 +427,26 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double transmitter_height, double receiver_height, int p_mode, double horizons[], double &clutter_loss) { + distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone int mat = 0; int j=1; // first point is TX elevation, last is RX elevation - for (int k=3;k < (int)itm_elev[0];k++) { + for (int k=3;k < (int)(itm_elev[0]) + 2;k++) { double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; - double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 1] + receiver_height) / distance_m; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) ); - + assert(frs_rad > 0); //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 - double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 1] + receiver_height); + double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); double d1 = j * itm_elev[1]; - if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 1] + receiver_height) ) { + if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) { d1 = (itm_elev[0] - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; @@ -462,28 +475,30 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm else if (p_mode == 1) { // diffraction if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point - int num_points_1st = (int)floor( horizons[0] * (double)itm_elev[0] / distance_m ); - int num_points_2nd = (int)floor( (distance_m - horizons[0]) * (double)itm_elev[0] / distance_m ); + int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m ); + int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m ); + cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl; int last = 1; /** perform the first pass */ int mat = 0; int j=1; // first point is TX elevation, 2nd is obstruction elevation - for (int k=3;k < num_points_1st ;k++) { - + for (int k=3;k < num_points_1st + 2;k++) { + if (num_points_1st < 1) + break; double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; - double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 1] + clutter_height) / distance_m; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m; // First Fresnel radius - double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); - + double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); + assert(frs_rad > 0); //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 - double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 1] + clutter_height); + double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height); double d1 = j * itm_elev[1]; - if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 1] + clutter_height) ) { + if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) { d1 = (num_points_1st - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; @@ -510,25 +525,26 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm } /** and the second pass */ - - int l =1; // first point is diffraction edge, 2nd the RX elevation - for (int k=last+1;k < num_points_2nd ;k++) { - + mat +=1; + j =1; // first point is diffraction edge, 2nd the RX elevation + for (int k=last+2;k < (int)(itm_elev[0]) + 2;k++) { + if (num_points_2nd < 1) + break; double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; - double grad = fabs(itm_elev[last] + clutter_height - itm_elev[(int)itm_elev[0] + 1] + receiver_height) / distance_m; + double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius - double frs_rad = 548 * sqrt( (l * itm_elev[1] * (num_points_2nd - l) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); - + double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); + assert(frs_rad > 0); //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 - double min_elev = SGMiscd::min(itm_elev[last] + clutter_height, itm_elev[(int)itm_elev[0] + 1] + receiver_height); - double d1 = l * itm_elev[1]; - if ( (itm_elev[last] + clutter_height) > (itm_elev[(int)itm_elev[0] + 1] + receiver_height) ) { - d1 = (num_points_2nd - l) * itm_elev[1]; + double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); + double d1 = j * itm_elev[1]; + if ( (itm_elev[last+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) { + d1 = (num_points_2nd - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; @@ -549,36 +565,38 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm // no losses } j++; - l++; mat++; } } else { // double horizon: same as single horizon, except there are 3 segments - int num_points_1st = (int)floor( horizons[0] * (double)itm_elev[0] / distance_m ); - int num_points_2nd = (int)floor( (horizons[1] - horizons[0]) * (double)itm_elev[0] / distance_m ); - int num_points_3rd = (int)floor( (distance_m - horizons[1]) * (double)itm_elev[0] / distance_m ); + int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m ); + int num_points_2nd = (int)ceil( (horizons[1] - horizons[0]) * itm_elev[0] / distance_m ); + int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd; + + cerr << "Clutter:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl; int last = 1; /** perform the first pass */ int mat = 0; int j=1; // first point is TX elevation, 2nd is obstruction elevation - for (int k=3;k < num_points_1st ;k++) { - + for (int k=3;k < num_points_1st +2;k++) { + if (num_points_1st < 1) + break; double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; - double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 1] + clutter_height) / distance_m; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); - + assert(frs_rad > 0); //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 - double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 1] + clutter_height); + double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height); double d1 = j * itm_elev[1]; - if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 1] + clutter_height) ) { + if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) { d1 = (num_points_1st - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; @@ -602,27 +620,28 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm j++; last = k; } - + mat +=1; /** and the second pass */ - - int l =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation - for (int k=last;k < num_points_2nd ;k++) { - + int last2=1; + j =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation + for (int k=last+2;k < num_points_1st + num_points_2nd +2;k++) { + if (num_points_2nd < 1) + break; double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; - double grad = fabs(itm_elev[last] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 1] + clutter_height) / distance_m; + double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m; // First Fresnel radius - double frs_rad = 548 * sqrt( (l * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); - - //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); + //cerr << "Clutter:: fresnel radius: " << frs_rad << " points2: " << num_points_2nd << " j: " << j << endl; + assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 - double min_elev = SGMiscd::min(itm_elev[last] + clutter_height, itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height); - double d1 = l * itm_elev[1]; - if ( (itm_elev[last] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 1] + clutter_height) ) { - d1 = (num_points_2nd - l) * itm_elev[1]; + double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height); + double d1 = j * itm_elev[1]; + if ( (itm_elev[last+1] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) ) { + d1 = (num_points_2nd - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; @@ -643,31 +662,32 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm // no losses } j++; - l++; mat++; - last = k; + last2 = k; } /** third and final pass */ - - int m =1; // first point is 2nd obstruction elevation, 3rd is RX elevation - for (int k=last;k < num_points_3rd ;k++) { - + mat +=1; + j =1; // first point is 2nd obstruction elevation, 3rd is RX elevation + for (int k=last2+2;k < (int)itm_elev[0] + 2;k++) { + if (num_points_3rd < 1) + break; double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; - double grad = fabs(itm_elev[last] + clutter_height - itm_elev[(int)itm_elev[0] + 1] + receiver_height) / distance_m; + double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius - double frs_rad = 548 * sqrt( (m * itm_elev[1] * (num_points_3rd - m) * itm_elev[1] / 1000000) / ( num_points_3rd * itm_elev[1] * freq / 1000) ); - + double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_3rd - j) * itm_elev[1] / 1000000) / ( num_points_3rd * itm_elev[1] * freq / 1000) ); + cerr << "Clutter:: fresnel radius: " << frs_rad << " points2: " << num_points_3rd << " j: " << j << endl; + assert(frs_rad > 0); //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 - double min_elev = SGMiscd::min(itm_elev[last] + clutter_height, itm_elev[(int)itm_elev[0] + 1] + receiver_height); - double d1 = m * itm_elev[1]; - if ( (itm_elev[last] + clutter_height) > (itm_elev[(int)itm_elev[0] + 1] + receiver_height) ) { - d1 = (num_points_3rd - m) * itm_elev[1]; + double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); + double d1 = j * itm_elev[1]; + if ( (itm_elev[last2+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) { + d1 = (num_points_3rd - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; @@ -688,9 +708,8 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm // no losses } j++; - m++; mat++; - last = k+1; + } } diff --git a/src/Radio/radio.hxx b/src/Radio/radio.hxx index da84313fc..4c2bb7f64 100644 --- a/src/Radio/radio.hxx +++ b/src/Radio/radio.hxx @@ -45,6 +45,11 @@ private: double _tx_antenna_height; double _rx_antenna_height; double _antenna_gain; + double _rx_antenna_gain; + double _tx_antenna_gain; + double _rx_line_losses; + double _tx_line_losses; + double _terrain_sampling_distance; std::map _mat_database; int _propagation_model; /// 0 none, 1 round Earth, 2 ITM From 8928e0c415da5c259b12b5713e314a1b4b5d3bec Mon Sep 17 00:00:00 2001 From: adrian Date: Tue, 29 Nov 2011 16:15:06 +0200 Subject: [PATCH 09/11] Clutter loss doesn't depend anymore on sampling distance Also, fix double horizon diffraction, the second horizon is relative to the first horizon, not to the beginning of the path. --- src/Radio/radio.cxx | 87 +++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index 3ea219ff7..a16dee5e4 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -70,7 +70,7 @@ FGRadioTransmission::FGRadioTransmission() { _tx_line_losses = 2.0; _propagation_model = 2; // choose between models via option: realistic radio on/off - _terrain_sampling_distance = 90.0; // regular SRTM is 90 meters + _terrain_sampling_distance = fgGetDouble("/sim/radio/sampling-distance", 90.0); // regular SRTM is 90 meters } FGRadioTransmission::~FGRadioTransmission() @@ -428,20 +428,21 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double horizons[], double &clutter_loss) { distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points + if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone int mat = 0; - int j=1; // first point is TX elevation, last is RX elevation + int j=1; for (int k=3;k < (int)(itm_elev[0]) + 2;k++) { double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); - //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) ); assert(frs_rad > 0); - //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); @@ -450,19 +451,19 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm d1 = (itm_elev[0] - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; - //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; double intrusion = fabs(clearance); - //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { // no losses } else if (clearance < 0 && (intrusion < clutter_height)) { - clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100); } else if (clearance < 0 && (intrusion > clutter_height)) { - clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100); } else { // no losses @@ -481,19 +482,19 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm int last = 1; /** perform the first pass */ int mat = 0; - int j=1; // first point is TX elevation, 2nd is obstruction elevation + int j=1; for (int k=3;k < num_points_1st + 2;k++) { if (num_points_1st < 1) break; double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); - //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); assert(frs_rad > 0); - //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height); @@ -502,19 +503,19 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm d1 = (num_points_1st - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; - //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; double intrusion = fabs(clearance); - //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { // no losses } else if (clearance < 0 && (intrusion < clutter_height)) { - clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100); } else if (clearance < 0 && (intrusion > clutter_height)) { - clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100); } else { // no losses @@ -533,12 +534,12 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); - //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); assert(frs_rad > 0); - //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); @@ -547,19 +548,19 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm d1 = (num_points_2nd - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; - //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; double intrusion = fabs(clearance); - //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { // no losses } else if (clearance < 0 && (intrusion < clutter_height)) { - clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100); } else if (clearance < 0 && (intrusion > clutter_height)) { - clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100); } else { // no losses @@ -572,10 +573,10 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm else { // double horizon: same as single horizon, except there are 3 segments int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m ); - int num_points_2nd = (int)ceil( (horizons[1] - horizons[0]) * itm_elev[0] / distance_m ); + int num_points_2nd = (int)floor(horizons[1] * itm_elev[0] / distance_m ); int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd; - - cerr << "Clutter:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl; + cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl; + cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl; int last = 1; /** perform the first pass */ int mat = 0; @@ -586,12 +587,12 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); - //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); assert(frs_rad > 0); - //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height); @@ -600,19 +601,19 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm d1 = (num_points_1st - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; - //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; double intrusion = fabs(clearance); - //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { // no losses } else if (clearance < 0 && (intrusion < clutter_height)) { - clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100); } else if (clearance < 0 && (intrusion > clutter_height)) { - clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100); } else { // no losses @@ -630,11 +631,11 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); - //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); - //cerr << "Clutter:: fresnel radius: " << frs_rad << " points2: " << num_points_2nd << " j: " << j << endl; + //cerr << "Double horizon second pass:: fresnel radius: " << frs_rad << " points2: " << num_points_2nd << " j: " << j << endl; assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 @@ -644,19 +645,19 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm d1 = (num_points_2nd - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; - //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; double intrusion = fabs(clearance); - //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { // no losses } else if (clearance < 0 && (intrusion < clutter_height)) { - clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100); } else if (clearance < 0 && (intrusion > clutter_height)) { - clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100); } else { // no losses @@ -675,13 +676,13 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double clutter_height = 0.0; // mean clutter height for a certain terrain type double clutter_density = 0.0; // percent of reflected wave get_material_properties(materials[mat], clutter_height, clutter_density); - //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl; + double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_3rd - j) * itm_elev[1] / 1000000) / ( num_points_3rd * itm_elev[1] * freq / 1000) ); - cerr << "Clutter:: fresnel radius: " << frs_rad << " points2: " << num_points_3rd << " j: " << j << endl; + //cerr << "Double horizon third pass:: fresnel radius: " << frs_rad << " points3: " << num_points_3rd << " j: " << j << endl; assert(frs_rad > 0); - //cerr << "Clutter:: fresnel radius: " << frs_rad << endl; + //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height); @@ -690,19 +691,19 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm d1 = (num_points_3rd - j) * itm_elev[1]; } double ray_height = (grad * d1) + min_elev; - //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl; + double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10; double intrusion = fabs(clearance); - //cerr << "Clutter:: clearance: " << clearance << endl; + if (clearance >= 0) { // no losses } else if (clearance < 0 && (intrusion < clutter_height)) { - clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100; + clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100); } else if (clearance < 0 && (intrusion > clutter_height)) { - clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100; + clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100); } else { // no losses From 0c66ca67852a87c47046edfedbf2978bc024ba91 Mon Sep 17 00:00:00 2001 From: adrian Date: Tue, 29 Nov 2011 16:38:02 +0200 Subject: [PATCH 10/11] remove debugging code --- src/Radio/radio.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index a16dee5e4..994f3aee9 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -23,6 +23,7 @@ #endif #include +#define NDEBUG #include #include #include @@ -478,7 +479,7 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m ); int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m ); - cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl; + //cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl; int last = 1; /** perform the first pass */ int mat = 0; @@ -575,8 +576,8 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m ); int num_points_2nd = (int)floor(horizons[1] * itm_elev[0] / distance_m ); int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd; - cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl; - cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl; + //cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl; + //cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl; int last = 1; /** perform the first pass */ int mat = 0; @@ -635,7 +636,7 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); - //cerr << "Double horizon second pass:: fresnel radius: " << frs_rad << " points2: " << num_points_2nd << " j: " << j << endl; + assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 @@ -680,7 +681,7 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_3rd - j) * itm_elev[1] / 1000000) / ( num_points_3rd * itm_elev[1] * freq / 1000) ); - //cerr << "Double horizon third pass:: fresnel radius: " << frs_rad << " points3: " << num_points_3rd << " j: " << j << endl; + assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 From 1c1e954de22a775dfa72ce1c9066e3637783b340 Mon Sep 17 00:00:00 2001 From: adrian Date: Thu, 1 Dec 2011 13:34:34 +0200 Subject: [PATCH 11/11] Remove hard-coded values wherever possible; Make most of the station parameters configurable outside the attenuation functions with the ultimate goal of exposing them via the property tree --- src/Radio/radio.cxx | 86 ++++++++++++++------------------------------- src/Radio/radio.hxx | 5 ++- 2 files changed, 31 insertions(+), 60 deletions(-) diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index 994f3aee9..4f2772e4e 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -23,8 +23,7 @@ #endif #include -#define NDEBUG -#include + #include #include #include "radio.hxx" @@ -37,15 +36,10 @@ FGRadioTransmission::FGRadioTransmission() { - /** radio parameters (which should probably be set for each radio) */ _receiver_sensitivity = -110.0; // typical AM receiver sensitivity seems to be 0.8 microVolt at 12dB SINAD /** AM transmitter power in dBm. - * Note this value is calculated from the typical final transistor stage output - * small aircraft have portable transmitters which operate at 36 dBm output (4 Watts) others operate in the range 10-20 W - * later possibly store this value in aircraft description - * ATC comms usually operate high power equipment, thus making the link asymetrical; this is taken care of in propagation routines * Typical output powers for ATC ground equipment, VHF-UHF: * 40 dBm - 10 W (ground, clearance) * 44 dBm - 20 W (tower) @@ -59,18 +53,14 @@ FGRadioTransmission::FGRadioTransmission() { _rx_antenna_height = 2.0; // RX antenna height above ground level - /** pilot plane's antenna gain + AI aircraft antenna gain - * real-life gain for conventional monopole/dipole antenna - **/ - _antenna_gain = 2.0; - _rx_antenna_gain = 1.0; + _rx_antenna_gain = 1.0; // gain expressed in dBi _tx_antenna_gain = 1.0; _rx_line_losses = 2.0; // to be configured for each station _tx_line_losses = 2.0; - _propagation_model = 2; // choose between models via option: realistic radio on/off + _propagation_model = 2; _terrain_sampling_distance = fgGetDouble("/sim/radio/sampling-distance", 90.0); // regular SRTM is 90 meters } @@ -124,10 +114,16 @@ double FGRadioTransmission::receiveNav(SGGeod tx_pos, double freq, int transmiss void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_air) { + if(ground_to_air == 1) { + _transmitter_power += 6.0; + _tx_antenna_height += 30.0; + _tx_antenna_gain += 3.0; + } + + double comm1 = getFrequency(1); double comm2 = getFrequency(2); if ( !(fabs(freq - comm1) <= 0.0001) && !(fabs(freq - comm2) <= 0.0001) ) { - //cerr << "Frequency not tuned: " << freq << " Radio1: " << comm1 << " Radio2: " << comm2 << endl; return; } else { @@ -139,13 +135,10 @@ void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, in // TODO: free space, round earth double signal = LOS_calculate_attenuation(tx_pos, freq, ground_to_air); if (signal <= 0.0) { - SG_LOG(SG_GENERAL, SG_BULK, "Signal below receiver minimum sensitivity: " << signal); - //cerr << "Signal below receiver minimum sensitivity: " << signal << endl; return; } else { - SG_LOG(SG_GENERAL, SG_BULK, "Signal completely readable: " << signal); - //cerr << "Signal completely readable: " << signal << endl; + fgSetString("/sim/messages/atc", text.c_str()); /** write signal strength above threshold to the property tree * to implement a simple S-meter just divide by 3 dB per grade (VHF norm) @@ -157,8 +150,6 @@ void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, in // Use ITM propagation model double signal = ITM_calculate_attenuation(tx_pos, freq, ground_to_air); if (signal <= 0.0) { - SG_LOG(SG_GENERAL, SG_BULK, "Signal below receiver minimum sensitivity: " << signal); - //cerr << "Signal below receiver minimum sensitivity: " << signal << endl; return; } if ((signal > 0.0) && (signal < 12.0)) { @@ -188,8 +179,6 @@ void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, in fgSetDouble("/sim/sound/voices/voice/volume", old_volume); } else { - SG_LOG(SG_GENERAL, SG_BULK, "Signal completely readable: " << signal); - //cerr << "Signal completely readable: " << signal << endl; fgSetString("/sim/messages/atc", text.c_str()); /** write signal strength above threshold to the property tree * to implement a simple S-meter just divide by 3 dB per grade (VHF norm) @@ -233,16 +222,11 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i double clutter_loss = 0.0; // loss due to vegetation and urban double tx_pow = _transmitter_power; - double ant_gain = _antenna_gain; + double ant_gain = _rx_antenna_gain + _tx_antenna_gain; double signal = 0.0; - if(transmission_type == 1) - tx_pow = _transmitter_power + 6.0; - - if((transmission_type == 1) || (transmission_type == 3)) - ant_gain = _antenna_gain + 3.0; //pilot plane's antenna gain + ground station antenna gain - double link_budget = tx_pow - _receiver_sensitivity + ant_gain; + double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain; FGScenery * scenery = globals->get_scenery(); @@ -259,11 +243,7 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i SGGeoc center = SGGeoc::fromGeod( max_own_pos ); SGGeoc own_pos_c = SGGeoc::fromGeod( own_pos ); - /** position of sender radio antenna (HAAT) - sender can be aircraft or ground station - **/ - double ATC_HAAT = 30.0; - double Aircraft_HAAT = 5.0; + double sender_alt_ft,sender_alt; double transmitter_height=0.0; double receiver_height=0.0; @@ -302,7 +282,7 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i double elevation_under_pilot = 0.0; if (scenery->get_elevation_m( max_own_pos, elevation_under_pilot, NULL )) { - receiver_height = own_alt - elevation_under_pilot + 3; //assume antenna located 3 meters above ground + receiver_height = own_alt - elevation_under_pilot; } double elevation_under_sender = 0.0; @@ -313,10 +293,10 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i transmitter_height = sender_alt; } - if(transmission_type == 1) - transmitter_height += ATC_HAAT; - else - transmitter_height += Aircraft_HAAT; + + transmitter_height += _tx_antenna_height; + receiver_height += _rx_antenna_height; + SG_LOG(SG_GENERAL, SG_BULK, "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters"); @@ -383,7 +363,7 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i } double num_points= (double)_elevations.size(); - //cerr << "ITM:: Max alt between: " << max_alt_between << ", num points:" << num_points << endl; + _elevations.push_front(point_distance); _elevations.push_front(num_points -1); int size = _elevations.size(); @@ -442,7 +422,6 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) ); - assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 @@ -494,7 +473,6 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); - assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 @@ -539,7 +517,6 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); - assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 @@ -592,7 +569,6 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m; // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) ); - assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 @@ -637,7 +613,6 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) ); - assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height); @@ -682,7 +657,6 @@ void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm // First Fresnel radius double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_3rd - j) * itm_elev[1] / 1000000) / ( num_points_3rd * itm_elev[1] * freq / 1000) ); - assert(frs_rad > 0); //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3 @@ -847,10 +821,9 @@ double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, i frq_mhz = freq; double dbloss; double tx_pow = _transmitter_power; - double ant_gain = _antenna_gain; + double ant_gain = _rx_antenna_gain + _tx_antenna_gain; double signal = 0.0; - double ATC_HAAT = 30.0; - double Aircraft_HAAT = 5.0; + double sender_alt_ft,sender_alt; double transmitter_height=0.0; double receiver_height=0.0; @@ -859,13 +832,8 @@ double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, i double own_alt_ft = fgGetDouble("/position/altitude-ft"); double own_alt= own_alt_ft * SG_FEET_TO_METER; - if(transmission_type == 1) - tx_pow = _transmitter_power + 6.0; - - if((transmission_type == 1) || (transmission_type == 3)) - ant_gain = _antenna_gain + 3.0; //pilot plane's antenna gain + ground station antenna gain - double link_budget = tx_pow - _receiver_sensitivity + ant_gain; + double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain; //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl; @@ -881,10 +849,10 @@ double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, i double distance_m = SGGeodesy::distanceM(own_pos, sender_pos); - if(transmission_type == 1) - transmitter_height += ATC_HAAT; - else - transmitter_height += Aircraft_HAAT; + + transmitter_height += _tx_antenna_height; + receiver_height += _rx_antenna_height; + /** radio horizon calculation with wave bending k=4/3 */ double receiver_horizon = 4.12 * sqrt(receiver_height); diff --git a/src/Radio/radio.hxx b/src/Radio/radio.hxx index 4c2bb7f64..1261b7c51 100644 --- a/src/Radio/radio.hxx +++ b/src/Radio/radio.hxx @@ -44,7 +44,6 @@ private: double _transmitter_power; double _tx_antenna_height; double _rx_antenna_height; - double _antenna_gain; double _rx_antenna_gain; double _tx_antenna_gain; double _rx_line_losses; @@ -72,6 +71,10 @@ public: void setRxSensitivity(double sensitivity) { _receiver_sensitivity = sensitivity; }; void setTxAntennaHeight(double tx_antenna_height) { _tx_antenna_height = tx_antenna_height; }; void setRxAntennaHeight(double rx_antenna_height) { _rx_antenna_height = rx_antenna_height; }; + void setTxAntennaGain(double tx_antenna_gain) { _tx_antenna_gain = tx_antenna_gain; }; + void setRxAntennaGain(double rx_antenna_gain) { _rx_antenna_gain = rx_antenna_gain; }; + void setTxLineLosses(double tx_line_losses) { _tx_line_losses = tx_line_losses; }; + void setRxLineLosses(double rx_line_losses) { _rx_line_losses = rx_line_losses; }; void setPropagationModel(int model) { _propagation_model = model; }; // transmission_type: 0 for air to ground 1 for ground to air, 2 for air to air, 3 for pilot to ground, 4 for pilot to air void receiveATC(SGGeod tx_pos, double freq, string text, int transmission_type);