Jump to content

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


Recommended Posts

Hey @Arrowstar, long time no see! I'm a returning user after quite some time away from KSP (and KSP-TOT) and was quite happy to see the amount of features/polishing you put into the tool.While trying to [re]learn the tool, I'm modelling a simple mission to Duna starting from a parking orbit. I just imported a mission from the MFMS and tweaked it to for my needs (I want the ship to enter a polar orbit at Duna), but there are some problems which might be bugs or just me not knowing how to use the tool. Here's the LVD mission for reference.

Now the problems:

- When I change the event 1 from Two body propagator to the Force model propagator, the orbit seems to decay to the ground, even though there shouldn't be any thrust/drag to the ship at that orbit

- Propagating it takes less than 5 seconds, but actually optimizing it is *very* slow. It can take multiple minutes between steps. I wasn't expecting that much from a simple mission like this one

 

Related to that slowness, I'm curious: can I use two body propagators on steps that have only an impulsive delta-v (the instantaneous one) as the action (plus a non-zero event duration) to optimize that?

 

Link to comment
Share on other sites

4 hours ago, vitorboschi said:

Now the problems:

- When I change the event 1 from Two body propagator to the Force model propagator, the orbit seems to decay to the ground, even though there shouldn't be any thrust/drag to the ship at that orbit

- Propagating it takes less than 5 seconds, but actually optimizing it is *very* slow. It can take multiple minutes between steps. I wasn't expecting that much from a simple mission like this one

Okay, so the issue is in how this is all set up.  What you're running into is not drag but instead integration error that accumulates because you're going around and around Kerbin many times.  This is sending you into Kerbin. You can get around this by tightening your integration tolerances (say, to 1E-10 for both absolute and relative tolerances).  A better way to go about this, though, is to only propagate less than one revolution and optimize the initial time directly.  Propagating for millions of seconds is always going to be awful for both run time and optimization time.

To your second point, after the initial propagations finish to compute the gradient, the optimizer needs to do a line search kind of thing and this is always done in serial.  This is what's killing your optimization time, because it might have to repropagate the trajectory many times to finish each optimization step.

As always, getting your trajectory propagation time down as low as possible is the best bet to speedy optimization.  Sub 1 second times are preferable if you can swing them.  Also make sure you're optimizing in parallel.    

Quote

Related to that slowness, I'm curious: can I use two body propagators on steps that have only an impulsive delta-v (the instantaneous one) as the action (plus a non-zero event duration) to optimize that?

If by steps you mean events: yes, you can do that.  No reason why not!

Link to comment
Share on other sites

Thanks for the answers!

Quote

 A better way to go about this, though, is to only propagate less than one revolution and optimize the initial time directly.

What's the best way to do this? Simply changing/optimizing the Epoch field of the initial state would change the orbit, no? That's not desirable in my case because the rocket is already in a parking orbit.

Scratch that. I realized I asked the same question a year or two ago.

12 hours ago, Arrowstar said:

As always, getting your trajectory propagation time down as low as possible is the best bet to speedy optimization.  Sub 1 second times are preferable if you can swing them.  Also make sure you're optimizing in parallel.    

If by steps you mean events: yes, you can do that.  No reason why not!

Cool! I kinda expected it should be allowed, but since the MFMS mission importer stay with the force model propagator, I was a bit wary about changing it

Edited by vitorboschi
Link to comment
Share on other sites

On 12/23/2022 at 7:07 AM, vitorboschi said:

@Arrowstar I've found a bug with LVD's node upload feature: it seems to always set the node execution to the end time of the event, even when it was set to execute the actions before propagation.

Okay, thanks for the notice.  I'll take a look!

Link to comment
Share on other sites

Woah, 192 pages of posts... sorry for not reading but is there a Python implementation of this for those without MATLAB? I used to have matlab and then my computer (and backups) crashed. If no python version, anybody up for translation? Seems like an interesting project. 

