Rendez-vous with bit of calculations and C language

HDavy

Registered
#1
This is my first attempt at using astrodynamics formulas to play more efficiently (especially for rendez-vous).
I used to time warp for a countless number of revolutions waiting for the Soyuz to meet the ISS.
It all began with the very basics like Newton' second and third laws of motion and the universal law of gravitation.

The tangential velocity helped me to get familiar with the units and thanks to it, I calculated the G.Me constant also simplified as "µ".
To do so, I measured the orbital period of a satellite orbiting Earth with a circular orbit (eccentricity=0) since then, with the second formula where 'T' is now known and 'r' is the orbit radius, by doing the math we can find that µ is approximately 971410890600. Its value is based on a simple measure.
Next step was to do it over again with the elliptical orbit formulas and apply them to other spacecrafts. I concluded that I found the good value of µ.

Now my goal was to put all that together in a simple C program which would tell me when to launch the Soyuz to rendez-vous the ISS in the shortest time.

First version of the code shown below:

Screen Shot 2019-01-06 at 4.52.13 PM.png


Let me now explain the principle:
1) You are asked to giver the target apoapsis and periapsis.
2) The program calculates the orbital period of the target (Tiss variable).
3) Now we suppose that both spacecrafts are at the same location which means the Soyuz reached its apoapsisnext to the ISS. From now, tanks to the "tsto" constant, the program can say where the ISS should have been at liftoff.
The "tsto" constant was determined after a lot of soyuz launches. It is basically the average time elapsed between liftoff and the end of the first Hohmann transfer burn for an identical path.
4) The program finally calculates an angle and shows it. You also have other informations such as the orbital period of the ISS, its max and min velocity.
I'll explain what is the calculated angle don't worry!

I know this is the most illegal way to do astrodynamics but hey it works!

Anyways, it's a really basic C file I run with the terminal using "./":p
Here's an example of what you can get as result:
Screen Shot 2019-01-06 at 4.51.14 PM.png

As you can see, it says you to launch when there is an angle of 44.8° or about π/4 if you prefer!
But now you have to know where to put it. On the following screenshot, you can see a red angle this is the one the program just gave you! It's really important to have it well placed. Adding the other angle to the red makes 90°. The next picture shows the kind of abaci that help me to launch the rocket quite precisely. To use them you just have to put the abacus on the screen and wait for the target to be on the line.
Screenshot_20190106-163326.jpg IMG_20190106_172618.jpg

Unfortunately, this only works with my Soyuz or any rocket with the same performance/spec. I did another version for my Falcon 9 block 5 (and it works really nice as well !). But I'm currently working on a new version that can be applied to any rocket as long as it can lift a payload into orbit and has enough fuel left!

This might already be obvious for some of you but I wanted to share my work and maybe help those who'd like or planned to do a similar thing.

Finally, here's a quick video of a demo flight:


I hope I was clear, and sorry for the long post !:)
 

Altaïr

Space Stig, Master of gravity
Staff member
Head Moderator
Team Kolibri
Modder
TEAM HAWK
Atlas
Deja Vu
Under Pressure
Forum Legend
#2
Wow, very impressive! I already thought about doing something like that, but to plan injection burns to go to other planets instead. You did it, congratulations! ;)
However there's a way easier way to get the "mu" parameter. By using the gravitational field formula:
g = mu/r^2, with r being the planet radius, and g the gravity at its surface.
You can write it as mu = g × r^2, and then you can get g and r from the planet data.
For Earth that gives 972,405 km^3/s^2, so you were very close.
 

HDavy

Registered
#3
Wow, very impressive! I already thought about doing something like that, but to plan injection burns to go to other planets instead. You did it, congratulations! ;)
However there's a way easier way to get the "mu" parameter. By using the gravitational field formula:
g = mu/r^2, with r being the planet radius, and g the gravity at its surface.
You can write it as mu = g × r^2, and then you can get g and r from the planet data.
For Earth that gives 972,405 km^3/s^2, so you were very close.
Thanks! I've never seen this formula before :)
Indeed it's more easy that way and more accurate!
 
#4
This is my first attempt at using astrodynamics formulas to play more efficiently (especially for rendez-vous).
I used to time warp for a countless number of revolutions waiting for the Soyuz to meet the ISS.
It all began with the very basics like Newton' second and third laws of motion and the universal law of gravitation.

