Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend external addon API (yet again) #3132

Open
AleXmShef opened this issue Oct 1, 2021 · 0 comments
Open

Extend external addon API (yet again) #3132

AleXmShef opened this issue Oct 1, 2021 · 0 comments

Comments

@AleXmShef
Copy link

AleXmShef commented Oct 1, 2021

Introduction

Hi! I plan to develop an addon for KSP for maneuver planning and execution as my term paper in the university (I'm a software engineer student). Overall, it will enable users to plan their maneuvers by simply entering their desired orbital parameters, and then execute them automatically (like MechJeb does). Under the hood I plan on using differential corrector (like in NASA's GMAT tool) for finite burn maneuver targeting, and some analog of Space Shuttle's PEG for execution. While it is pretty straightforward to implement in a vanilla game using stock KSP API, there are some problems with this magnificent addon, Principia.

Proposition

Since under the hood Principia uses it's own maneuver planner and completely overrides game's physics, a lot of stock API functions become useless (i.e. Planetarium.right returns anything but the solar prime vector).
As I understood from #2144 there were already plans to open up maneuver planner for external addons, but they never came to fruition.
So, in order to support external plugins like mine to do their work, I propose some additional API methods, which, as I understand, either already had somewhat been implemented before, or are used internally by Principia's C# connector.

Design

Here I list some API methods which I propose to be implemented on Principia's side, along with their signatures. Now, as I understand, some of them could be resource heavy, but I hope we can discuss what are possible workarounds and solutions to this problem.

Reference frames

Since stock KSP reference system is basically gibberish, I think it would be best for all API methods to work in J2000eq reference frame, or, which is even better, to support a list of different reference systems via some kind of enum as a method parameter maybe?

General

  • //returns SolarPrimeVector of the solar system in KSP's stock reference frame (purely for conversion purposes).
    XYZ SolarPrimeVectorGet()

Vessels

  • //same as XYZ but holds two vectors, instead of one, see further
    public struct StateVector {
      public XYZ position;
      public XYZ velocity;
    }
  • //struct containing maneuver information
    public struct Maneuver {
      public double beginTime;  //TOI
      public double beginMass;  //Mass of the vessel before ignition
      public double duration; //Duration of the burn
      public double totalThrust;  //Total thrust of all the engines participating in the burn, in N
      public double totalIsp;  //Total ISP of all the engines participating in the burn, in s
      public XYZ burnVector;  //Burn vector
    }
  • //replaces VesselGetPosition and returns position and velocity of the given vessel at UT time
    StateVector VesselGetState(string vessel_guid, double time)
  • //same for celestials
    StateVector CelestialGetState(string celestial_guid, double time)
  • //Same as GetState, but take into account all maneuvers in the queue
    //I don't know if this is even possible given how Principia works under the hood, but it sure will be very good to have.
    StateVector VesselPropagateState(string vessel_guid, double time)

Maneuver planner

  • //get number of maneuvers int he queue
    int ManeuverGetNumber()
  • //get maneuver by its number in the queue
    Maneuver ManeuverGet(int number)
  • //append maneuver to the end of the queue
    void ManeuverAppend(Maneuver maneuver)
  • //remove last maneuver from the queue
    void ManeuverRemove()

I'm very much open to a discussion on how to best implement these methods and/or change them according to your preferences and limitations.

Consideration

I understand that, to most people, KSP is, first and foremost, the game, and while developing Principia you have made sure that it stays a game. And this proposition, in pair with my addon, will remove probably one of the biggest and most important mechanics from it. While this is true, I also believe that some people find the beauty of this game in something else entirely. I personally spent countless hours playing KSP with RSS/RO installed, developing kOS plugins and libraries to support my missions, calculate maneuvers and execute them the way I want. It improved my coding skills, teached me about orbital mechanics way deeper than the vanilla game, and I very much enjoyed it. And i believe i'm not alone. So to some people, like me, this proposition will help to make KSP even better, especially for kOS players.

Postscriptum

My apologies for any grammatical mistakes, English is not my primary language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant