1 |
//
|
2 |
// SxP4Test.cpp
|
3 |
// This sample code demonstrates how to use the C++ classes in order
|
4 |
// to determine satellite position and look angles.
|
5 |
//
|
6 |
// mfh 12/07/2003
|
7 |
//
|
8 |
#include "stdafx.h"
|
9 |
|
10 |
#include <stdio.h>
|
11 |
#include "cTle.h"
|
12 |
#include "cEci.h"
|
13 |
#include "cOrbit.h"
|
14 |
#include "cSite.h"
|
15 |
|
16 |
|
17 |
/////////////////////////////////////////////////////////////////////////////
|
18 |
// Test routine to output position and velocity information
|
19 |
void PrintPosVel(const cTle &tle)
|
20 |
{
|
21 |
cOrbit orbit(tle);
|
22 |
cEci eci;
|
23 |
vector<cEci> Pos;
|
24 |
|
25 |
// Calculate position, velocity
|
26 |
// mpe = "minutes past epoch"
|
27 |
for (int mpe = 0; mpe <= (360 * 4); mpe += 360)
|
28 |
{
|
29 |
// Get the position of the satellite at time "mpe"
|
30 |
// The coordinates are placed into the local variable "eci".
|
31 |
orbit.getPosition(mpe, &eci);
|
32 |
|
33 |
// Push the coordinates object onto the end of the vector.
|
34 |
Pos.push_back(eci);
|
35 |
}
|
36 |
|
37 |
// Print TLE data
|
38 |
printf("%s\n", tle.getName().c_str());
|
39 |
printf("%s\n", tle.getLine1().c_str());
|
40 |
printf("%s\n\n", tle.getLine2().c_str());
|
41 |
|
42 |
// Header
|
43 |
printf(" TSINCE X Y Z\n\n");
|
44 |
|
45 |
// Iterate over each of the ECI position objects pushed onto the
|
46 |
// position vector, above, printing the ECI position information
|
47 |
// as we go.
|
48 |
for (unsigned int i = 0; i < Pos.size(); i++)
|
49 |
{
|
50 |
printf("%8d.00 %16.8f %16.8f %16.8f\n",
|
51 |
i * 360,
|
52 |
Pos[i].getPos().m_x,
|
53 |
Pos[i].getPos().m_y,
|
54 |
Pos[i].getPos().m_z);
|
55 |
}
|
56 |
|
57 |
printf("\n XDOT YDOT ZDOT\n\n");
|
58 |
|
59 |
// Iterate over each of the ECI position objects in the position
|
60 |
// vector again, but this time print the velocity information.
|
61 |
for (unsigned int i = 0; i < Pos.size(); i++)
|
62 |
{
|
63 |
printf(" %16.8f %16.8f %16.8f\n",
|
64 |
Pos[i].getVel().m_x,
|
65 |
Pos[i].getVel().m_y,
|
66 |
Pos[i].getVel().m_z);
|
67 |
}
|
68 |
}
|
69 |
|
70 |
//////////////////////////////////////////////////////////////////////////////
|
71 |
int main(int argc, char* argv[])
|
72 |
{
|
73 |
// Test SGP4
|
74 |
string str1 = "SGP4 Test";
|
75 |
string str2 = "1 88888U 80275.98708465 .00073094 13844-3 66816-4 0 8";
|
76 |
string str3 = "2 88888 72.8435 115.9689 0086731 52.6988 110.5714 16.05824518 105";
|
77 |
|
78 |
cTle tle1(str1, str2, str3);
|
79 |
|
80 |
PrintPosVel(tle1);
|
81 |
|
82 |
printf("\n");
|
83 |
|
84 |
// Test SDP4
|
85 |
str1 = "SDP4 Test";
|
86 |
str2 = "1 11801U 80230.29629788 .01431103 00000-0 14311-1 8";
|
87 |
str3 = "2 11801 46.7916 230.4354 7318036 47.4722 10.4117 2.28537848 6";
|
88 |
|
89 |
cTle tleSDP4(str1, str2, str3);
|
90 |
|
91 |
PrintPosVel(tleSDP4);
|
92 |
|
93 |
printf("\nExample output:\n");
|
94 |
|
95 |
// Example: Define a location on the earth, then determine the look-angle
|
96 |
// to the SDP4 satellite defined above.
|
97 |
|
98 |
// Create an orbit object using the SDP4 TLE object.
|
99 |
cOrbit orbitSDP4(tleSDP4);
|
100 |
|
101 |
// Create an ECI object to hold the location of the satellite
|
102 |
cEci eciSDP4;
|
103 |
|
104 |
// Get the location of the satellite from the Orbit object. The
|
105 |
// earth-centered inertial information is placed into eciSDP4.
|
106 |
// Here we ask for the location of the satellite 90 minutes after
|
107 |
// the TLE epoch.
|
108 |
orbitSDP4.getPosition(90.0, &eciSDP4);
|
109 |
|
110 |
// Now create a site object. Site objects represent a location on the
|
111 |
// surface of the earth. Here we arbitrarily select a point on the
|
112 |
// equator.
|
113 |
cSite siteEquator(0.0, -100.0, 0); // 0.00 N, 100.00 W, 0 km altitude
|
114 |
|
115 |
// Now get the "look angle" from the site to the satellite.
|
116 |
// Note that the ECI object "eciSDP4" contains a time associated
|
117 |
// with the coordinates it contains; this is the time at which
|
118 |
// the look angle is valid.
|
119 |
cCoordTopo topoLook = siteEquator.getLookAngle(eciSDP4);
|
120 |
|
121 |
// Print out the results. Note that the Azimuth and Elevation are
|
122 |
// stored in the cCoordTopo object as radians. Here we convert
|
123 |
// to degrees using rad2deg()
|
124 |
printf("AZ: %.1f EL: %.1f\n",
|
125 |
rad2deg(topoLook.m_Az),
|
126 |
rad2deg(topoLook.m_El));
|
127 |
|
128 |
}
|
129 |
|