The tangential velocity helped me to get familiar with the units and thanks to it, I calculated the G.Me constant also simplified as "µ".
To do so, I measured the orbital period of a satellite orbiting Earth with a circular orbit (eccentricity=0) since then, with the second formula where 'T' is now known and 'r' is the orbit radius, by doing the math we can find that µ is approximately 971410890600. Its value is based on a simple measure.
Next step was to do it over again with the elliptical orbit formulas and apply them to other spacecrafts. I concluded that I found the good value of µ.

Now my goal was to put all that together in a simple C program which would tell me when to launch the Soyuz to rendez-vous the ISS in the shortest time.

First version of the code shown below:

View attachment 11547

Let me now explain the principle:
1) You are asked to giver the target apoapsis and periapsis.
2) The program calculates the orbital period of the target (Tiss variable).
3) Now we suppose that both spacecrafts are at the same location which means the Soyuz reached its apoapsisnext to the ISS. From now, tanks to the "tsto" constant, the program can say where the ISS should have been at liftoff.
The "tsto" constant was determined after a lot of soyuz launches. It is basically the average time elapsed between liftoff and the end of the first Hohmann transfer burn for an identical path.
4) The program finally calculates an angle and shows it. You also have other informations such as the orbital period of the ISS, its max and min velocity.
I'll explain what is the calculated angle don't worry!

I know this is the most illegal way to do astrodynamics but hey it works!

Anyways, it's a really basic C file I run with the terminal using "./":p
Here's an example of what you can get as result:
View attachment 11548
As you can see, it says you to launch when there is an angle of 44.8° or about π/4 if you prefer!
But now you have to know where to put it. On the following screenshot, you can see a red angle this is the one the program just gave you! It's really important to have it well placed. Adding the other angle to the red makes 90°. The next picture shows the kind of abaci that help me to launch the rocket quite precisely. To use them you just have to put the abacus on the screen and wait for the target to be on the line.
View attachment 11550 View attachment 11556

Unfortunately, this only works with my Soyuz or any rocket with the same performance/spec. I did another version for my Falcon 9 block 5 (and it works really nice as well !). But I'm currently working on a new version that can be applied to any rocket as long as it can lift a payload into orbit and has enough fuel left!

This might already be obvious for some of you but I wanted to share my work and maybe help those who'd like or planned to do a similar thing.

Finally, here's a quick video of a demo flight:


I hope I was clear, and sorry for the long post !:)
A real autopilot? Nice. Do you know of kOS for KSP?
 

Altaïr

Space Stig, Master of gravity
Staff member
Head Moderator
Team Kolibri
Modder
TEAM HAWK
Atlas
Deja Vu
Under Pressure
Forum Legend
#6
Thanks! I've never seen this formula before :)
Indeed it's more easy that way and more accurate!
You can get it from 2 very well known formulas:
F = G×M×m/r^2
and P = m×g
P is the same force as F (it's just used at ground level on a small scale), so you have:
m×g = G×M×m/r^2.
Simplify, congratulations, you just found g! ;)
 
#9
You should try to make a flight computer, I did mine. Basically there will be a different cmd window that shows me all the flight parameters (velocity, orbital altitude, eccentricity, delta velocity etc.), at the bottom there will be a prompt to select a task for the computer to perform. So far for me there are only 2 tasks, and that is Interplanetary Course Planner and Orbital Maneuver Planner.

Interplanetary Course Planner (Written as ICP in the program for ease of reading) will prompt the user for current position and orbital parameters, then it will ask the user for planned destination and final orbital parameters, once done the computer will calculate the burn window, burn time and display the delta velocity required for said maneuver. (I am using Altair's equations.)

However the flaw of this program is that its not automatic and it can only calculate one type of route, I am trying to make the program read from the game so that I just need to key in my destination plans, this part should be easy to implement. Right now I am planning to program the ICP to be able to calculate both Hohmann Transfer and Oberth Gravity Assist Transfer.

Orbital Maneuver Planner or OMP will prompt the user for current flight parameters, then for the planned final orbital parameter and calculate the delta velocity needed. The flaw is the same here, its not automatic.

It'll be cool to see your work progress into a full on flight computer like or better than mine!
 
#10
If I can remember my code correctly, for the prompt:
Could be the wrong one, It's been months since I worked on it :(

#include stdio.h

.
.
.

int main ()
{
int Ve;
int Pap;
int Aap;
cout << "Please enter your velocity: ";
cin >> Ve;
cout << "Velocity: " << Ve;
return 0;

cout << "Please enter your current periapse: ";
cin >> Pap;
cout << "C. Periapse: " << Pap;
return 0;

cout << "Please enter your current apoapse: ";
cin >> Aap;
cout << "C. Apoapse: " << Aap;
return 0;
}