Simplify beam angle computation

This commit is contained in:
Tim Schubert 2020-08-28 00:43:47 +02:00
parent 1531696255
commit ae1d24ca80
5 changed files with 43 additions and 168 deletions

View file

@ -99,12 +99,13 @@ int main (int argc, char *argv[])
}
else
{
// Install internet stack on nodes
AodvHelper aodv;
aodv.Set ("EnableHello", BooleanValue (false));
//aodv.Set ("EnableHello", BooleanValue (false));
stack.SetRoutingHelper (aodv);
}
// Install internet stack on nodes
stack.Install (satellites);
stack.Install (stations);

View file

@ -21,12 +21,6 @@ LeoPropagationLossModel::GetTypeId (void)
.SetParent<PropagationLossModel> ()
.SetGroupName ("Leo")
.AddConstructor<LeoPropagationLossModel> ()
.AddAttribute ("MaxDistance",
"Cut-off distance for signal propagation",
DoubleValue (2500.0),
MakeDoubleAccessor (&LeoPropagationLossModel::SetCutoffDistance,
&LeoPropagationLossModel::GetCutoffDistance),
MakeDoubleChecker<double> ())
.AddAttribute ("ElevationAngle",
"Cut-off angle for signal propagation",
DoubleValue (40.0),
@ -60,54 +54,45 @@ LeoPropagationLossModel::~LeoPropagationLossModel ()
{
}
double
LeoPropagationLossModel::GetAngle (Ptr<MobilityModel> a, Ptr<MobilityModel> b)
{
Vector3D x = a->GetPosition ();
Vector3D y = b->GetPosition ();
Vector3D pa, pb;
if (x.GetLength () < y.GetLength ())
{
pa = x - y;
pb = y;
NS_LOG_DEBUG ("LEO ground -> space");
}
else
{
pa = y - x;
pb = x;
NS_LOG_DEBUG ("LEO space -> ground");
}
double prod = abs ((pa.x*-pb.x) + (pa.y*-pb.y) + (pa.z*-pb.z));
double norm = pa.GetLength () * pb.GetLength ();
return acos (prod / norm);
}
void
LeoPropagationLossModel::SetElevationAngle (double angle)
{
m_elevationAngle = (90 - angle) * (M_PI/180.0);
m_elevationAngle = angle * (M_PI/180.0);
}
double
LeoPropagationLossModel::GetCutoffDistance (const Ptr<MobilityModel> sat) const
{
double angle = m_elevationAngle;
double hs = sat->GetPosition ().GetLength ();
double a = 1 + tan (angle) * tan (angle);
double b = 2.0 * tan (angle) * hs;
double c = hs*hs - LEO_PROP_EARTH_RAD*LEO_PROP_EARTH_RAD;
double disc = b*b + 4*a*c;
NS_LOG_DEBUG ("angle="<<angle<<" hs="<<hs<<" a="<<a<<" b="<<b<<" c="<<c<<" disc="<<disc);
if (disc < 0)
{
// point not on earth surface
return - 1.0;
}
double t1 = (-b - sqrt (disc)) / (2.0 * a);
double t2 = (-b + sqrt (disc)) / (2.0 * a);
double num1 = Vector2D (t1, - tan (angle) * t1).GetLength ();
double num2 = Vector2D (t2, - tan (angle) * t2).GetLength ();
return fmin (num1, num2);
}
double
LeoPropagationLossModel::GetElevationAngle () const
{
return 90 - (m_elevationAngle * (180.0/M_PI));
}
void
LeoPropagationLossModel::SetCutoffDistance (double d)
{
m_cutoffDistance = d * 1000.0;
}
double
LeoPropagationLossModel::GetCutoffDistance () const
{
return m_cutoffDistance / 1000.0;
return m_elevationAngle * (180.0/M_PI);
}
double
@ -115,27 +100,21 @@ LeoPropagationLossModel::DoCalcRxPower (double txPowerDbm,
Ptr<MobilityModel> a,
Ptr<MobilityModel> b) const
{
Ptr<MobilityModel> sat = a->GetPosition ().GetLength () > b->GetPosition ().GetLength () ? a : b;
double distance = a->GetDistanceFrom (b);
if (distance > m_cutoffDistance)
double cutOff = GetCutoffDistance (sat);
if (distance > cutOff)
{
NS_LOG_DEBUG ("LEO DROP distance: a=" << a->GetPosition () << " b=" << b->GetPosition ()<<" dist=" << distance);
NS_LOG_DEBUG ("LEO DROP distance: a=" << a->GetPosition () << " b=" << b->GetPosition ()<<" dist=" << distance<<" cutoff="<<cutOff);
return -1000.0;
}
double angle = GetAngle (a, b);
if (angle > m_elevationAngle)
{
NS_LOG_DEBUG ("LEO DROP angle: a=" << a->GetPosition () << " b=" << b->GetPosition () << " dist=" << distance << "angle=" << angle);
return -1000.0;
}
// txPowerDbm includes tx antenna gain and losses
// receiver loss and gain added at net device
// P_{RX} = P_{TX} + G_{TX} - L_{TX} - L_{FS} - L_M + G_{RX} - L_{RX}
double rxc = txPowerDbm - m_atmosphericLoss - m_freeSpacePathLoss - m_linkMargin;
NS_LOG_DEBUG ("LEO TRANSMIT: angle=" << angle <<";distance=" << distance << ";rxc=" << rxc);
NS_LOG_DEBUG ("LEO TRANSMIT distance: a=" << a->GetPosition () << " b=" << b->GetPosition ()<<" dist=" << distance <<" cutoff="<<cutOff<< "rxc=" << rxc);
return rxc;
}

View file

@ -6,6 +6,8 @@
#include <ns3/object.h>
#include <ns3/propagation-loss-model.h>
#define LEO_PROP_EARTH_RAD 6.37101e6
namespace ns3 {
class LeoPropagationLossModel : public PropagationLossModel
@ -15,15 +17,8 @@ public:
LeoPropagationLossModel ();
virtual ~LeoPropagationLossModel ();
static double GetAngle (Ptr<MobilityModel> a, Ptr<MobilityModel> b);
private:
/**
* Cutoff distance for signal
*/
double m_cutoffDistance;
/**
* Maximum elevation angle
*/
@ -65,8 +60,7 @@ private:
void SetElevationAngle (double angle);
double GetElevationAngle () const;
void SetCutoffDistance (double d);
double GetCutoffDistance () const;
double GetCutoffDistance (const Ptr<MobilityModel> sat) const;
};
}

