wmvanvliet

[1.4.4] Kerbulator: use your own math!

Recommended Posts

This is the new thread about Kerbulator. Here is the old thread, where the plugin was called Kalculator. Turned out that name was already taken.

One of the big joys of Kerbal Space Program is that game progress is not based on experience points, or character level, but based on your own knowledge about orbital mechanics. Maybe this is why I don't like using MechJeb much, its free progress in the game.

Inspired by Scott Manley's videos about 'orbital mechanics on paper', I spend an afternoon thoroughly enjoying myself deriving various formulae. Oh, how much fun the creators of MechJeb must have had with it themselves.

So I created a mod that lets you put your own formulae in KSP and named it Kalculator Kerbulator. It is a small plugin that allows you to program mathematical equations, run them to see the output and create maneuver nodes. Of course, your calculations need various inputs (like the mass of the body you're currently orbiting, the value of the gravitational constant, etc.) and for this, Kerbulator aims to strike a balance between providing enough useful variables to be productive, and not supply too much information and rob you of the joy of calculating things for yourself. The current guideline is that Kerbulator gives you access to all the various numbers that appear in the vanilla KSP GUI.

So, what are you waiting for?

  1. Download the plugin or get the source code
  2. Read the manual
  3. And start learning interesting math

 

screenshot2.png

Author: Marijn van Vliet

License: GPL v3

Feature highlights:

  • Create manoeuvre nodes and alarms (if KAC is installed) based on your calculations
  • Open windows that continuously evaluate your functions and present the result
  • Unicode aware, so you can use math symbols for operators and greek letters for variables
  • Contains a numeric solver to approximate answers that cannot be calculated analytically
  • Edit functions in any editor you want. Returning to the KSP window will reload all functions.

Current verion: 0.43

Changelog
---------
0.44
Add support for KSP version 1.4.4

  GUI features
    Kerbulator now makes use of the clickthrough prevention logic


0.43
Recompile for KSP 1.3

0.42
Recompile for KSP 1.2

0.41
Bugfixes.

 Globals
   Added Inf and ∞ globals to denote infinity
   Fixed some globals that were in radians instead of degrees (e.g. θ)

 GUI features
   Fix function name validation in GUI
   Fix column indicator in error messages
   Fix missing expression error message
   Fix behavior when running a repeating function that contains an error
   Fix a bug where the output of the previously run function was shown
   Fix delta-V in normal direction when placing maneuver node

0.4
Some welcome additions to the language.

 Language features
   Add boolean operators: < > <= ≤ >= ≥ == != ≠ ¬ ! ∧ and ∨ or
   Add support for piecewise functions (a.k.a. if-statements)
   Add support for specifying pre- and postfixes for output variables

 GUI features
   Add support for showing pre- and postfixes for output variables
   An error message is shown when the user tries to save a function with an invalid name

0.36
  Add support for KSP version 1.1.3
  
  GUI features
    Remember window positions

0.35
  Add support for KSP 1.1.2
  
  Language features
    Added global `Sun`

0.34.5
  Recompiled against KSP 1.0.5

0.34
  More globals. Thanks to Emanuele Bardelli.

  Language features
    Fixed `{Body}.AtmosHeight` global
    Fixed `{Body}.AtmosPress` global
    Added `Craft.Rel.AN` global
    Added `Craft.Rel.DN` global
    Added `Craft.Rel.Inc` global

0.33
  Small maintenance update. Thanks to Emanuele Bardelli.

  GUI features
    Fixed support for blizzy78 toolbar

  Language features
    Added build-in function `atan2`
    Added build-in function `atan2_rad`

  !! Breaking backwards compatability
    Kerbulator used to store its files (.math) outside the main Kerbulator folder,
    which is a violation of the guidelines laid out by Squad. Function files now go
    in the `PluginData/Kerbulator` folder.

0.32
  Kerbal Alarm Clock integration

    GUI features
      Maneuver node button hides when not in flight
      Added button to add alarm

    Language features
      Added ability to add alarm when KAC is installed

0.31
  KSP 1.0 Compatibility

  GUI features
      Added support for the stock application toolbar
      Kerbulator now available in all scenes, not just in flight

  Globals
    *.AtmosHeight and *.AtmosPress currently disabled as KSP 1.0 changed things

0.3
  JIT Compiling baby!

  GUI features
    Added GUI for calling functions that require inputs
    Added ability to run functions continuously and pin the output to the HUD
    Windows can be resized

  Language features
    Functions are now JIT-compiled and run at native .NET speed.
    Added Nelder-Mead solver for numeric approximation
    Added build-in function `mag`
    Added build-in function `cosh`
    Added build-in function `sinh`
    Added build-in function `tanh`
    Geometric build-in functions now work in degrees by default
    *_rad function added that work in radians
    Build-in function `dot` can now also perform matrix multiplication

  Globals
    Craft.Inter1.TrueAnomaly is now in degrees instead of radians
    Craft.Inter1.θ is now in degrees instead of radians
    Craft.Inter2.TrueAnomaly is now in degrees instead of radians
    Craft.Inter2.θ is now in degrees instead of radians

  !! Breaking backwards compatability
    Geometric build-in functions now work in degrees instead of radians.
    Use the *_rad functions to get the versions that work in radians.

0.23
  Bugfix. Thanks to Bas Cornelissen to patiently work it out with me.

  Language features:
    Properly deal with `\t` and `\r`

0.22
  Better errors and more globals.

  Globals ([URL="https://github.com/wmvanvliet/Kerbulator/blob/master/doc/globals.mkd"]description of all globals[/URL]):
    Added {body}.Inc
    Added {body}.LAN
    Added {body}.Ω
    Added {body}.SOI.ÃŽâ€t
    Added Navball.Heading
    Added Navball.Pitch
    Added Navball.Roll
    Added Navball.OrbitalVelocity
    Added Navball.SurfaceVelocity
    Added Navball.VerticalVelocity
    Renamed Craft.Inter1.sep to Craft.Inter1.Sep
    Renamed Craft.Inter2.sep to Craft.Inter2.Sep

  GUI features:
    Better error messages. Hunt down the bugs in your code with more ease.

0.21
  Bugfixes. Thanks to Teseracto for finding them.

  GUI features:
    Fixed losing changes on window switch
    Closing main window no longer breaks toolbar button

  Language features:
    Operator precedence fixed. (Added some unit tests for these cases)

0.2
  Renamed the entire project Kerbulator, since [URL="forum.kerbalspaceprogram.com/threads/66881-0-23-In-game-scientific-calculator-Kalculator-v0-1-1-1-24-14"]Kalculator[/URL] is already an excellent mod by agises.

  Globals:
    Fixed µ globals

  GUI features:
    Added support for blizzy78 toolbar
    Icons for some buttons

0.11
  Fixed bug where sometimes the run button did not work.

0.1
  Initial version.

  Language features:
  Functions
  Expressions
  Lists
  List unpacking

  Globals:
  All celestial bodies
  Current orbit
  Orbit of target
  Target intercept information

  GUI features:
  Function list
  Description of input and outputs
  Very basic support for error reporting
  Editor with keyboard
  Re-scan function on window focus
  Add maneuver nodes

 

Edited by wmvanvliet
Fix download link

Share this post


Link to post
Share on other sites

Great! Not only fun, also very useful for some custom calcs that the other information mods don't provide.

Some issues and suggestions:

- If the window is closed using the upper right button it can't be reopened from the toolbar. Exiting to the space center and reentering the flight solves the problem.

- Evaluation of expresions is bugged, eg: the expresions 2/2*4 and 2*4/2 should evaluate to the same result, 4. However 2/2*4 evaluates to 2/(2*4) = 2/8 = 0.125

- Any unsaved changes to a function are erased if the game is minimized using alt-tab.

- Limiting the information provided to the one on the vanilla GUI is a very good choice, but some info is lacking. Relative inclination of the target's and active vessel's orbits should be added, in addition to some way of locating the nodes (true anomalie and/or time to node). True anomaly of the target at intercepts or at current time should be added too.

- The ability to read the navball seems very fitting, lat/lon of current attitude and of the various vectors displayed (prograde, target, and maneuver node).

- Being able to run a function with inputs directly, manually entering the input values would be great.

- It would be very useful to have some sort of auto-updating widget that constantly calculates a given function.

Share this post


Link to post
Share on other sites
Is this compatible with Linux, cause I can't get it to work. The icon doesn't show up the toolbar.

It should be compatible, but must admit I never tested it under linux. I will give it a go when I have access to a linux machine. In the meanwhile, could you perhaps check your KSP.log file in your KSP dir to see if any error messages have been put there? And maybe check the debug toolbar? (Mod + F12)

Edited by wmvanvliet

Share this post


Link to post
Share on other sites
Hey I think I found a bug. Happens when I try to open the window.

I fixed something that looked like this in version 0.21. Are you running the latest version? If so, on what platform are you?

Share this post


Link to post
Share on other sites
I fixed something that looked like this in version 0.21. Are you running the latest version? If so, on what platform are you?

I am running the latest version on 32 bit windows vista.

Edited by DoubleOSeven1

Share this post


Link to post
Share on other sites
I am running the latest version on 32 bit windows vista.

Sorry, I can't seem to reproduce it. Can you give any more details? Does it happen every time? Was is some sort of fluke once? Does it work, even though you get the errors? Does it go away once you've run a function? Are you in orbit or on the ground? Anyway, thanks for reporting it, I'll keep an eye out for any null-pointer exceptions :)

Share this post


Link to post
Share on other sites

1.) Possibly a mod conflict

