29 #include <ns3/boolean.h>
31 #include <ns3/simulator.h>
32 #include <ns3/string.h>
34 NS_LOG_COMPONENT_DEFINE(
"sat-sgp4-mobility-model");
39 NS_OBJECT_ENSURE_REGISTERED(SatSGP4MobilityModel);
48 TypeId(
"ns3::SatSGP4MobilityModel")
50 .AddConstructor<SatSGP4MobilityModel>()
51 .AddAttribute(
"StartDateStr",
52 "Absolute start time of simulation (UTC)",
53 StringValue(
"1992-01-01 00:00:00"),
56 .AddAttribute(
"UpdatePositionEachRequest",
57 "Compute position each time a packet is transmitted",
62 "UpdatePositionPeriod",
63 "Period of satellite position refresh, if UpdatePositionEachRequest is false",
64 TimeValue(Seconds(1)),
77 : m_startStr(
"1992-01-01 00:00:00"),
78 m_timeLastUpdate(Time::Min())
80 NS_LOG_FUNCTION(
this);
82 ObjectBase::ConstructSelf(AttributeConstructionList());
93 NS_LOG_FUNCTION(
this);
101 NS_LOG_FUNCTION(
this << t);
109 NS_LOG_FUNCTION(
this);
125 return 1000 *
rvTemeTovItrf(Vector3D(r[0], r[1], r[2]), Vector3D(v[0], v[1], v[2]), cur);
131 NS_LOG_FUNCTION(
this);
139 NS_LOG_FUNCTION(
this << position);
147 NS_LOG_FUNCTION(
this);
178 NS_LOG_FUNCTION(
this << position);
187 NS_LOG_FUNCTION(
this);
195 NS_LOG_FUNCTION(
this);
206 NS_LOG_FUNCTION(
this << tle);
208 uint32_t delimPos = tle.find(
"\n");
209 const std::string line1 = tle.substr(0, delimPos);
210 const std::string line2 = tle.substr(delimPos + 1, tle.size() - delimPos);
212 double start, stop, delta;
217 "Two-Line Element info lines must be of length" <<
TleSatInfoWidth <<
"!");
219 m_tle1 = std::string(line1.c_str());
220 m_tle2 = std::string(line2.c_str());
222 memcpy(l1, line1.c_str(),
sizeof(l1));
223 memcpy(l2, line2.c_str(),
sizeof(l2));
235 NS_FATAL_ERROR(
"Simulation start date "
237 <<
" after TLE epoch. TLE are only valid for a few days");
242 NS_FATAL_ERROR(
"Error while loading TLE file");
254 return pmt * (tmt * rteme);
259 const Vector3D& vteme,
266 return pmt * ((tmt * vteme) -
CrossProduct(w, tmt * rteme));
274 const double &xp = eop.first, &yp = eop.second;
275 const double cosxp = cos(xp), cosyp = cos(yp);
276 const double sinxp = sin(xp), sinyp = sin(yp);
302 const double gmst = t.
GetGmst();
303 const double cosg = cos(gmst), sing = sin(gmst);
314 return Matrix(cosg, sing, 0, -sing, cosg, 0, 0, 0, 1);
341 return Vector3D(m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z,
342 m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z,
343 m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z);
GeoCoordinate class is used to store and operate with geodetic coordinates.
Vector ToVector() const
Converts Geodetic coordinates to Cartesian coordinates.
Class to handle Julian days and provide respective Earth Orientation Parameters (EOP).
double GetGmst(void) const
Retrieve the Greenwich Mean Sidereal Time.
double GetOmegaEarth(void) const
Retrieve Earth's angular velocity.
std::pair< double, double > GetPolarMotion(void) const
Retrieve the polar motion cofficients measured/predicted.
Keep track of the current position and velocity of an object in satellite network.
void NotifyGeoCourseChange(void) const
std::string m_startStr
Simulation absolute start time in string format.
virtual void DoSetGeoPosition(const GeoCoordinate &position)
static const gravconsttype WGeoSys
World Geodetic System (WGS) constants to be used by SGP4/SDP4 models.
JulianDate GetStartTime() const
Get the time instant considered as the simulation start.
virtual void DoSetPosition(const Vector &position)
static const uint32_t TleSatInfoWidth
Satellite's information line size defined by TLE data format.
GeoCoordinate m_lastPosition
Last saved satellite position.
void SetStartTime(const JulianDate &t)
Set the time instant considered as the simulation start.
SatSGP4MobilityModel()
Default constructor.
TypeId GetInstanceTypeId(void) const
static Matrix PefToItrf(const JulianDate &t)
Retrieve the matrix for converting from PEF to ITRF at a given time.
Time m_updatePositionPeriod
Period of satellite position refresh, if UpdatePositionEachRequest is false.
JulianDate GetTleEpoch(void) const
Retrieve the TLE epoch time.
bool m_updatePositionEachRequest
Compute position each time a packet is transmitted.
virtual Vector DoGetVelocity() const
elsetrec m_sgp4_record
SGP4/SDP4 record.
static Vector3D rvTemeTovItrf(const Vector3D &rteme, const Vector3D &vteme, const JulianDate &t)
Retrieve the satellite's velocity vector in ITRF coordinates.
static Matrix TemeToPef(const JulianDate &t)
Retrieve the matrix for converting from TEME to PEF at a given time.
Time m_timeLastUpdate
Last position update time.
std::string m_tle2
satellite's TLE data.
static TypeId GetTypeId(void)
Get the type ID.
static Vector3D rTemeTorItrf(const Vector3D &rteme, const JulianDate &t)
Retrieve the satellite's position vector in ITRF coordinates.
virtual GeoCoordinate DoGetGeoPosition() const
bool IsInitialized(void) const
Check if the satellite has already been initialized.
virtual Vector DoGetPosition() const
void SetTleInfo(const std::string &tle)
Set satellite's TLE information required for its initialization.
JulianDate m_start
Simulation absolute start time.
virtual ~SatSGP4MobilityModel()
Destructor.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Vector3D CrossProduct(const Vector3D &v1, const Vector3D &v2)
Cross product of two Vector3D objects.
void twoline2rv(char longstr1[130], char longstr2[130], char typerun, char typeinput, char opsmode, gravconsttype whichconst, double &startmfe, double &stopmfe, double &deltamin, elsetrec &satrec)
bool sgp4(gravconsttype whichconst, elsetrec &satrec, double tsince, double r[3], double v[3])
Matrix data structure to make coordinate conversion code clearer and less verbose.
Vector3D operator*(const Vector3D &v) const