diff options
author | Baitinq <you@example.com> | 2022-02-09 12:23:40 +0000 |
---|---|---|
committer | Baitinq <you@example.com> | 2022-02-09 18:01:23 +0000 |
commit | f01fdaaa948bc087978b24baf9af665739997167 (patch) | |
tree | 147b11e48b8a3296d47cef621aed67fc8b88987a | |
parent | Removed unnecessary plank constant (diff) | |
download | OSLS-f01fdaaa948bc087978b24baf9af665739997167.tar.gz OSLS-f01fdaaa948bc087978b24baf9af665739997167.tar.bz2 OSLS-f01fdaaa948bc087978b24baf9af665739997167.zip |
Started preparation to implement x movement
-rw-r--r-- | main.py | 40 | ||||
-rw-r--r-- | simulation.py | 25 | ||||
-rw-r--r-- | stage.py | 18 |
3 files changed, 58 insertions, 25 deletions
diff --git a/main.py b/main.py index e5ad3c8..c369814 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,7 @@ def main(argv): stage_mass=180000, engine=raptor_engine, engine_number=33, + max_engine_gimbaling_angle=30, fuel_type=methane_fuel, fuel_mass=3600000, drag_coefficient=1.18, @@ -33,6 +34,7 @@ def main(argv): stage_mass=80000, engine=raptor_engine, engine_number=6, + max_engine_gimbaling_angle=30, fuel_type=methane_fuel, fuel_mass=1200000, drag_coefficient=1.18, @@ -126,16 +128,25 @@ def draw_simulation(simulation_display: type[pygame.Surface], simulation: type[S #draw stats text font = pygame.font.SysFont("Comic Sans MS", 30) + curr_thrust = simulation.rocket.current_stage().current_thrust(simulation.body.g(simulation.universe.G, simulation.y)) + g = simulation.body.g(simulation.universe.G, simulation.y) + simulation_display.blit(font.render("Simulation time: {:.0f}s".format(simulation.time), False, (255, 255, 255)),(0,0)) - 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(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)) - simulation_display.blit(font.render("Stage number: {:.0f}".format(simulation.rocket.stages_spent), False, (255, 255, 255)),(0,320)) - simulation_display.blit(font.render("Throttle: {:.0f}%".format(simulation.rocket.current_stage().throttle), False, (255, 255, 255)),(0,360)) + simulation_display.blit(font.render("X: {:.0f}m".format(simulation.x), False, (255, 255, 255)),(0,40)) + simulation_display.blit(font.render("Y: {:.0f}m".format(simulation.y), False, (255, 255, 255)),(0,80)) + simulation_display.blit(font.render("Speed x: {:.0f}m/s".format(simulation.speed_x), False, (255, 255, 255)),(0,120)) + simulation_display.blit(font.render("Speed y: {:.0f}m/s".format(simulation.speed_y), False, (255, 255, 255)),(0,160)) + simulation_display.blit(font.render("Acceleration x: {:.2f}m/s2".format(simulation.acceleration_x), False, (255, 255, 255)),(0,200)) + simulation_display.blit(font.render("Acceleration y: {:.2f}m/s2".format(simulation.acceleration_y), False, (255, 255, 255)),(0,240)) + simulation_display.blit(font.render("Thrust x: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g)[0]), False, (255, 255, 255)),(0,280)) + simulation_display.blit(font.render("Thrust y: {:.0f}N".format(simulation.rocket.current_stage().current_thrust(g)[1]), False, (255, 255, 255)),(0,320)) + simulation_display.blit(font.render("Altitude: {:.0f}m".format(simulation.y), False, (255, 255, 255)),(0,360)) + simulation_display.blit(font.render("Fuel in stage: {:.0f}kg".format(simulation.rocket.current_stage().fuel_mass), False, (255, 255, 255)),(0,400)) + simulation_display.blit(font.render("Stage mass: {:.0f}kg".format(simulation.rocket.current_stage().total_mass()), False, (255, 255, 255)),(0,440)) + simulation_display.blit(font.render("Rocket mass: {:.0f}kg".format(simulation.rocket.total_mass()), False, (255, 255, 255)),(0,480)) + simulation_display.blit(font.render("Stage number: {:.0f}".format(simulation.rocket.stages_spent), False, (255, 255, 255)),(0,520)) + simulation_display.blit(font.render("Throttle: {:.0f}%".format(simulation.rocket.current_stage().throttle), False, (255, 255, 255)),(0,560)) + simulation_display.blit(font.render("Gimbal: {:.0f}deg".format(simulation.rocket.current_stage().gimbal), False, (255, 255, 255)),(0,600)) #draw rocket first_stage_height = 90 #TODO @@ -158,6 +169,7 @@ def draw_simulation(simulation_display: type[pygame.Surface], simulation: type[S flame_radius = 10 flame_color = (255, 125, 100) + #TODO: Rotate rocket with gimbal? or with accel? probs with accel i = simulation.rocket.stages_spent stage_height = first_stage_height / (i + 1) stage_y = rocket_y + first_stage_height - stage_height @@ -187,11 +199,13 @@ def handle_key_press(simulation, key): if current_stage.throttle < 100: current_stage.throttle += 1 elif key == pygame.K_LEFT: - return None - #sys.exit(0) + current_stage = simulation.rocket.current_stage() + if current_stage.gimbal > 0 - current_stage.max_engine_gimbaling_angle: + current_stage.gimbal -= 1 elif key == pygame.K_RIGHT: - return None - #sys.exit(0) + current_stage = simulation.rocket.current_stage() + if current_stage.gimbal < 0 + current_stage.max_engine_gimbaling_angle: + current_stage.gimbal += 1 if __name__ == "__main__": main(sys.argv) \ No newline at end of file diff --git a/simulation.py b/simulation.py index cad7772..ff8bd4e 100644 --- a/simulation.py +++ b/simulation.py @@ -17,8 +17,11 @@ class Simulation(): self.universe = universe self.body = body self.rocket = rocket - self.y = 0 + self.x = 0#TODO + self.y = 0 #TODO: we need to make it so there is height() to calc height based on x and y + self.speed_x = 0#TODO self.speed_y = 0 + self.acceleration_x = 0#TODO self.acceleration_y = 0 #simulation logic @@ -31,21 +34,20 @@ class Simulation(): current_stage.fuel_mass -= fuel_used print("Fuel remaining: " + str(current_stage.fuel_mass)) - #upwards_force = fuel_used * self.rocket.fuel_type.energy_density #we should calculate thrust based on this + #TODO: FORCE_X AND FORCE_Y + upwards_force = 0 if fuel_used > 0: - upwards_force = current_stage.current_thrust(self.body.g(self.universe.G, self.y)) + upwards_force = current_stage.current_thrust(self.body.g(self.universe.G, self.y))[1] print("Upwards force: " + str(upwards_force)) - print("g: " + str(self.body.g(G=self.universe.G, height=self.y))) - - #calculate downwards force by drag and gravity - gravitational_force = self.body.g(G=self.universe.G, height=self.y) * self.rocket.total_mass() - print("Gravity: " + str(gravitational_force)) + #print("Y THRUST: " + str(upwards_force)) + #print("TOTAL THRUST: " + str(current_stage.convert_y_component_to_total_with_gimbal(upwards_force))) print("BODY MASS: " + str(self.body.mass())) print("ROCKET TOTAL MASS: " + str(self.rocket.total_mass())) + #calculate downwards force by drag and gravity print("Atmosphere density: " + str(self.body.atmosphere.density_at_height(self.y, self.body.g(G=self.universe.G, height=self.y)))) #https://www.grc.nasa.gov/www/k-12/airplane/drageq.html @@ -55,6 +57,13 @@ class Simulation(): drag_force *= -1 print("Drag: " + str(drag_force)) + print("g: " + str(self.body.g(G=self.universe.G, height=self.y))) + + gravitational_force = self.body.g(G=self.universe.G, height=self.y) * self.rocket.total_mass() + print("Gravity: " + str(gravitational_force)) + + + downwards_force = gravitational_force + drag_force #shouldnt delta influence, TODO: WAIT DRAG COULD BE POSITIVE OR NEGATIVE print("Downwards force: " + str(downwards_force)) diff --git a/stage.py b/stage.py index 0df1d52..b3140c8 100644 --- a/stage.py +++ b/stage.py @@ -1,8 +1,10 @@ +import math + from engine import Engine from fuel import Fuel class Stage(): - def __init__(self, name: str, stage_mass: int, engine: type[Engine], engine_number: int, fuel_type: type[Fuel], fuel_mass: int, drag_coefficient: float, cross_sectional_area: float): + def __init__(self, name: str, stage_mass: int, engine: type[Engine], engine_number: int, max_engine_gimbaling_angle: int, fuel_type: type[Fuel], fuel_mass: int, drag_coefficient: float, cross_sectional_area: float): self.name = name self.stage_mass = stage_mass self.engine = engine @@ -12,17 +14,22 @@ class Stage(): self.drag_coefficient = drag_coefficient self.cross_sectional_area = cross_sectional_area + self.max_engine_gimbaling_angle = max_engine_gimbaling_angle + self.gimbal = 0 self.throttle = 100 self.engines_on = False def total_mass(self): return (self.stage_mass + self.fuel_mass) - def current_thrust(self, g: float): + def current_thrust(self, g: float) -> (float, float): if(self.engines_on and self.fuel_mass > 0): - return self.engine.thrust(self.throttle, g) * self.engine_number + total_thrust = self.engine.thrust(self.throttle, g) * self.engine_number + thrust_x = math.fabs(math.sin(math.radians(self.gimbal)) * total_thrust) + thrust_y = math.fabs(math.cos(math.radians(self.gimbal)) * total_thrust) + return (thrust_x, thrust_y) else: - return 0 + return (0, 0) def total_fuel_used(self, delta: int): if(self.engines_on): @@ -30,6 +37,9 @@ class Stage(): else: return 0 + def convert_y_component_to_total_with_gimbal(self, y_value): + return math.fabs(y_value / math.cos(math.radians(self.gimbal))) + #total drag coefficient is just the upper stage #engines on is just the lower stage #thrust is just the lower stage |