# [WIN/MAC/LINUX] KSP Trajectory Optimization Tool v1.6.9 [New MATLAB Version!]

## Recommended Posts

15 hours ago, dlrk said:

How would I arrive that estimate though? Perhaps take the time between burns 1 and 2 from the RMS?

Characteristic length meaning number digits before zero?

1. Yep, that would work.
2. Meaning the typical length scale of the problem.  So like the Mun's orbit around the 12000 km, so that could be your scale factor if you're looking at constraints in position in between Kerbin and the Mun.
3. Okay, that's really way too long.  Can you send me your MAT file so I can take a look and find out why?
11 hours ago, dlrk said:

Is there perhaps a step by step tutorial for planning a mission in the LVD? I'm trying to plan Kerbin-Mun transfer by putting the initial parking orbit as initial state, calculating the maneuver in RMS, and creating an event in LVD to propagate to the burn True Anomaly, then apply a delta v of the calculated maneuver, followed by a terminate next SOI event with no actions, and it winds up like this: https://imgur.com/a/WgnKJRB

There's a tutorial that ships with the main KSPTOT download called "Mission to Eve" or something like that.  It's a bit out of date but should still give you a decent idea about how to set up a mission in general.

##### Share on other sites

11 hours ago, Arrowstar said:
1. Yep, that would work.
2. Meaning the typical length scale of the problem.  So like the Mun's orbit around the 12000 km, so that could be your scale factor if you're looking at constraints in position in between Kerbin and the Mun.
3. Okay, that's really way too long.  Can you send me your MAT file so I can take a look and find out why?

There's a tutorial that ships with the main KSPTOT download called "Mission to Eve" or something like that.  It's a bit out of date but should still give you a decent idea about how to set up a mission in general.

Found the tutorial, thanks!

Would I enter that scale factor as "12000.0"?

Here's my MAT, if that helps

Edited by dlrk
##### Share on other sites

8 hours ago, dlrk said:

Would I enter that scale factor as "12000.0"?

Yep!  No quotes, of course.

Quote

Okay, a few things.

