I just finished the first version of "Kerbal Guidance System", a kOS script capable of launching a rocket to a precise orbit while maximizing payload. The algorithm is based on optimal control theory using a Newton-Raphson algorithm to solve a set of guidance equations and determine the optimal trajectory. I am aware that other scripts exist, including PEGAS from which I gained a lot of inspiration, my original goal was to get a better understanding of the math behind guidance algorithms. I set out to learn more about PEG, but ultimately decided to use a different type algorithm. Both are based on similar fundamentals, but hopefully this adds something new and can maybe help others learn a little bit more as well. This technique is relatively computationally expensive when compared to the slow processor speeds of kOS. In the future I may translate the code to python to use with krpc.
KGS can launch a rocket to a specified orbit while minimizing fuel consumption. KGS offers the specification of three types of orbits:
Unconstrainted orbital plane
Constrained inclination
Constrained inclination and longitude of the ascending node
Some of the capabilities of KGS include:
calculation of launch time
calculate of launch azimuth
predefined atmospheric ascent phase
coast phases
precise orbit targeting
I put together a few examples, two for the stock KSP system and one for RSS. The scripts, a guide, and theoretical background documents can all be found on my GitHub page https://github.com/TomTheLion/Kerbal-Guidance-System. It can be somewhat challenging to set up and successfully fly a rocket using this script, but hopefully the guide provides enough detail. I would be more than happy to offer help or clarify anything if anyone decides to try this script.
For the stock rockets the only required mod is kOS, for the RSS rocket I used a custom module manager patch to rebalance the engines for a larger solar system (included on my Github page) and the following mods installed from CKAN:
Real Solar System
Kerbal Joint Reinforcement Continued
Restock
Restock+
Waterfall Core
Simple Adjustable Fairings - KW Rocketry Pack
Simple Adjustable Fairings - Plugin