-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaunchAzimuthCalculator - sin GUI.py
More file actions
168 lines (133 loc) · 4.85 KB
/
LaunchAzimuthCalculator - sin GUI.py
File metadata and controls
168 lines (133 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 28 12:41:59 2024
@author: miguelangel
# Todas las unidades en SI (metros, kilogramos, segundos)
"""
import math as mt
def calculo_simple():
# Valores por defecto y constantes
launch_lat = 28.5
desired_inc = 51.6
target_speed = 7729.516427
RAD_TO_DEG = 180 / mt.pi
DEG_TO_RAD = mt.pi / 180
# Calculations
b_azimuth = mt.asin(mt.cos(desired_inc * DEG_TO_RAD) / mt.cos(launch_lat * DEG_TO_RAD))
v_x_rot = (target_speed * mt.sin(b_azimuth)) - (464.5812 * mt.cos(launch_lat * DEG_TO_RAD))
v_y_rot = target_speed * mt.cos(b_azimuth)
true_azimuth = mt.atan(v_x_rot / v_y_rot)
return true_azimuth * RAD_TO_DEG
# valores por defecto (Tierra) y otras constantes
masa = 5.973698968e+24
radio = 6371010.0
periodo = 86164.10132
G = 6.67384e-11 # constante gravitacional
launch_lat = 28.5 #KSC
target_inc = 51.6 #ISS
#target_speed = 7729.52 #para órbita en la tierra de 300 km.
target_orbit = 300
# Conversión grados -> radianes.
grad_to_rad = mt.pi / 180
# leemos la lista de cuerpos
bodies_data = {}
msg = ''
try:
with open("bodies_data.cfg", "r") as f:
bd = f.readlines()
# algunos chequeos para comprobar el archivo
if len(bd) > 1 and bd[0].split('\t')[0] == "Planet name":
# Almacenamos los valores en un diccionario
for l in bd[1:]:
bodies_data[l.split('\t')[0]] = list(float(i.replace('None', '0')) for i in l[:-1].split('\t')[1:])
msg = "Cargados " + str(len(bd)-1) + " cuerpos celestes."
else:
raise Exception
except:
msg = "No se encuentra el fichero de datos, o contiene errores.\n"\
"Usaremos los datos de la Tierra."
#print(msg)
bodies_data['Earth'] = [masa, radio, periodo]
# funciones necesarias
def betaInertial(inc,lat):
# returns the inertial azimuth
sine = mt.cos(inc) / mt.cos(lat)
beta = mt.asin(sine)
return beta
def azimuth(lat,inertial,v_orb,v_rot):
# returns the inertial launch azimuth for the rocket to target
vxrot = (v_orb * mt.sin(inertial)) - (v_rot * mt.cos(lat))
vyrot = v_orb * mt.cos(inertial)
return [mt.atan(vxrot/vyrot), vxrot, vyrot]
def vBoost(xrot,yrot):
# returns the effective delta-v needed to be produced
return mt.sqrt( xrot**2 + yrot**2)
def resultado(body,launch_lat,target_inc,target_orbit):
'''
#ta = str(round(calculo_simple(), 2))
# Print Data
print("True Azimuth:", calculo_simple())
'''
masa, radio, periodo = bodies_data[body]
latitude = launch_lat * grad_to_rad
inclination = target_inc * grad_to_rad
altitude = target_orbit * 1000
vOrb = mt.sqrt(masa * G / (altitude + radio))
vRot = 2 * mt.pi * radio / periodo
beta_inert = betaInertial(inclination, latitude)
az = azimuth(latitude, beta_inert, vOrb, vRot)
heading = az[0] / grad_to_rad
delta_v = vOrb - vBoost(az[1],az[2])
'''
# Print outputs -----------------------------------------
if heading < 0:
heading1 = heading + 360
else:
heading1 = heading
heading2 = 180 - heading
print("Launch azimuth in degrees:")
print(round(heading1,2))
if heading1 != heading2:
print(round(heading2,2))
print("\nOrbital speed in meters per second, and vRot:")
print(round(vOrb,2),round(vRot*mt.cos(latitude),2))
print("\nDelta-v required, less gravity/drag losses:")
print(round(vOrb - delta_v,2))
print("\nSpeed saved in meters per second:")
print(round(delta_v,2))
'''
return [heading, vOrb, vOrb-delta_v, msg]
def main():
# Hay que recoger por consola:
# body, launch_lat, target_inc, target_orbit
# ojo, chequear:
# target_orbit > 0
# target_inc > launch_lat en valores absolutos mt.absolute()
datos = resultado('Earth', 28.5, 51.6, 300)
print(f'Heading: {round(datos[0],2)}, vOrb: {round(datos[1],2)}, Delta_v: {round(datos[2])}')
print("Mensaje:", datos[3])
#360-a,a,a+180,180-a
# interfaz gráfica
'''
from tkinter import Tk
ventana = Tk()
ventana.title(ta)
ventana.minsize(width=300, height=200)
ventana.config(padx=10, pady=20)
ventana.mainloop()
# auto-py-to-exe
import tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=300, height=300)
canvas.pack()
def hello():
label = tk.Label(
root, text=ta, fg="blue", font=("Arial", 18, "bold")
)
canvas.create_window(150, 200, window=label)
button = tk.Button(text="Calcular", command=hello, bg="brown", fg="white")
canvas.create_window(150, 150, window=button)
root.mainloop()
'''
if __name__ == "__main__":
main()