1. Don't use the Set Kinematic State action on the first event.  Instead, just set the Initial State (Scenario -> Edit Initial State).  You can actually just delete your first event once you do this.
2. Don't use the Next SoI termination condition on the 4th event.  Use an event duration termination condition and just let the optimizer figure out how long to coast for.  Right now you're not actually getting to the next SoI because your orbit apogee is too low, and that's why it's just coasting forever (it's looking and looking for an SoI change and not finding one, so it just propagates until it hits the maximum script propagation time of 5 seconds and quits).  I promise if you just stick with the "event duration" condition and use constraints everything will work out much more smoothly.

Here's your MAT file back with some tweaks.

##### Share on other sites

I wanted to share tonight a couple of updates coming to Launch Vehicle Designer in the next KSPTOT pre-release.

1. Now that we're definitively going to MATLAB R2022a, I've added the ODE78 and ODE89 integrators.   As it turns out, ODE78 seems to be faster than ODE113 for those interplanetary arcs, especially for those gravity assist tours we all like to do.  I get a nice little speed up when I use it in this case.
2. There's now auto-constraint scaling in the code.  Under the Optimization menu you'll find the ability to scale your constraints by either their current value or by the constraint Jacobian matrix, all rounded up to the nearest power of 10.  This is super nice because it was always a pain to manually set the constraint scale factors before.
3. I've added "feasibility mode" to the Fmincon optimizer's options menu.  You can read up more on it at the link I've provided.

I imagine I'll push out a new pre-release in the next week or so.  As usual, I welcome reports of any bugs with either the current production version of KSPTOT or the pre-releases!

Happy orbiting.

##### Share on other sites

16 minutes ago, Arrowstar said:

now auto-constraint scaling

But... I just started learning...

Spoiler

but for real though, woo hoo! It is definitely a pain, even when you do know what you're doing...

##### Share on other sites

3 minutes ago, Razgriz1 said:

But... I just started learning...

Hide contents

but for real though, woo hoo! It is definitely a pain, even when you do know what you're doing...

The goal is always to make things easier for users lol. For what it's worth the auto scaling is only an estimate and there's plenty of room to tinker, haha.

##### Share on other sites

23 minutes ago, Arrowstar said:

The goal is always to make things easier for users lol.

Honestly, I'm amazed that you're still working on and improving this thing. Thank you so much for your effort!

##### Share on other sites

6 minutes ago, Razgriz1 said:

Honestly, I'm amazed that you're still working on and improving this thing. Thank you so much for your effort!

You're welcome!

##### Share on other sites

Hi everyone,

Today I've built KSPTOT v1.6.9 pre-release 8.  Here's a list of the changes from the previous pre-release, which are fairly extensive.  As previously mentioned, this PR is going to be on MATLAB R2022a, so you will need that version of the MATLAB compiler runtime to use it.

The big thing you'll notice right away is that I've added icons to many buttons in the LVD user interface and dialog boxes.  The goal here was to both help users understand the functionality of each button at a glance as well as make the program more visually appealing.  Hopefully I've accomplished these things, but feedback is always welcome!

• LVD: Performance improvement for generic polynomial steering model.
• LVD: Fixed issue with mission optimization observation UI always popping up back on top when drawing plots.
• LVD: Migrated the optimization observer and optimization scorecard UIs to App Designer.
• LVD: Added icons to many of the buttons in many of the user interfaces.
• LVD: Added ability to show markers on trajectory lines for events.
• LVD: Added new geometric vector x,y,z constraints
• LVD: Added ability to normalize vectors to the geometric Scaled Vector.
• LVD: Added new geometric vectors: point velocity vector, vector difference vector.
• LVD: Added feasibility mode option for FMINCON solver.
• LVD: Added auto scaling for constraints.  See Optimization menu -> Scale Constraints
• LVD: Bug with position marker not showing when there's only one state in the internal state log (such as when LVD starts or a new mission is created).
• LVD: Added ODE78 and ODE89 integrators for use.
• ...plus a bunch of other bug fixes and a few performance improvements.

Please let me know if you have any questions or find any bugs.  Happy orbiting!

##### Share on other sites

Hi everyone!

Tonight I want to share with you some new functionality that is coming to KSPTOT's Launch Vehicle Designer soon.  One of the big weaknesses that I've been aware of with LVD has always been to aerodynamic forces.  Drag forces, in particular, have never really been modeled well.  Thankfully, some of that is now changing.

There are now four different drag models you can select from in LVD when you edit your drag properties (either in the initial state or by using the appropriate event action).

The "One Dimensional" drag model is what you will have seen in LVD now.  This is the drag  coefficient as a function of some independent variable.  The "Constant" model is just that, Cd*A is a specified constant value.

Where things get interesting is with the new "Kerbal Wind Tunnel" (KWT) models.  These use data from the  Kerbal Wind Tunnel mod in order to model drag coefficient (Cd*A) as a function of speed and altitude.  The two dimensional version (just speed/altitude) assumes that Cd*A does not change as a function of vehicle attitude (angle of attack in this case).  While not strictly true, it's also the easier KWT drag model to generate.  You basically just point it to the "Flight Envelope" data file that gets generated by KWT and it does the rest.

Notice that the Cd*A grid gets plotted with a nice heat map so that you can visualize the data you've imported.

As I said, this functionality doesn't consider vehicle attitude, angle of attack though.  For that, I have a 3D drag model that involves taking a number of these 2D models, evaluated at fixed AoAs, and then doing 3D interpolation across all of it.  This is a tad more complicated, but the same basic idea of "load KWT output file" still holds, you just do that more than once.

Here you can see all of the AoA "slices" of data, each being represented by a KWT output file at a given angle of attack.  Note that each slice has to have the same grid of speed and altitude for this to work, which is why I display the properties of the data and some warnings/alerts if the code detects issues.  Interpolation is handled automatically under the hood, you don't have to worry about that.

There is one big caveat with using all of this KWT stuff right now: it doesn't work this way "out of the box."  Right now, if you go download KWT, it will spit out the drag "flight envelope" data at a bunch of different AoAs corresponding to some level flight AoA that would be more useful for airplanes.  In order to get all this to work, I had to hack the source code a bit to fix the AoA used to a given value.  I also had to up the maximum altitude to 70 km for Kerbin, because otherwise your altitude grid tops out at 25 km I think.

These are sort of a big deal, and I'm happy to help anyone interested in editing the KWT source code so that it will generate the data products necessary to use all this.  I have also been talking with the author of KWT about producing the speed/altitude grids at a specified AoA and with user-defined grid min/max/step size so that hacking around with his code isn't necessary anymore, but I have no idea when and if he'll get around to implementing any of the suggestions I asked for.

Anyway, I'm open to A) questions about what I've got here, and B) suggestions for other mods I could tap that produce drag coefficient (Cd*A) data.

