Illation / PEGAS

Powered Explicit Guidance Ascent System

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PS: git is hard.

PEGAS

Powered Explicit Guidance Ascent System is an autopilot for Kerbal Space Program made and ran in kOS, designed to control launch vehicles under a modified version of the game running Realism Overhaul. At its current state it features two main sections:

  • passive pitch control for atmospheric flight (first stage guidance),
  • active pitch control using Powered Explicit Guidance algorithm for parking orbit targeting (second stage guidance).

They are connected by a common launch sequence, so PEGAS controls the complete launch vehicle ascent from countdown to orbital insertion.

Code structure

PEGAS is comprised of 5 main elements:

  • bootfile, designed as individual for each launch vehicle, containing LV-specific stuff,
  • loader that initializes the system (pegas_loader),
  • libraries that contain often-used functions (pegas_nav, pegas_lib),
  • settings which contain some technical variables like timeouts (pegas_set),
  • and the main launch sequence control program, pegas, that carries out the whole procedure.

It also comes with a dedicated MATLAB suite designed to perform flight simulations, particularly ascent path design and verification of PEG. Originally built as a prototype for algorithm design and debugging, now covers quite nicely with actual KSP flight results and can be used to predict trajectories. Last section of this document explains some details of the m-code.

Current capabilities

For now PEGAS can only launch two-stage rockets into a circular parking orbit of a given altitude, although with no inclination control. It can be set to jettison boosters or fairings, and can perform a ullage burn using either RCS or SRBs. It is capable of igniting engines before launch, allowing liquid fuel engines to reach and stabilize thrust before liftoff.

Check how it performs in my youtube video below:

First stage guidance

First stage control is very simple: the autopilot simply follows a precalculated pitch program, at each step interpolating from a pitch-time table it is given in the bootfile. The downside is that you need to prepare this table before the flight, effectively having to solve the ascent path problem. The actual shape of the path will depend on the LV's parameters such as TWR and drag curve, as well as miscellaneous design constraints (apoapsis at burnout, drag losses, maxQ etc.) and will need to assure aerodynamic safety of the vehicle (too much AoA will kill it).

Please note that this the kOS part of the project does not deal with ascent path design. See MATLAB section on the end of this document for that.

Staging sequence

Almost everything in PEGAS is timed, that is: no dynamic checking for engine shutdown, flow stability etc. are performed and most actions must be scheduled beforehand. Staging sequence is the best example of this. All events PEGAS can handle - separation, ullage engine ignition, main engine ignition, ullage engine cutoff (optional for RCS ullage) - are explicitly stated in vehicle-specific time table. All the autopilot does is execute them, assuming that they are all properly ordered in staging sequence (in other words: presses space when it's told to).

Second stage guidance (PEG)

Some time after seconds stage ignition (another declared value) PEG guidance is activated and the autopilot begins navigating the craft into a specified orbit. For now it can only be a circular orbit with only inclination coming from launch site latitude.

To understand the guidance algorithm, read the original document: Explicit guidance equations for multistage boost trajectories by Fred Teren, Lewis Research Center (today Glenn Research Center). This article on Orbiter Wiki, which is less mathematical and focuses on what you need to know to implement it, will be easier to digest, however it might not be enough and in order to understand everything you'll need to refer to the original anyway.

Coming up

  • Currently PEGAS suffers some minor targeting accuracy problems (+/- 10km on a 200km target orbit). This is unexpected, since a prototype designed in MATLAB showed excellent performance, and kOS version is an exact translation of the code. This could've as well been expected after all: updated MATLAB code with improved simulation accuracy shows some deviation from ideal (typical orbit: 200x194km vs target of 200km). Therefore this issue will not be investigated at this time.

  • Next thing to implement is yaw control and inclined orbit targeting. I am focusing on this feature now, first building a separate prototype in MATLAB. See branch yawcontrol for progress.

  • In the future, I will implement multistage control for PEG flight. This will allow for flying 3 stage vehicles like the Saturn V, or "2.5" stage Atlas-Centaur-style sustainer+second stage combinations.

MATLAB suite

When I first began thinking of implementing Powered Explicit Guidance, I realized that getting the math right will be tricky and writing code/debugging in kOS - extremely tedious. I chose to create a simulation environment in MATLAB and design the algorithm there, with easy variable preview, comfortable language and (most importantly) fast execution times. Having first written a simplified physics engine I took a small detour and created a simple tool for designing atmospheric ascent trajectories. All that now makes a software suite you can use to design your own ascent profiles or test your craft's performance.

MATLAB folder contains the following main files (named in a different fashion to distinguish from functions):

  • PM1_initSim.m - prepares global variables with atmosphere data (straight from RO settings) etc.
  • PM2_createVehicle.m - sample sheet for defining a vehicle (includes parameters of the demo rocket from my video).
  • PM3_findAscentPaths.m - a rather brute-force attempt at ascent profile design: finds gravity turn parameters (initial angle and velocity) that satisfy a condition (apoapsis at burnout) by running simulations for each parameter combination and analyzing solutions. In my experience, there is a linear relation between the two that produce desired burnout state, so this script finds such a relation.
  • PM4_makePitchProgram.m - creates a pitch program (pitch~time table as used by PEGAS) from a selected natural gravity turn path by fitting a piecewise linear function into a flight profile obtained in previous step. This allows easy usage of pitch profile in kOS and minimizes AoA during ascent.
  • PM5_testAscentProfile.m - flies a detailed simulation using the newly created pitch program as guidance. Creates a structure containing some basic flight data and plots various logs.
  • PM6_simulatePEG.m - runs another simulation, this time with Powered Explicit Guidance. Easy continuation of a previous flight is possible, even with coast periods inbetween (or after). Flight data output to screen.
  • PM7_writeKSBoot.m - outputs the pitch program and some basic stage data (time of burn) straight to a .ks file in a format (almost) immediately ready to use as a PEGAS bootfile (user still needs to fill in blanks that MATLAB isn't aware of, such as fairings jettison, ullage mode etc.).

Aside from those scripts, code contains various functions which are sufficiently (I hope) described within their files.

Credits

MATLAB linearFit.m function contains pieces written originally by Andrey Rubshtein and Nikolai Golovchenko. flightPlots.m uses Richard Crozier's tightfit (see MATLAB\tightfit.license for attached BSD license). Thank you for your great work!

About

Powered Explicit Guidance Ascent System

License:MIT License


Languages

Language:MATLAB 100.0%