Link to comment
Share on other sites

3 hours ago, shootnscoot said:

Woah, 192 pages of posts... sorry for not reading but is there a Python implementation of this for those without MATLAB? I used to have matlab and then my computer (and backups) crashed. If no python version, anybody up for translation? Seems like an interesting project. 

You don't need MATLAB to use this thankfully! You can freely acquire the MATLAB Runtime Environment from the install instructions in the OP.  Install that and KSPTOT will just run.

Good thing, too, because it would take years to reimplement KSPTOT in python lol.

Link to comment
Share on other sites

@Arrowstar a few more bugs on the LVD:

- In some cases, while a chart manipulation tool is active (Pan, rotate, zoom...), you cannot properly interact with the events list: double clicking an event will not open the edit window, and right-clicking will open a menu with chart options rather than the usual event popup menu.

- When inserting a "Set kinematic state" action, I cannot set the epoch using the date/time editor. When I choose that option, the editor will appear, but when I click "Ok", the time is not set. Instead, the console will show this error:

Error using matlab.ui.control.EditField/set
Unrecognized property String for class EditField.

Error in lvd_EditActionSetKinematicStateGUI_App/enterUTAsDateTimeContextMenu_Callback (line 1536)

Error in appdesigner.internal.service.AppManagementService/executeCallback (line 138)

Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)

Error using matlab.ui.internal.controller.WebMenuController/fireActionEvent
Error while evaluating Menu Callback.

- Also when inserting the "Set kinematic state" action, in some cases it will not appear at the list after I change the settings and click "Save & Close". I couldn't find the exact steps to reproduce this one yet, but will report once I do.

- I noticed the initial state doesn't always match what I set as the scenario initial state (see image for ref) . Is that expected?

Link to comment
Share on other sites

4 hours ago, vitorboschi said:

- In some cases, while a chart manipulation tool is active (Pan, rotate, zoom...), you cannot properly interact with the events list: double clicking an event will not open the edit window, and right-clicking will open a menu with chart options rather than the usual event popup menu.

This, unfortunately, is an issue with MATLAB and not with KSPTOT.  I've tried to work around it, but in general, when a figure's pan/zoom/rotate/etc tools are active, they block clicks to other UI elements, much to my chagrin.  I can try to file a bug report with The MathWorks, but I suspect this one isn't getting fixed for a while.

Quote

- When inserting a "Set kinematic state" action, I cannot set the epoch using the date/time editor. When I choose that option, the editor will appear, but when I click "Ok", the time is not set. Instead, the console will show this error:

Error using matlab.ui.control.EditField/set
Unrecognized property String for class EditField.

Error in lvd_EditActionSetKinematicStateGUI_App/enterUTAsDateTimeContextMenu_Callback (line 1536)

Error in appdesigner.internal.service.AppManagementService/executeCallback (line 138)

Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)

Error using matlab.ui.internal.controller.WebMenuController/fireActionEvent
Error while evaluating Menu Callback.

Fixed!  Thanks for the report.  It'll be in v1.6.10 PR3, which I'll look into releasing next week.

Quote

- Also when inserting the "Set kinematic state" action, in some cases it will not appear at the list after I change the settings and click "Save & Close". I couldn't find the exact steps to reproduce this one yet, but will report once I do.

If you can figure out how to reproduce it, please let me know.  I've been running after bugs similar to this one for a bit and they've been hard to track down, though I have successfully fixed some cases where it occurs.

Quote

- I noticed the initial state doesn't always match what I set as the scenario initial state (see image for ref) . Is that expected?

Your reference image shows the state being defined in the Body Fixed Frame, but the states shown in the main LVD window are by definition in the inertial frame, which is why you're seeing a difference.  It's my intention to let the user change the displayed frame and element set shown on the LVD window for both initial and final state, I just have to get around to it. :) 

Link to comment
Share on other sites

19 minutes ago, Arrowstar said:

