about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <you@example.com>2022-02-09 10:17:11 +0000
committerBaitinq <you@example.com>2022-02-09 10:26:05 +0000
commit97337879d2e60c3b6ee73e283547f6c61cf6067a (patch)
tree56957b3a2a0a1955fcef83fa9061191cc9462a48
parentAdd support for rocket stages (diff)
downloadOSLS-97337879d2e60c3b6ee73e283547f6c61cf6067a.tar.gz
OSLS-97337879d2e60c3b6ee73e283547f6c61cf6067a.tar.bz2
OSLS-97337879d2e60c3b6ee73e283547f6c61cf6067a.zip
Fixed thrust calculation by taking g into account
-rw-r--r--engine.py5
-rw-r--r--fuel.py5
-rw-r--r--main.py14
-rw-r--r--simulation.py2
-rw-r--r--stage.py4
5 files changed, 15 insertions, 15 deletions
diff --git a/engine.py b/engine.py
index bc08a43..f1da646 100644
--- a/engine.py
+++ b/engine.py
@@ -6,8 +6,9 @@ class Engine():
         self.max_flow_rate = max_flow_rate
         self.isp = isp
 
-    def thrust(self, throttle: int):
-        return self.flow_rate(throttle) * self.isp
+    def thrust(self, throttle: int, g: float):
+        #https://www.grc.nasa.gov/www/k-12/airplane/specimp.html
+        return self.flow_rate(throttle) * self.isp * g
 
     def flow_rate(self, throttle: int):
         return self.max_flow_rate * (throttle / 100)
\ No newline at end of file
diff --git a/fuel.py b/fuel.py
index 11fc233..caca9a9 100644
--- a/fuel.py
+++ b/fuel.py
@@ -1,4 +1,3 @@
 class Fuel():
-    def __init__(self, name: str, energy_density: float):
-        self.name = name
-        self.energy_density = energy_density
\ No newline at end of file
+    def __init__(self, name: str):
+        self.name = name
\ No newline at end of file
diff --git a/main.py b/main.py
index f94780a..d2c92d1 100644
--- a/main.py
+++ b/main.py
@@ -15,9 +15,8 @@ import pygame
 from pygame.locals import *
 
 def main(argv):
-    #add engine mass
-    raptor_engine = Engine(name="raptor", isp=360, max_flow_rate=9000) #https://en.wikipedia.org/wiki/SpaceX_Raptor
-    methane_fuel = Fuel(name="methane", energy_density=None) #TODO: density
+    raptor_engine = Engine(name="raptor", isp=360, max_flow_rate=931) #https://en.wikipedia.org/wiki/SpaceX_Raptor
+    methane_fuel = Fuel(name="methane") #TODO: more
 
     #https://en.wikipedia.org/wiki/SpaceX_Starship
     first_stage = Stage(name="superheavy booster",
@@ -93,7 +92,6 @@ def main(argv):
             print("delta: " + str(delta))
             simulation.tick(delta=delta)
 
-        #TODO: support rocket engine mass
         #TODO: draw floor, flame (continuity)
         #TODO: do max load on rocket so it blows up
         #TODO: allow for x movement, speed, accel etc
@@ -131,7 +129,7 @@ def draw_simulation(simulation_display: type[pygame.Surface], simulation: type[S
         simulation_display.blit(font.render("Altitude: {:.0f}m".format(simulation.y), False, (255, 255, 255)),(0,40))
         simulation_display.blit(font.render("Speed: {:.0f}m/s".format(simulation.speed_y), False, (255, 255, 255)),(0,80))
         simulation_display.blit(font.render("Acceleration: {:.2f}m/s2".format(simulation.acceleration_y), False, (255, 255, 255)),(0,120))
-        simulation_display.blit(font.render("Thrust: {:.0f}N".format(simulation.rocket.current_stage().current_thrust()), False, (255, 255, 255)),(0,160))
+        simulation_display.blit(font.render("Thrust: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(simulation.body.g(simulation.universe.G, simulation.y))), False, (255, 255, 255)),(0,160))
         simulation_display.blit(font.render("Fuel in stage: {:.0f}kg".format(simulation.rocket.current_stage().fuel_mass), False, (255, 255, 255)),(0,200))
         simulation_display.blit(font.render("Stage mass: {:.0f}kg".format(simulation.rocket.current_stage().total_mass()), False, (255, 255, 255)),(0,240))
         simulation_display.blit(font.render("Rocket mass: {:.0f}kg".format(simulation.rocket.total_mass()), False, (255, 255, 255)),(0,280))
@@ -188,9 +186,11 @@ def handle_key_press(simulation, key):
         if current_stage.throttle < 100:
             current_stage.throttle += 1
     elif key == pygame.K_LEFT:
-        sys.exit(0)
+        return None
+        #sys.exit(0)
     elif key == pygame.K_RIGHT:
-        sys.exit(0)
+        return None
+        #sys.exit(0)
 
 if __name__ == "__main__":
     main(sys.argv)
\ No newline at end of file
diff --git a/simulation.py b/simulation.py
index 4d6fc73..cad7772 100644
--- a/simulation.py
+++ b/simulation.py
@@ -34,7 +34,7 @@ class Simulation():
         #upwards_force = fuel_used * self.rocket.fuel_type.energy_density #we should calculate thrust based on this
         upwards_force = 0
         if fuel_used > 0:
-            upwards_force = current_stage.current_thrust()
+            upwards_force = current_stage.current_thrust(self.body.g(self.universe.G, self.y))
         print("Upwards force: " + str(upwards_force))
 
         print("g: " + str(self.body.g(G=self.universe.G, height=self.y)))
diff --git a/stage.py b/stage.py
index 783e1f4..0df1d52 100644
--- a/stage.py
+++ b/stage.py
@@ -18,9 +18,9 @@ class Stage():
     def total_mass(self):
         return (self.stage_mass + self.fuel_mass)
 
-    def current_thrust(self):
+    def current_thrust(self, g: float):
         if(self.engines_on and self.fuel_mass > 0):
-            return self.engine.thrust(self.throttle) * self.engine_number
+            return self.engine.thrust(self.throttle, g) * self.engine_number
         else:
             return 0