View file

@ -168,7 +168,7 @@ MockChannel::Deliver (
{
// check if signal reaches destination
rxPower = pLoss->CalcRxPower (txPower, srcMob, dstMob);
if (rxPower <= -1000.0)
if (rxPower < -900.0)
{
NS_LOG_WARN (this << "unable to reach destination " << dst->GetNode ()->GetId () << " from " << src->GetNode ()->GetId ());
return false;

View file

@ -8,102 +8,6 @@
using namespace ns3;
class LeoPropagationAngleTestCase1 : public TestCase
{
public:
LeoPropagationAngleTestCase1 ();
virtual ~LeoPropagationAngleTestCase1 ();
private:
virtual void DoRun (void);
};
LeoPropagationAngleTestCase1::LeoPropagationAngleTestCase1 ()
: TestCase ("Test angle computation 90 deg")
{
}
LeoPropagationAngleTestCase1::~LeoPropagationAngleTestCase1 ()
{
}
void
LeoPropagationAngleTestCase1::DoRun (void)
{
Ptr<ConstantPositionMobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
a->SetPosition (Vector3D (10, 0, 0));
Ptr<ConstantPositionMobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
b->SetPosition (Vector3D (0, 10, 0));
double angle = LeoPropagationLossModel::GetAngle (a, b);
NS_TEST_ASSERT_MSG_EQ ((M_PI/4 - 0.1 < angle && angle < M_PI/4 + 0.1), true, "Angle should be 90 deg.");
}
class LeoPropagationAngleTestCase2 : public TestCase
{
public:
LeoPropagationAngleTestCase2 ();
virtual ~LeoPropagationAngleTestCase2 ();
private:
virtual void DoRun (void);
};
LeoPropagationAngleTestCase2::LeoPropagationAngleTestCase2 ()
: TestCase ("Test angle computation 0 deg")
{
}
LeoPropagationAngleTestCase2::~LeoPropagationAngleTestCase2 ()
{
}
void
LeoPropagationAngleTestCase2::DoRun (void)
{
Ptr<ConstantPositionMobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
a->SetPosition (Vector3D (10, 0, 0));
Ptr<ConstantPositionMobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
b->SetPosition (Vector3D (10, 0, 0));
double angle = LeoPropagationLossModel::GetAngle (a, b);
NS_TEST_ASSERT_MSG_EQ (isnan(angle), true, "Angle should be 0 deg.");
}
class LeoPropagationAngleTestCase3 : public TestCase
{
public:
LeoPropagationAngleTestCase3 ();
virtual ~LeoPropagationAngleTestCase3 ();
private:
virtual void DoRun (void);
};
LeoPropagationAngleTestCase3::LeoPropagationAngleTestCase3 ()
: TestCase ("Test angle computation 0 vector")
{
}
LeoPropagationAngleTestCase3::~LeoPropagationAngleTestCase3 ()
{
}
void
LeoPropagationAngleTestCase3::DoRun (void)
{
Ptr<ConstantPositionMobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
a->SetPosition (Vector3D (0, 0, 0));
Ptr<ConstantPositionMobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
b->SetPosition (Vector3D (0, 0, 0));
double angle = LeoPropagationLossModel::GetAngle (a, b);
NS_TEST_ASSERT_MSG_EQ (isnan(angle), true, "Angle should be NaN");
}
class LeoPropagationRxNoLosTestCase : public TestCase
{
public:
@ -228,9 +132,6 @@ LeoPropagationTestSuite::LeoPropagationTestSuite ()
: TestSuite ("leo-propagation", UNIT)
{
// TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER
AddTestCase (new LeoPropagationAngleTestCase1, TestCase::QUICK);
AddTestCase (new LeoPropagationAngleTestCase2, TestCase::QUICK);
AddTestCase (new LeoPropagationAngleTestCase3, TestCase::QUICK);
AddTestCase (new LeoPropagationRxNoLosTestCase, TestCase::QUICK);
AddTestCase (new LeoPropagationRxLosTestCase, TestCase::QUICK);
AddTestCase (new LeoPropagationBadAngleTestCase, TestCase::QUICK);