Happy orbiting!

##### Share on other sites

Ooh I was just about to start setting up a very primitive version of this with a plugin. Beat me to it

On 4/25/2022 at 5:21 PM, Arrowstar said:

B) suggestions for other mods I could tap that produce drag coefficient (Cd*A) data.

It would be great to be able to get this sort of information for FAR as well, though I am currently unaware of any way to export data like this from FAR. Booots has previously stated that FAR integration into Kerbal Wind Tunnel is on the roadmap, but last I saw is that there were some roadblocks that have made FAR integration more difficult than initially assumed.

I do know that you can output live flight data using FAR, though that obviously doesn't allow for 3-dimensional interpolation so it's use would be somewhat limited.

The FAR analysis tool in the VAB is able to produce the same kinds of sweeps that you'd need, but I am unaware of any way to export the data, other than manually setting up sweeps and recording some data points from them to then build a very coarse map by hand.

##### Share on other sites

Would anyone be interested in user-defined themes for KSPTOT?

Edited by Arrowstar
##### Share on other sites

That's cool! Dark model

##### Share on other sites

Personally I have no interest in creating a user defined theme, but I would try a dark theme, if it was included in the download.

##### Share on other sites

Quick update on the efforts to get drag modeled more precisely:

I've found that Ren0k's Project Atmospheric Drag is probably going to be the best we get as far as getting decent estimates for drag coefficient as a function of Mach number and vehicle attitude.  I've written a kOS script that will loop over various angles of attack and sideslip angles and calls Ren0k's code to generate drag coefficient as a function of Mach number.  These all get spit out into a giant CSV file which you can then read into LVD using Yet Another Drag Model (TM).  See image below.

I'm now debating about keeping the Kerbal Wind Tunnel drag models in LVD since they required hacking the source code to use and didn't really account for attitude all that well.  It may be more intuitive to users if I don't include them at all.

When I use my kOS control script to run a launch vehicle trajectory modeled in LVD, what I find is that the LVD predicted performance is still less than what shows up in KSP proper.  I believe that's due to the fact that I'm not modeling the lift force, but the end result even without lift is pretty close.  I was aiming for a circular 750 km orbit in this particular trial and I ended up with a roughly circular 770 km orbit instead.  So not terrible.

Unfortunately, I have no idea how to model lift in KSP and unlike drag, no one seems to have done much work in figuring out that system that I could find.  So this might be as good as it gets for now.  Of course, if anyone does have information on how lift is modeled in KSP, or at least how it could be approximated, please let me know!

Edited by Arrowstar
##### Share on other sites

Hi everyone,

Today I've built KSPTOT v1.6.9 pre-release 9.  Here's the change log:

• LVD: Lots of Graphical Analysis UI improvements, including proper selection of figure background colors based on axis color, resizable UI, arrow buttons for changing the order of tasks, and settings being remembered from session to session.
• Old list dialog box now replaced with custom App Designer implementation throughout all of KSPTOT.
• LVD: New drag models added, including new higher fidelity kOS-based drag model.
• LVD: Added createDragData.ks kOS script for use with the new kOS drag model in LVD.
• LVD: New example showing how the kOS drag model ("complex drag model") is used.
• LVD: Edit Event ui now shows the event number being edited in the title of the window.
• LVD: Updated kOS control script to have a T- timing if the script is called before the control sequence starts.
• LVD: Added thrust to weight constraint.
• LVD: Added the ability to compute constraint Jacobian to fmincon optimizer. This can improve optimization performance at the expense of additional calculation time.

I've included both the new LVD example with the new complex kOS data-based drag model and the updated kOS scripts for LVD control and producing the drag coefficient data needed for the kOS based drag model.  Please check them out if this is something you're interested in.

As always, please let me know if you find any bugs!  I think we're getting close to the v1.6.9 release and I'd like to make sure there's nothing horrible in the code before that happens.