2.) Happens everytime

3.) Tested in Orbit everytime

4.) Does not work with the errors

EDIT: Mod conflict, removed all the mods but a few and it works fine, will trace it down.

One of these I think breaks it

Blt4rX2.jpg

Well ain't that weird, I threw all of them back in to start binary fission and it now works while sitting on the pad....

Great mod going to dive right in

Edited by DoubleOSeven1

Share this post


Link to post
Share on other sites
It should be compatible, but must admit I never tested it under linux. I will give it a go when I have access to a linux machine. In the meanwhile, could you perhaps check your KSP.log file in your KSP dir to see if any error messages have been put there? And maybe check the debug toolbar? (Mod + F12)

Needed to download the latest Toolbar mod and now it's showing up.

Share this post


Link to post
Share on other sites

I like to "fly by the seat of my pants," meaning doing everything by hand (without even Kerbal Engineer, much less MechJeb). That way is more intuitive for me to learn orbital mechanics, and experience those fun "whoops I missed it, and now Major Tom is stranded" moments. Your mod helps just enough without taking away those fun screw-up moments. Also, I've noticed the older I get the more fascinating math & physics are (why couldn't they be that fun in school!!!), and this mod adds depth to mechanics that are already in the game. Good job, sir!

Share this post


Link to post
Share on other sites