This, unfortunately, is an issue with MATLAB and not with KSPTOT.  I've tried to work around it, but in general, when a figure's pan/zoom/rotate/etc tools are active, they block clicks to other UI elements, much to my chagrin.  I can try to file a bug report with The MathWorks, but I suspect this one isn't getting fixed for a while.

Fixed!  Thanks for the report.  It'll be in v1.6.10 PR3, which I'll look into releasing next week.

If you can figure out how to reproduce it, please let me know.  I've been running after bugs similar to this one for a bit and they've been hard to track down, though I have successfully fixed some cases where it occurs.

Your reference image shows the state being defined in the Body Fixed Frame, but the states shown in the main LVD window are by definition in the inertial frame, which is why you're seeing a difference.  It's my intention to let the user change the displayed frame and element set shown on the LVD window for both initial and final state, I just have to get around to it. :) 

@Arrowstar Thanks!

I've seen this error log being generated when I try to add the "Set Kinematic State" event, which might be related to it not being added to the list afterwards:

Nonfinite endpoints or increment for colon operator in index.

Error in lvd_EditActionSetKinematicStateGUI_App/populateGUI (line 284)

Error in lvd_EditActionSetKinematicStateGUI_App/lvd_EditActionSetKinematicStateGUI_OpeningFcn (line 1357)

Error in lvd_EditActionSetKinematicStateGUI_App>@(app)lvd_EditActionSetKinematicStateGUI_OpeningFcn(app,varargin{:}) (line 4540)

Error in appdesigner.internal.service.AppManagementService/runStartupFcn (line 103)

Error in matlab.apps.AppBase/runStartupFcn (line 69)

Error in lvd_EditActionSetKinematicStateGUI_App (line 4540)

Error in SetKinematicStateAction.openEditActionUI (line 443)

Error in lvd_editEventGUI_App/addActionButton_Callback (line 427)

Error in appdesigner.internal.service.AppManagementService/executeCallback (line 138)

Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)

Error in matlab.ui.internal.controller.uicontrol.UicontrolRedirectStrategy/executeCallback (line 231)

Error in matlab.ui.internal.controller.uicontrol.PushButtonRedirectStrategy/handleCallbackFired (line 13)

Error in matlab.ui.internal.controller.uicontrol.PushButtonRedirectStrategy>@(varargin)obj.handleCallbackFired(varargin{:}) (line 19)

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback
Error while evaluating Button PrivateButtonPushedFcn.

 

Another, unrelated bug:

When I try to optimize this LVD mission, I get:

Error using optimfcnchk/checkfun
Supplied function '@(x)lvdOpt.constraints.evalConstraintsWithGradients(x,true,evtToStartScriptExecAt,true,[])' returned NaN when evaluated;
 FMINCON cannot continue.

Error in fmincon (line 672)

Error in lvd_executeOptimProblem (line 30)

Error in FminconOptimizer/optimize (line 106)

Error in LvdOptimization/optimize (line 62)

Error in ma_LvdMainGUI_App/optimizeMissionMenu_Callback (line 2865)

Error in appdesigner.internal.service.AppManagementService/executeCallback (line 138)

Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)

Caused by:
    Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.

Error using matlab.ui.internal.controller.WebMenuController/fireActionEvent
Error while evaluating Menu Callback.

 

Link to comment
Share on other sites

2 hours ago, akyyy said:

Hi! I trying to create a simple porkchop plot based on this tutorial, but doesn't work.

RO/RP1 with RSS.

Simple Earth-Venus,  if i use Transfer Window Planner, or Metchjeb2, it works, but using TOT I don't encounter Venus.

How close are you getting?

If it's close, you're running into the zero radius SOI assumption introducing some inaccuracies into the burn.  All you need to do is tweak things slightly and it'll come in.

If it's really off, then this is a case where your initial orbit definition (the mean anomaly and epoch) are probably off and it's throwing you out into space.

Can you share some pictures or screenshots?

On 12/27/2022 at 10:39 AM, vitorboschi said:

@Arrowstar Thanks!

I've seen this error log being generated when I try to add the "Set Kinematic State" event, which might be related to it not being added to the list afterwards:

Nonfinite endpoints or increment for colon operator in index.

Error in lvd_EditActionSetKinematicStateGUI_App/populateGUI (line 284)

Error in lvd_EditActionSetKinematicStateGUI_App/lvd_EditActionSetKinematicStateGUI_OpeningFcn (line 1357)

Error in lvd_EditActionSetKinematicStateGUI_App>@(app)lvd_EditActionSetKinematicStateGUI_OpeningFcn(app,varargin{:}) (line 4540)

Error in appdesigner.internal.service.AppManagementService/runStartupFcn (line 103)

Error in matlab.apps.AppBase/runStartupFcn (line 69)

Error in lvd_EditActionSetKinematicStateGUI_App (line 4540)

Error in SetKinematicStateAction.openEditActionUI (line 443)

Error in lvd_editEventGUI_App/addActionButton_Callback (line 427)

Error in appdesigner.internal.service.AppManagementService/executeCallback (line 138)

Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)

Error in matlab.ui.internal.controller.uicontrol.UicontrolRedirectStrategy/executeCallback (line 231)

Error in matlab.ui.internal.controller.uicontrol.PushButtonRedirectStrategy/handleCallbackFired (line 13)

Error in matlab.ui.internal.controller.uicontrol.PushButtonRedirectStrategy>@(varargin)obj.handleCallbackFired(varargin{:}) (line 19)

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback
Error while evaluating Button PrivateButtonPushedFcn.

 

Another, unrelated bug:

When I try to optimize this LVD mission, I get:

Error using optimfcnchk/checkfun
Supplied function '@(x)lvdOpt.constraints.evalConstraintsWithGradients(x,true,evtToStartScriptExecAt,true,[])' returned NaN when evaluated;
 FMINCON cannot continue.

Error in fmincon (line 672)

Error in lvd_executeOptimProblem (line 30)

Error in FminconOptimizer/optimize (line 106)

Error in LvdOptimization/optimize (line 62)

Error in ma_LvdMainGUI_App/optimizeMissionMenu_Callback (line 2865)

Error in appdesigner.internal.service.AppManagementService/executeCallback (line 138)

Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)

Caused by:
    Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.

Error using matlab.ui.internal.controller.WebMenuController/fireActionEvent
Error while evaluating Menu Callback.

 

Thanks for these! I couldn't reproduce the second one, but I'll take a look into the first.  If you come up with more concrete steps to reproduce that issue, please let me know.

Link to comment
Share on other sites

16 hours ago, Bej Kerman said:

KjKF8Lb.png

...fine, I guess?

Trying to do a reasonable amount of runs, like 15, even at the default iteration and population size, just causes the window to remain in its default layout without the information boxes ever showing anything or the map showing up.

A few things:  First, is there anything in the ksptot.log file that shows up when you run the software?  Any errors or warnings?

Second, could you show me a picture of the window with the RSS solar system data loaded into KSPTOT instead of the stock solar system?  I'd like to try to recreate the issue you described earlier.  To be honest, I'm still not entirely sure what's wrong, because the screenshot you provided does show plots and information in the text boxes. 

Link to comment
Share on other sites

On 12/23/2022 at 7:07 AM, vitorboschi said:

@Arrowstar I've found a bug with LVD's node upload feature: it seems to always set the node execution to the end time of the event, even when it was set to execute the actions before propagation.

Pretty sure I've got this one fixed but I'll check next week when I have more time to use KSP. 

Link to comment
Share on other sites

17 hours ago, akyyy said:

Tried the Duna again, basic KSP, clean install.

I think it worked.

Now I tried the other tutorial.
Kerbin to Laythe - Mission Architect Tutorial

I'm already stuck at the starting.Dates do not match.
 

  Hide contents

 

 

WB1ejrG.jpg

 

X2uUpRB.jpg

0ukNhnk.jpg

 

I wouldn't worry about the dates being too different actually.  There are tons of solutions for the Kerbin-Jool transfer you're looking at.  As long as you have a good one, it'll work out fine.

For what it's worth, I'd use Launch Vehicle Designer instead of Mission Architect at this point.  Despite the name, LVD is far more fully featured and is the code I'm actively maintaining at this point.  Let me know if you have any questions. :) 

Link to comment
Share on other sites

In other news, a few other improvements will be coming to v1.6.10 PR3.  First, I've upgraded the NOMAD solver in LVD to v4.3.1.  There should be some nice performance improvements in there.  Second, I implemented the ability to change the reference frame and element set of the two orbit displays on the main LVD UI.  Simply right click the display text to get the option to change things. 

Link to comment
Share on other sites

4 hours ago, akyyy said:

Error message

"Index exceeds the number of array elements. Index must not exceed 1."

 

Thanks for the report.  Can you clarify what you were doing when the error occurred?  I tried to walk through what I think are the steps you took and I couldn't reproduce the issue.  Thanks!

On 12/27/2022 at 10:39 AM, vitorboschi said:

@Arrowstar Thanks!

I've seen this error log being generated when I try to add the "Set Kinematic State" event, which might be related to it not being added to the list afterwards:

Nonfinite endpoints or increment for colon operator in index.

Error in lvd_EditActionSetKinematicStateGUI_App/populateGUI (line 284)

Error in lvd_EditActionSetKinematicStateGUI_App/lvd_EditActionSetKinematicStateGUI_OpeningFcn (line 1357)

Error in lvd_EditActionSetKinematicStateGUI_App>@(app)lvd_EditActionSetKinematicStateGUI_OpeningFcn(app,varargin{:}) (line 4540)

Error in appdesigner.internal.service.AppManagementService/runStartupFcn (line 103)

Error in matlab.apps.AppBase/runStartupFcn (line 69)

Error in lvd_EditActionSetKinematicStateGUI_App (line 4540)

Error in SetKinematicStateAction.openEditActionUI (line 443)

Error in lvd_editEventGUI_App/addActionButton_Callback (line 427)

Error in appdesigner.internal.service.AppManagementService/executeCallback (line 138)

Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)

Error in matlab.ui.internal.controller.uicontrol.UicontrolRedirectStrategy/executeCallback (line 231)

Error in matlab.ui.internal.controller.uicontrol.PushButtonRedirectStrategy/handleCallbackFired (line 13)

Error in matlab.ui.internal.controller.uicontrol.PushButtonRedirectStrategy>@(varargin)obj.handleCallbackFired(varargin{:}) (line 19)

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback
Error while evaluating Button PrivateButtonPushedFcn.

I found and fixed this issue.  Fix will be in the next v1.6.10 pre-release.

Link to comment
Share on other sites

Hi everyone,

This evening I'm releasing KSPTOT v1.6.10 pre-release 3.  Here's the change log for this pre-release:

  • MFMS: Implemented cancel button for the MFMS multi-run mode progress dialog box.
  • MFMS: MFMS now computes departure delta-v for the objective function instead of departure C3 energy. 
  • LVD: Fixed a bug in the Set Kinematic State action where you couldn't use the set date/time UI.
  • LVD: Implemented NOMAD 4.3.1 optimizer and removed NOMAD 3.9 optimizer.
  • LVD: Main UI orbit display labels can now have their reference frame and element set configurable.
  • LVD: NOMAD optimizer now can make use of the NOMAD surrogate library.  See NOMAD optimizer options.
  • LVD: Limited time slider updates to 20 Hz for smoothness.
  • A number of bug fixes, both reported and not.

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

Edited by Arrowstar
Link to comment
Share on other sites

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.

×
×
  • Create New...