Happy orbiting!

##### Share on other sites

• 2 weeks later...

I've got a fun new feature to introduce today.  One of the tricky bits with space mission design is integrating multiple spacecraft into one mission plan.  Getting all of those different vehicles modeled at the same time can often be clumsy and adds additional propagation CPU time.  Enter a solution: the "LVD Trajectory Point".

This is a type of geometric point, part of the geometry system.  All you have to do is create the Point and load the LVD file that contains the trajectory you're looking to integrate.

LVD will load the LVD case MAT file you select, parse the trajectory, and create the Point.  Once you've done that, you can interact with it as you would any other Point.  This means that you can plot it, as I've done here.

The red line in the display is the circular Kerbin orbit that I'm actually modeling.  The cyan dashed-dotted line is the imported LVD trajectory as a Point.  I've got it plotted here so you can see.

The big advantage to this system is that the Point's trajectory does not need to be propagated constantly: it's loaded into memory and interpolation is used to get the state of the point at any moment in time.

There are a few caveats.  First, the loaded trajectory has to reference celestial bodies that are in the current session of LVD.  If your LVD MAT file uses Earth and Mars but your current session of LVD is in the Kerbol system, this will not work and that's intentional.  Second, if you ask the Point for its position and velocity at a time outside its trajectory, it will provide its position and velocity at the nearest point in time on its trajectory.  Third, the loaded trajectory is static and can't be optimized.  This means this functionality is more suited for stations or other "static" vehicles whose trajectory is complex but otherwise can be known ahead of time.

What do you all think?  Could this be useful for you in your mission design activities?

Happy orbiting!

##### Share on other sites

Hi everyone,

Today I've built KSPTOT v1.6.9 pre-release 10.  This is the v1.6.9 release candidate build.  Here's the change log from PR9:

• LVD: Added projection type to view settings. Default is perspective now.
• Added available textures for Earth, Moon, Mercury, Venus, Mars, and Pluto.  (For RSS.)
• LVD: Added a "LVD trajectory" point type that reads in an LVD case MAT file and propagates that trajectory in the current LVD case.
• LVD: In Adjust Variable UI, angle variables now show units of degrees and not radians.
• LVD: Migrated the steering and throttle model selections away from the listbox dialog.
• LVD: Added a new coordinate system which is parallel to a reference frame at a given universal time.
• A ton of bug fixes and a few performance enhancements, especially with LVD reference frames.

As always, please let me know if you find any bugs!  Happy orbiting!

##### Share on other sites

Hi! This looks really cool, so I downloaded it to see if I can use it to plan some gravity assist maneuvers in my scaled-up solar system. However, it seems like the only options for time units are Earth time and stock Kerbin time? In a 2.5x scaled up system with OPM and Kronometer, Kerbin has ~10 hour days and ~400 day years, so trying to use something like the Multi-Flyby Tool gives me very different dates for a given UT than what is shown in game.

So that brings me to my question - is there a way to get KSPTOT to work with non-stock / scaled up systems?

##### Share on other sites

21 minutes ago, Zelda said:

Hi! This looks really cool, so I downloaded it to see if I can use it to plan some gravity assist maneuvers in my scaled-up solar system. However, it seems like the only options for time units are Earth time and stock Kerbin time? In a 2.5x scaled up system with OPM and Kronometer, Kerbin has ~10 hour days and ~400 day years, so trying to use something like the Multi-Flyby Tool gives me very different dates for a given UT than what is shown in game.

So that brings me to my question - is there a way to get KSPTOT to work with non-stock / scaled up systems?

Hey!  So don't worry top much about the time system stuff.  It's just a way to convert seconds of universal time to a more typical year/day/hour/minute/second representation. Under the hood, though, everything is done in seconds of universal time, both in KSP and KSPTOT.

That's my way of saying just use the universal time numbers and ignore the year/day/hour/minute/second stuff.  KSPTOT will still work great!

Btw, if you are using a different solar system than the stock one (and scaled solar aystems are different) , you'll need to use the KSPTOTConnect plugin for KSP and generate a bodies.ini file for your solar system.  I can show you how to do that if you need help.

##### Share on other sites

6 hours ago, Arrowstar said:

