mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 10:03:58 +02:00
Enable setting of mobility precision and add test
This commit is contained in:
parent
6fdfc6b2a8
commit
4cad8458ab
4 changed files with 115 additions and 10 deletions
|
@ -19,6 +19,7 @@ LeoCircularOrbitMobilityModel::GetTypeId ()
|
|||
static TypeId tid = TypeId ("ns3::LeoCircularOrbitMobilityModel")
|
||||
.SetParent<MobilityModel> ()
|
||||
.SetGroupName ("Leo")
|
||||
.AddConstructor<LeoCircularOrbitMobilityModel> ()
|
||||
.AddAttribute ("Altitude",
|
||||
"A height from the earth's surface in meters",
|
||||
DoubleValue (1000.0),
|
||||
|
@ -32,11 +33,16 @@ LeoCircularOrbitMobilityModel::GetTypeId ()
|
|||
MakeDoubleAccessor (&LeoCircularOrbitMobilityModel::SetInclination,
|
||||
&LeoCircularOrbitMobilityModel::GetInclination),
|
||||
MakeDoubleChecker<double> ())
|
||||
.AddAttribute ("Precision",
|
||||
"The time precision with which to compute position updates. 0 means arbitrary precision",
|
||||
TimeValue (Seconds (1)),
|
||||
MakeTimeAccessor (&LeoCircularOrbitMobilityModel::m_precision),
|
||||
MakeTimeChecker ())
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
LeoCircularOrbitMobilityModel::LeoCircularOrbitMobilityModel() : MobilityModel (), m_latitude (0.0), m_offset (0.0)
|
||||
LeoCircularOrbitMobilityModel::LeoCircularOrbitMobilityModel() : MobilityModel (), m_latitude (0.0), m_offset (0.0), m_position ()
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
}
|
||||
|
@ -107,13 +113,39 @@ LeoCircularOrbitMobilityModel::RotatePlane (double a, const Vector3D &x) const
|
|||
}
|
||||
|
||||
Vector
|
||||
LeoCircularOrbitMobilityModel::DoGetPosition (void) const
|
||||
LeoCircularOrbitMobilityModel::CalcPosition (Time t) const
|
||||
{
|
||||
Vector3D x = Product (m_orbitHeight, Vector3D (cos (m_inclination) * cos (m_latitude),
|
||||
cos (m_inclination) * sin (m_latitude),
|
||||
sin (m_inclination)));
|
||||
|
||||
return RotatePlane (GetProgress (Simulator::Now ()), x);
|
||||
return RotatePlane (GetProgress (t), x);
|
||||
}
|
||||
|
||||
Vector LeoCircularOrbitMobilityModel::Update ()
|
||||
{
|
||||
m_plane = PlaneNorm ();
|
||||
|
||||
m_position = CalcPosition (Simulator::Now ());
|
||||
NotifyCourseChange ();
|
||||
|
||||
if (m_precision > Seconds (0))
|
||||
{
|
||||
Simulator::Schedule (m_precision, &LeoCircularOrbitMobilityModel::Update, this);
|
||||
}
|
||||
|
||||
return m_position;
|
||||
}
|
||||
|
||||
Vector
|
||||
LeoCircularOrbitMobilityModel::DoGetPosition (void) const
|
||||
{
|
||||
if (m_precision == Time (0))
|
||||
{
|
||||
// Notice: NotifyCourseChange () will not be called
|
||||
return CalcPosition (Simulator::Now ());
|
||||
}
|
||||
return m_position;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -125,7 +157,7 @@ LeoCircularOrbitMobilityModel::DoSetPosition (const Vector &position)
|
|||
// SetPostion
|
||||
m_latitude = position.x;
|
||||
m_offset = position.y;
|
||||
m_plane = PlaneNorm ();
|
||||
Update ();
|
||||
}
|
||||
|
||||
double LeoCircularOrbitMobilityModel::GetAltitude () const
|
||||
|
@ -136,7 +168,7 @@ double LeoCircularOrbitMobilityModel::GetAltitude () const
|
|||
void LeoCircularOrbitMobilityModel::SetAltitude (double h)
|
||||
{
|
||||
m_orbitHeight = LEO_EARTH_RAD_M + h;
|
||||
m_plane = PlaneNorm ();
|
||||
Update ();
|
||||
}
|
||||
|
||||
double LeoCircularOrbitMobilityModel::GetInclination () const
|
||||
|
@ -148,7 +180,7 @@ void LeoCircularOrbitMobilityModel::SetInclination (double incl)
|
|||
{
|
||||
NS_ASSERT_MSG (incl != 0.0, "Plane must not be orthogonal to axis");
|
||||
m_inclination = (incl / 180) * M_PI;
|
||||
m_plane = PlaneNorm ();
|
||||
Update ();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -70,6 +70,16 @@ private:
|
|||
*/
|
||||
Vector3D m_plane;
|
||||
|
||||
/**
|
||||
* Current position
|
||||
*/
|
||||
Vector3D m_position;
|
||||
|
||||
/**
|
||||
* Time precision for positions
|
||||
*/
|
||||
Time m_precision;
|
||||
|
||||
/**
|
||||
* \return the current position.
|
||||
*/
|
||||
|
@ -94,6 +104,15 @@ private:
|
|||
* Advances a satellite by a degrees on the orbital plane
|
||||
*/
|
||||
Vector3D RotatePlane (double a, const Vector3D &x) const;
|
||||
|
||||
/**
|
||||
* Calculate the position at time
|
||||
*
|
||||
* \param t time
|
||||
*/
|
||||
Vector CalcPosition (Time t) const;
|
||||
|
||||
Vector Update ();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
|
||||
#include "math.h"
|
||||
|
||||
#include "ns3/integer.h"
|
||||
#include "leo-circular-orbit-position-allocator.h"
|
||||
|
||||
|
@ -25,12 +27,12 @@ LeoCircularOrbitAllocator::GetTypeId (void)
|
|||
"The number of orbits",
|
||||
IntegerValue (1),
|
||||
MakeIntegerAccessor (&LeoCircularOrbitAllocator::m_numOrbits),
|
||||
MakeIntegerChecker<uint64_t> ())
|
||||
MakeIntegerChecker<uint16_t> ())
|
||||
.AddAttribute ("NumSatellites",
|
||||
"The number of satellites per orbit",
|
||||
IntegerValue (1),
|
||||
MakeIntegerAccessor (&LeoCircularOrbitAllocator::m_numSatellites),
|
||||
MakeIntegerChecker<uint64_t> ())
|
||||
MakeIntegerChecker<uint16_t> ())
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
@ -44,9 +46,17 @@ LeoCircularOrbitAllocator::AssignStreams (int64_t stream)
|
|||
Vector
|
||||
LeoCircularOrbitAllocator::GetNext () const
|
||||
{
|
||||
return Vector (180 * ((double) m_lastOrbit / (double) m_numOrbits),
|
||||
360.0 * ((double) m_lastSatellite / (double) m_numSatellites),
|
||||
Vector next = Vector (M_PI * (m_lastOrbit / (double) m_numOrbits),
|
||||
2 * M_PI * (m_lastSatellite / (double) m_numSatellites),
|
||||
0);
|
||||
|
||||
m_lastSatellite = (m_lastSatellite + 1) % m_numSatellites;
|
||||
if (m_lastSatellite >= m_numSatellites)
|
||||
{
|
||||
m_lastOrbit = (m_lastOrbit + 1) % m_numOrbits;
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue