From cc2a8ae5e9381b654bc5cb0ff82d30dd2f22c1b1 Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Sat, 15 Aug 2020 17:25:27 +0200 Subject: [PATCH] Add test for latitude change --- model/leo-circular-orbit-mobility-model.cc | 48 +++++----------------- model/leo-circular-orbit-mobility-model.h | 6 --- test/leo-orbit-test-suite.cc | 38 +++++++++++++---- wscript | 2 + 4 files changed, 42 insertions(+), 52 deletions(-) diff --git a/model/leo-circular-orbit-mobility-model.cc b/model/leo-circular-orbit-mobility-model.cc index d2bce7d..116e28a 100644 --- a/model/leo-circular-orbit-mobility-model.cc +++ b/model/leo-circular-orbit-mobility-model.cc @@ -32,23 +32,11 @@ LeoCircularOrbitMobilityModel::GetTypeId () MakeDoubleAccessor (&LeoCircularOrbitMobilityModel::SetInclination, &LeoCircularOrbitMobilityModel::GetInclination), MakeDoubleChecker ()) - .AddAttribute ("Latitude", - "The latitude at which the orital plane intersects the equatorial plane in degrees", - DoubleValue (0.0), - MakeDoubleAccessor (&LeoCircularOrbitMobilityModel::SetLatitude, - &LeoCircularOrbitMobilityModel::GetLatitude), - MakeDoubleChecker ()) - .AddAttribute ("Offset", - "The relative offset of the satellite along the orbital plane from the equatorial plane in degrees", - DoubleValue (0.0), - MakeDoubleAccessor (&LeoCircularOrbitMobilityModel::SetOffset, - &LeoCircularOrbitMobilityModel::GetOffset), - MakeDoubleChecker ()) ; return tid; } -LeoCircularOrbitMobilityModel::LeoCircularOrbitMobilityModel() : MobilityModel () +LeoCircularOrbitMobilityModel::LeoCircularOrbitMobilityModel() : MobilityModel (), m_latitude (0.0), m_offset (0.0) { NS_LOG_FUNCTION_NOARGS (); } @@ -105,15 +93,14 @@ double LeoCircularOrbitMobilityModel::GetProgress (Time t) const { // TODO use nanos or ms instead? does it give higher precision? - return 2 * M_PI * ((GetSpeed () * t.GetSeconds ()) / LEO_EARTH_RAD_M) + m_offset; + return (2 * M_PI * ((GetSpeed () * t.GetSeconds ()) / LEO_EARTH_RAD_M)) + m_offset; } Vector3D LeoCircularOrbitMobilityModel::RotatePlane (double a, const Vector3D &x) const { - Vector3D n = PlaneNorm (); + Vector3D n = m_plane; - // TODO optimize? return Product (DotProduct (n, x), n) + Product (cos (a), CrossProduct (CrossProduct (n, x), n)) + Product (sin (a), CrossProduct (n, x)); @@ -132,7 +119,13 @@ LeoCircularOrbitMobilityModel::DoGetPosition (void) const void LeoCircularOrbitMobilityModel::DoSetPosition (const Vector &position) { - NS_ASSERT_MSG (false, "Can not set position of satellite on circular orbit"); + // use first element of position vector as latitude, second for longitude + // this works nicely with MobilityHelper and GetPostion will still get the + // correct position, but be aware that it will not be the same as supplied to + // SetPostion + m_latitude = position.x; + m_offset = position.y; + m_plane = PlaneNorm (); } double LeoCircularOrbitMobilityModel::GetAltitude () const @@ -146,27 +139,6 @@ void LeoCircularOrbitMobilityModel::SetAltitude (double h) m_plane = PlaneNorm (); } -double LeoCircularOrbitMobilityModel::GetLatitude () const -{ - return m_latitude / M_PI * 180.0; -} - -void LeoCircularOrbitMobilityModel::SetLatitude (double lat) -{ - m_latitude = lat / 180 * M_PI; - m_plane = PlaneNorm (); -} - -double LeoCircularOrbitMobilityModel::GetOffset () const -{ - return (m_offset / M_PI) * 180; -} - -void LeoCircularOrbitMobilityModel::SetOffset (double off) -{ - m_offset = (off / 180) * M_PI; -} - double LeoCircularOrbitMobilityModel::GetInclination () const { return (m_inclination / M_PI) * 180.0; diff --git a/model/leo-circular-orbit-mobility-model.h b/model/leo-circular-orbit-mobility-model.h index 95b6fd2..c23993d 100644 --- a/model/leo-circular-orbit-mobility-model.h +++ b/model/leo-circular-orbit-mobility-model.h @@ -40,12 +40,6 @@ public: double GetAltitude () const; void SetAltitude (double h); - double GetLatitude () const; - void SetLatitude (double lat); - - double GetOffset () const; - void SetOffset (double off); - double GetInclination () const; void SetInclination (double incl); diff --git a/test/leo-orbit-test-suite.cc b/test/leo-orbit-test-suite.cc index 5fb2c9e..b6da59b 100644 --- a/test/leo-orbit-test-suite.cc +++ b/test/leo-orbit-test-suite.cc @@ -26,7 +26,7 @@ private: class LeoOrbitPositionTestCase : public TestCase { public: - LeoOrbitPositionTestCase () : TestCase ("Test position for 0 altitude and 0 inclination") {} + LeoOrbitPositionTestCase () : TestCase ("Test position for 0 altitude and 1.0 inclination") {} virtual ~LeoOrbitPositionTestCase () {} private: virtual void DoRun (void) @@ -35,36 +35,57 @@ private: mob->SetAttribute ("Altitude", DoubleValue (0.0)); mob->SetAttribute ("Inclination", DoubleValue (1.0)); - NS_TEST_ASSERT_MSG_EQ (mob->GetPosition ().GetLength(), LEO_EARTH_RAD_M, "Unexpected position on earths surface for 1 deg inclination"); + NS_TEST_ASSERT_MSG_EQ_TOL (mob->GetPosition ().GetLength(), LEO_EARTH_RAD_M, 0.1, "Unexpected position on earths surface for 1 deg inclination"); } }; class LeoOrbitProgressTestCase : public TestCase { public: - LeoOrbitProgressTestCase () : TestCase ("Test position for 0 altitude and 1.0 inclination after 360 seconds") {} + LeoOrbitProgressTestCase () : TestCase ("Test position shoudl not be the same after some time") {} virtual ~LeoOrbitProgressTestCase () {} private: void TestLengthPosition (double expl, double expx, Ptr mob) { Vector pos = mob->GetPosition (); - NS_TEST_EXPECT_MSG_NE_INTERNAL (pos.x, expx, "Position not equal", __FILE__, __LINE__); - NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (pos.GetLength (), expl, 0.001, "Position must be different", __FILE__, __LINE__); + NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (pos.GetLength (), expl, 0.001, "Distance to earth should be the same", __FILE__, __LINE__); + NS_TEST_EXPECT_MSG_NE_INTERNAL (pos.x, expx, "Position should not be equal", __FILE__, __LINE__); } virtual void DoRun (void) { Ptr mob = CreateObject (); mob->SetAttribute ("Altitude", DoubleValue (0.0)); - mob->SetAttribute ("Inclination", DoubleValue (1.0)); + mob->SetAttribute ("Inclination", DoubleValue (20.0)); Vector pos = mob->GetPosition (); - Simulator::Schedule (Seconds (360.0), &LeoOrbitProgressTestCase::TestLengthPosition, this, LEO_EARTH_RAD_M, pos.x, mob); + Simulator::Schedule (Seconds (100.0), &LeoOrbitProgressTestCase::TestLengthPosition, this, LEO_EARTH_RAD_M, pos.x, mob); Simulator::Run (); Simulator::Destroy (); } }; +class LeoOrbitLatitudeTestCase : public TestCase +{ +public: + LeoOrbitLatitudeTestCase () : TestCase ("Test offset between neighboring satellites planes") {} + virtual ~LeoOrbitLatitudeTestCase () {} +private: + virtual void DoRun (void) + { + Ptr mob = CreateObject (); + mob->SetAttribute ("Altitude", DoubleValue (1000.0)); + mob->SetAttribute ("Inclination", DoubleValue (20.0)); + + Vector pos1 = mob->GetPosition (); + + mob->SetPosition (Vector3D (20.0, 0, 0)); + Vector pos2 = mob->GetPosition (); + + NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "Neighboring satellite should have different position"); + } +}; + class LeoOrbitOffsetTestCase : public TestCase { public: @@ -79,7 +100,7 @@ private: Vector pos1 = mob->GetPosition (); - mob->SetAttribute ("Offset", DoubleValue (20.0)); + mob->SetPosition (Vector3D (0, 20.0, 0)); Vector pos2 = mob->GetPosition (); NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "Neighboring satellite should have different position"); @@ -93,6 +114,7 @@ public: AddTestCase (new LeoOrbitSpeedTestCase, TestCase::QUICK); AddTestCase (new LeoOrbitPositionTestCase, TestCase::QUICK); AddTestCase (new LeoOrbitProgressTestCase, TestCase::QUICK); + AddTestCase (new LeoOrbitLatitudeTestCase, TestCase::QUICK); AddTestCase (new LeoOrbitOffsetTestCase, TestCase::QUICK); } }; diff --git a/wscript b/wscript index 25f239f..52426da 100644 --- a/wscript +++ b/wscript @@ -17,6 +17,7 @@ def build(bld): 'helper/satellite-node-helper.cc', 'model/leo.cc', 'model/leo-circular-orbit-mobility-model.cc', + 'model/leo-circular-orbit-position-allocator.cc', 'model/leo-mock-channel.cc', 'model/leo-mock-net-device.cc', 'model/leo-propagation-loss-model.cc', @@ -55,6 +56,7 @@ def build(bld): 'helper/satellite-node-helper.h', 'model/leo.h', 'model/leo-circular-orbit-mobility-model.h', + 'model/leo-circular-orbit-position-allocator.h', 'model/leo-mock-channel.h', 'model/leo-mock-net-device.h', 'model/leo-oneweb-constants.h',