Hey!  So don't worry top much about the time system stuff.  It's just a way to convert seconds of universal time to a more typical year/day/hour/minute/second representation. Under the hood, though, everything is done in seconds of universal time, both in KSP and KSPTOT.

That's my way of saying just use the universal time numbers and ignore the year/day/hour/minute/second stuff.  KSPTOT will still work great!

Btw, if you are using a different solar system than the stock one (and scaled solar aystems are different) , you'll need to use the KSPTOTConnect plugin for KSP and generate a bodies.ini file for your solar system.  I can show you how to do that if you need help.

Oh, great! I will play with it more this weekend then!

I did figure out the KSPTOTConnect plugin / generating the bodies.ini file, which seemed to work great, thanks!

##### Share on other sites

4 minutes ago, Zelda said:

Oh, great! I will play with it more this weekend then!

I did figure out the KSPTOTConnect plugin / generating the bodies.ini file, which seemed to work great, thanks!

Awesome!  Please let me know if you have any more questions about KSPTOT.  Happy orbiting!

##### Share on other sites

• 2 weeks later...

Hi everyone!

This morning I'm happy to announce the release of KSP Trajectory Optimization Tool v1.6.9!  This is a major release that primarily focuses on adding additional functionality to Launch Vehicle Designer (LVD).  Here are some of the major highlights of this new release:

• Migration of the underlying MATLAB Compiler Runtime to version R2022a.
• LVD now includes an improved drag model that can be populated from data generated by an included kOS script.
• LVD now includes an ability to have user defined variables which can be used with LVD plugin code.  These plugin variables can then be used to with the new Case Matrix Runner to run a variety of cases of the same MAT file.

Here's the full change log:

• Converted all remaining maneuver planning tools to App Designer.
• Converted all remaining Launch Vehicle Designer UIs to Ap Designer.
• Converted a few misc UIs to App Designer.
• MFMS: Inclusion of a new button on the UI that allows for binary data from the last run to be exported to file.
• LVD: New menu item to create a new mission scenario from MFMS binary data.
• MA/LVD: Initial state and final state shown in the UI are now the earliest and last (chronological) state in the state log, as opposed to the first and last state log entries.  This is important in LVD because of the ability to use Set Kinematic State actions to move around in time, and because propagation can be both forwards and backwards.
• LVD: The Edit Constraint UI now shows the current scaled value of the selected constraint.
• LVD: Added functionality to the script event list right click context to convert Add Impulsive Delta-V actions to finite burns.
• LVD: Final and initial spacecraft state displays now show earliest and latest state and not first and last state in state log.
• LVD: Added new UI to fine-tune creating continuity constraints.
• LVD: Added gravity only RKN1210 high precision integrator.
• LVD: There should be a 5%-10% performance increase when running scripts for most scenarios, especially those that make use of 3rd body gravity.
• All single UI apps (MFMS, RMS, etc) now display their central body spheres with the texture and not the colormap, if available.
• LVD: Added the options dialog for the Second Order propagator.
• LVD: Tooltip for the warning/error labels is custom and now shows the proper width so everything that is meant to be on one line is actually on one line.
• Fixed bug in main UI options dialog.
• LVD: The tool tip string on the time slider text now shows the proper events.
• MFMS: New constaint that allows you to set a max delta-v  limit on flyby maneuvers.
• LVD: Added "plugin variables" which allow users to create their own plugin-accessible quantities which can be optimized.
• Refreshed the icons of many UIs.
• LVD: Performance improvements for 3rd body gravity.
• LVD: Updated the version of the IPOPT optimizer.
• LVD: Initial implementation of the Case Matrix Runner tool.
• LVD: Performance improvement for generic polynomial steering model.
• LVD: Fixed issue with mission optimization observation UI always popping up back on top when drawing plots.
• LVD: Migrated the optimization observer and optimization scorecard UIs to App Designer.
• LVD: Added icons to many of the buttons in many of the user interfaces.
• LVD: Added ability to show markers on trajectory lines for events.
• LVD: Added new geometric vector x,y,z constraints
• LVD: Added ability to normalize vectors to the geometric Scaled Vector.
• LVD: Added new geometric vectors: point velocity vector, vector difference vector.
• LVD: Added feasibility mode option for FMINCON solver.
• LVD: Added auto scaling for constraints.  See Optimization menu -> Scale Constraints
• LVD: Bug with position marker not showing when there's only one state in the internal state log (such as when LVD starts or a new mission is created).
• LVD: Added ODE78 and ODE89 integrators for use.
• LVD: Lots of Graphical Analysis UI improvements, including proper selection of figure background colors based on axis color, resizable UI, arrow buttons for changing the order of tasks, and settings being remembered from session to session.
• Old list dialog box now replaced with custom App Designer implementation throughout all of KSPTOT.
• LVD: New drag models added, including new higher fidelity kOS-based drag model.
• LVD: Added createDragData.ks kOS script for use with the new kOS drag model in LVD.
• LVD: New example showing how the kOS drag model ("complex drag model") is used.
• LVD: Edit Event UI now shows the event number being edited in the title of the window.
• LVD: Updated kOS control script to have a T- timing if the script is called before the control sequence starts.
• LVD: Added thrust to weight constraint.
• LVD: Added the ability to compute constraint Jacobian to fmincon optimizer. This can improve optimization performance at the expense of additional calculation time.
• LVD: Added projection type to view settings. Default is perspective now.
• Added available textures for Earth, Moon, Mercury, Venus, Mars, and Pluto.  (For RSS.)
• LVD: Added a "LVD trajectory" point type that reads in an LVD case MAT file and propagates that trajectory in the current LVD case.
• LVD: In Adjust Variable UI, angle variables now show units of degrees and not radians.
• LVD: Migrated the steering and throttle model selections away from the listbox dialog.
• LVD: Added a new coordinate system which is parallel to a reference frame at a given universal time.
• Many other performance improvements and bug fixes!

