How to write C++ code using SGP4 to propagate satellite position

In summary, the author writes code to propagate a satellite's position and velocity vectors, but is not able to get it to work because he is not familiar with the library functions. He finds a partial answer in the code distribution, but is not able to use it because it lacks documentation and richer comments.
  • #1
thor36
10
0
Greetings all !
I really hope this is the right sub-forum for my question, I have chosen it because I've seen TLE being mentioned a couple of times around here.

I have done some reading on astrodynamics and orbital mechanics, but I am relatively new to coding. I would like to write some C++ code that would make use of this software library ( Computer software in C++ ). So far I am not having success with using "sgp4" and "twoline2rv" routines. Obviously, I don't know how to use them properly, although I tried to follow and understand the routines line by line and particularly paid attention to comments.

Let's say I get the TLE data for ISS online and store it in a file called "isstle.txt", which would look like this :
ISS (ZARYA)
1 25544U 98067A 14296.89020256 .00021128 00000-0 36676-3 0 2914
2 25544 51.6464 181.6097 0002420 294.7068 172.8232 15.50795889911298

I would then like to propagate the satellite's position and velocity vectors from some initial moment ( Tstart, most likely defined by particular TLE ) to a final moment (Tend, say 2 hours after Tstart) and compute state vectors on every "time step" of length dT along the way, including at initial and final moment. These vectors would then be stored in type double arrays.

The algorithm doesn't need to follow the style of following pseudo code, but here is what I have in mind, and it may help clarify my intentions :

TLE from internet -> textfile
SatData = twoline2rv( textfile )
for ( T = Tstart : dT : Tend )
sgp4( SatData, T )
store RV to arrays​
end​

sgp4() and twoline2rv() are actual names of the functions found in the libraries mentioned earlier.
I would very much appreciate a piece of sample code that can solve this problem or at least help orient myself a little. Of course any other tips and hints are just as welcome.

Thank you very much and kind regards
T
 
Last edited:
Technology news on Phys.org
  • #2
Thanks for the post! Sorry you aren't generating responses at the moment. Do you have any further information, come to any new conclusions or is it possible to reword the post?
 
  • #3
Thank you for reply ! My question is very very specific, so I knew posting it is quite a long shot.

I have found a partial answer - the code distribution contains a "testcpp.cpp" file which provides a case of implementation. Using it is fine for start, but being a test example it has limitations. Therefore one is still in for a lot of code study and experimentation if he wants to implement his own algorithms. I suppose it is not a big problem for experienced coders, but to a beginner the lack of documentation and wealthier comments can be some trouble.

If it feels necessary I can try reword the post too. However, I don't see an "edit" button anymore.
 

1. How do I initialize the SGP4 class in C++?

The SGP4 class can be initialized in C++ by including the appropriate header file and creating an instance of the class with the desired satellite TLE (Two-Line Element) data. This can be done using the constructor or the member function initializeSGP4() with the TLE data as parameters.

2. How do I use the SGP4 class to propagate satellite position?

To propagate satellite position using the SGP4 class, first initialize the class with the desired TLE data. Then, use the member function sgp4() to update the position and velocity vectors of the satellite at a given time. This function takes the desired time as input and returns the updated position and velocity vectors.

3. Can I use the SGP4 class to propagate the position of multiple satellites simultaneously?

Yes, the SGP4 class can be used to propagate the position of multiple satellites simultaneously. Simply create separate instances of the class for each satellite with their respective TLE data, and call the sgp4() function for each satellite at the desired time.

4. How do I handle errors and exceptions while using the SGP4 class?

The SGP4 class has built-in error handling and exception handling mechanisms. The class has a member function getErrorCode() that returns an integer value corresponding to different types of errors. Additionally, the class also has a getErrorMsg() function that returns a string containing a description of the error. These can be used to handle errors and exceptions in the code.

5. Are there any limitations to using the SGP4 class in C++?

Yes, there are a few limitations to using the SGP4 class in C++. One major limitation is that the class does not take into account atmospheric drag, which can have a significant effect on the position and velocity of the satellite. Additionally, the class uses simplified analytical methods for propagation and may not be as accurate as more complex numerical methods. It is important to consider these limitations when using the SGP4 class for satellite position propagation.

Similar threads

Replies
1
Views
3K
Back
Top