An update that will hopefully put a smile on your faces: error messages have been greatly improved. It should now be within the realm of possibilities to hunt down that bug in your code :) Also, I've started work on providing globals for the different readings on your navball. Now we're at version 0.22

Share this post


Link to post
Share on other sites

Hey everybody,

Kerbulator has received a major overhaul, namely that functions are now JIT-compiled. JIT compilation means that whenever a function is first ran, it is compiled to native .NET code. The second time you run the function, it runs at native .NET speeds. Editing the function will cause it to re-compile.

Now why go through all this trouble? Why would anyone want to execute their functions thousands of times per second?

Because it enables these two awesome features:

  1. Kerbulator now has a numeric solver. Many things in orbital mechanics can not be calculated directly, but have to be approximated numerically. Determining the true anomaly for a example. Or solving the lambert problem so you can hit anything (like astroids) in space.
  2. You can 'stick' functions to the GUI. Every frame the function is executed and the GUI window is updated with the result. This had been on the requested feature list for some time and I'm happy I can now offer an implementation with satisfactory speed.

Some other improvements include support for matrix multiplication (comes in handy when performing coordinate transformations) and the fact that geometric functions now operate in degrees (*_rad versions have been added for the radian versions) which makes more sense, as the globals are all in degrees.

Go grab your copy now and do even more cool math!

Edited by wmvanvliet

Share this post


Link to post
Share on other sites

Numeric solver! Sticky functions! Transform coordinates! And... degrees (°.°)

Now will have to spend a lot more time doing fancy things with this mod :D.

Share this post


Link to post
Share on other sites

Do you know lua? Or luaJ? It would be awsome if it could work in there. Computercraft implemented luaJ succesfully in minecraft. I guess that it wouldn't be that difficult to do thesame with KSP. Just redirect the imput of your program to a file, execute that file with Lua runtime environment and return everything to ksp. Would be awsome!

Share this post


Link to post
Share on other sites
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.