NOTE: If you are upgrading from KSPTOT v1.6.8 or earlier, you MUST download the R2022a MATLAB Compiler Runtime (MCR)!  KSPTOT v1.6.9 will not run without this!  You can find the R2022a MCR download for your platform here: https://www.mathworks.com/products/compiler/matlab-runtime.html

Finally, if you enjoy using KSPTOT and its many applications (the Porkchop Plotter, Multi-Flyby Maneuver Sequencer, Mission Architect, Launch Vehicle Designer, and all the rest), please consider buying me a coffee via my Ko-Fi account to support KSPTOT's development. As I note in the first post of this thread, KSPTOT is a labor of love that I have put many, many hundreds of hours into for the benefit of the KSP community. The best part of it for me, aside from knowing that KSPTOT is the premier mission design tool for KSP, is all the thank you notes I've received over the years. I offer this as another way to say "Thank you!", if you so desire.

As usual, the release can be downloaded from the first post of this thread. Please let me know if you have any questions or find any bugs. Thanks, and happy orbiting!

##### Share on other sites

Hi, I seem to be running into an issue starting the Launch Vehicle Designer for some reason. Shortly after clicking on it, the window pops up, then closes, and the program presents an error window "An error occured while opening Launch Vehicle Designer. Please see the ksptot.log for more details." Looking at the log it gives this

"Invalid default value for property 'genericSelectableModels' in class 'SteeringModelsSet':
Invalid default value for property 'gammaAngleFitNet' in class 'GenericSelectableSteeringModel':
Unrecognized function or variable 'simplefit_dataset'."

I've tried running the program as administrator, and reinstalling it. Everything else seems to work fine, so I'm not entirely sure what the issue is.

##### Share on other sites

1 hour ago, trinimac said:

Hi, I seem to be running into an issue starting the Launch Vehicle Designer for some reason. Shortly after clicking on it, the window pops up, then closes, and the program presents an error window "An error occured while opening Launch Vehicle Designer. Please see the ksptot.log for more details." Looking at the log it gives this

"Invalid default value for property 'genericSelectableModels' in class 'SteeringModelsSet':
Invalid default value for property 'gammaAngleFitNet' in class 'GenericSelectableSteeringModel':
Unrecognized function or variable 'simplefit_dataset'."

I've tried running the program as administrator, and reinstalling it. Everything else seems to work fine, so I'm not entirely sure what the issue is.

Interesting.  So it's when starting LVD in general or when opening a MAT file?

Are you on the latest v1.6.9 that was released yesterday?

## 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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.