A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
leo-circular-orbit-mobility-model.cc
Go to the documentation of this file.
1// Copyright (c) Tim Schubert
2//
3// SPDX-License-Identifier: GPL-2.0-only
4//
5// Author: Tim Schubert <ns-3-leo@timschubert.net>
6// Porting: Thiago Miyazaki <miyathiago@gmail.com> <t.miyazaki@unesp.br>
7
8/**
9 * @file
10 * @ingroup leo
11 * Implementation of LeoCircularOrbitMobilityModel.
12 */
13
15
17#include "math.h"
18
19#include "ns3/angles.h"
20#include "ns3/double.h"
21#include "ns3/nstime.h"
22#include "ns3/simulator.h"
23
24namespace ns3
25{
26
27NS_LOG_COMPONENT_DEFINE("LeoCircularOrbitMobilityModel");
28
30
33{
34 static TypeId tid =
35 TypeId("ns3::LeoCircularOrbitMobilityModel")
37 .SetGroupName("Leo")
38 .AddConstructor<LeoCircularOrbitMobilityModel>()
39 .AddAttribute("Altitude",
40 "A height from the earth's surface in kilometers",
41 DoubleValue(1000.0),
45 // TODO check value limits
46 .AddAttribute("Inclination",
47 "The inclination of the orbital plane in degrees",
48 DoubleValue(10.0),
52 .AddAttribute("Speed",
53 "Orbital speed in meters per second; negative to compute from gravity",
54 DoubleValue(-1.0),
57 .AddAttribute("Resolution",
58 "Time interval between CourseChange notifications (zero disables). "
59 "Determines how frequently the mobility model notifies course changes.",
63 return tid;
64}
65
68 m_longitude(0.0),
70 m_orbitalSpeed(-1.0)
71{
72 /**
73 * @todo The current implementation uses a periodic event to trigger
74 * NotifyCourseChange(). As suggested by reviewers, a more idiomatic approach
75 * would be to rely on the underlying MobilityModel trace source. However,
76 * due to the continuous nature of LEO orbit changes, the periodic
77 * approximation is currently used.
78 */
79 NS_LOG_FUNCTION(this);
80}
81
90
91/// meters in a kilometer
92constexpr double M_PER_KM = 1000;
93
94double
96{
97 if (m_orbitalSpeed >= 0.0)
98 {
99 return m_orbitalSpeed;
100 }
101 else
102 {
103 // sqrt((m^3/s^2) / m) => sqrt(m^2/s^2) => m/s = m/s
105 }
106}
107
108Vector
110{
111 Time t = Simulator::Now();
112 Vector3D pos = DoGetPosition();
113 double radius = pos.GetLength();
114 Vector3D heading = CrossProduct(PlaneNorm(t), pos);
115 return (GetSpeed() / radius) * heading;
116}
117
120{
121 double lon = CalcLongitude(t);
122 return Vector3D(sin(-m_inclination) * cos(lon),
123 sin(-m_inclination) * sin(lon),
124 cos(m_inclination));
125}
126
129{
130 Vector3D k = PlaneNorm(t);
131 // Canonical Rodrigues' rotation formula:
132 // v_rot = v cos(theta) + (k x v) sin(theta) + k(k . v)(1 - cos(theta))
133 // where k is the unit rotation axis.
134 const double cosTheta = cos(theta);
135 const double sinTheta = sin(theta);
136 return (v * cosTheta) + (CrossProduct(k, v) * sinTheta) + (k * (k * v) * (1 - cosTheta));
137}
138
139double
141{
142 return m_longitude - (t * 2 * M_PI / Days(1)).GetDouble();
143}
144
145double
147{
148 double omega;
149 double orbitMeters = m_orbitHeight * M_PER_KM;
150 if (m_orbitalSpeed >= 0.0)
151 {
152 // If the user set up a different orbital speed
153 omega = std::abs(m_orbitalSpeed) / (orbitMeters);
154 }
155 else
156 {
157 // If the user did not setup an angular velocity, assume it based on earths gravity
158 // omega = sqrt(GM / r^3); units: sqrt(m^3/s^2 / m^3) = rad/s
159 omega = std::sqrt(GeographicPositions::LEO_EARTH_GGC /
160 (orbitMeters * orbitMeters * orbitMeters));
161 }
162 // Retrograde orbit: inclination > 90 degrees
163 if (m_inclination > M_PI / 2.0)
164 {
165 omega = -omega;
166 }
167 return omega;
168}
169
170Vector
172{
173 double lon = CalcLongitude(t);
174 // account for orbit longitude and earth rotation offset
176 Vector3D(cos(m_inclination) * cos(lon),
177 cos(m_inclination) * sin(lon),
178 sin(m_inclination)));
179
180 double progressAngleRad = m_argumentOfLatitude + GetAngularVelocity() * t.GetSeconds();
181 return RotatePlane(progressAngleRad, x, t);
182}
183
184void
195
196void
210
211void
218
219// The below two methods return the same ECEF position because this model's
220// state is contained in orbital data members only; it never populates the
221// base class m_position (lat/lon/alt) member variable. Without these overrides,
222// the methods would return the unused (0,0,0) m_position. It is not clear
223// whether DoGetPosition() will continue to return CalcPosition() in the future;
224// coordinate system handling may be refactored.
225
226Vector
228{
229 // This model uses ECEF coordinates, which is consistent with GeocentricEcefMobilityModel.
231}
232
233Vector
238
239void
241{
242 NS_LOG_FUNCTION(this << position);
243
244 const auto [longitudeDeg, argumentOfLatitudeDeg, satIndex] = position;
245 m_longitude = DegreesToRadians(longitudeDeg);
246 m_argumentOfLatitude = DegreesToRadians(argumentOfLatitudeDeg);
247 NS_LOG_INFO("Set orbital position: longitude = "
248 << longitudeDeg << " deg, argument of latitude = " << argumentOfLatitudeDeg
249 << " deg, altitude = " << GetAltitudeKm()
250 << " km, inclination = " << GetInclination()
251 << " deg, angular velocity = " << GetAngularVelocity() << " rad/s");
252
254}
255
256double
261
262void
268
269double
274
275void
281
282double
287
288void
294
295}; // namespace ns3
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
uint32_t v
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
GeocentricConstantPositionMobilityModel()=default
Create a position located at coordinates (0,0,0).
static constexpr double EARTH_SPHERE_RADIUS
Earth's radius in meters if modeled as a perfect sphere.
static constexpr double LEO_EARTH_GGC
Spheroid model to use for earth: perfect sphere (SPHERE), Geodetic Reference System 1980 (GRS80),...
Keep track of the orbital position and velocity of a satellite.
Vector3D RotatePlane(double theta, const Vector3D &v, Time t) const
Rotates a position vector by angle 'a' around the orbital plane normal, using the Rodrigues rotation ...
double GetInclination() const
Gets the inclination.
double GetAltitudeKm() const
Gets the altitude in km (not the usual meters used in ns-3).
double m_orbitalSpeed
Orbital speed in m/s; negative means compute from gravity.
Vector CalcPosition(Time t) const
Calculate the position at time t.
double GetAltitude() const
Gets the altitude in m.
double GetSpeed() const
Gets the speed of the node.
void SetAltitudeKm(double h)
Sets the altitude in km (not the usual meters used in ns-3).
void SetInclination(double incl)
Sets the inclination.
double m_argumentOfLatitude
Argument of latitude in rad.
Vector3D PlaneNorm(Time t) const
Get the normal vector of the orbital plane.
Time m_resolutionTimeStep
Time interval between CourseChange notifications; zero disables periodic notifications.
void SetAltitude(double h)
Sets the altitude in m.
void DoDispose() override
Destructor implementation.
Vector DoGetVelocity() const override
Returns the current velocity of the node.
void NotifyCourseChangeAndReschedule()
Fire NotifyCourseChange and reschedule at m_resolutionTimeStep.
double CalcLongitude(Time t) const
Calculate the ECEF longitude of the ascending node at simulation time t.
void DoInitialize() override
Initialize() implementation.
Vector DoGetGeocentricPosition() const override
Returns the Geocentric Position of the Node in ECEF (cartesian).
EventId m_courseChangeEvent
Event for course change notification.
void DoSetPosition(const Vector &position) override
Sets the node position via argument.
Vector DoGetPosition() const override
Returns the node current position.
double GetAngularVelocity() const
Get the orbital angular velocity.
void NotifyCourseChange() const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
virtual void DoInitialize()
Initialize() implementation.
Definition object.cc:437
virtual void DoDispose()
Destructor implementation.
Definition object.cc:430
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:398
@ S
second
Definition nstime.h:106
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
a 3d vector
Definition vector.h:35
double GetLength() const
Compute the length (magnitude) of the vector.
Definition vector.cc:68
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:267
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
Time Days(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1232
Declaration of LeoCircularOrbitMobilityModel.
log2() macro definition; to deal with Bug 1467.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1376
constexpr double M_PER_KM
meters in a kilometer
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Vector3D CrossProduct(const Vector3D &a, const Vector3D &b)
Definition vector.cc:210
double DegreesToRadians(double degrees)
converts degrees to radians
Definition angles.cc:28
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
double RadiansToDegrees(double radians)
converts radians to degrees
Definition angles.cc:34
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1396