Jump to content

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


Recommended Posts

Alright, everyone, here's KSPTOT v1.6.7 pre-release 4 with a bunch of bug fixes.  Namely:

  • MA/LVD: Added option to set number of parallel workers for optimization.
  • MA: Fixed bug with having more than one variable item in a variable (initial state).
  • MA: LWA can now import target orbit data from KSP.
  • MA: Added functionality to set launch site from ground target in Set State (estimate launch).
  • LVD: Fixed bug with power sources (wrong matrix size stuff).
  • MA: Resolved issue that causes error if an event does not have any states associated with it.

If I said I fixed your bug earlier, can you please check to see that it's actually resolved in this pre-release?  And if you asked for a feature and I added it, please make sure it does what you were expecting it to do.

Thanks for your help everyone!

Link to comment
Share on other sites

16 hours ago, Arrowstar said:
  • LVD: Fixed bug with power sources (wrong matrix size stuff).

If I said I fixed your bug earlier, can you please check to see that it's actually resolved in this pre-release?  And if you asked for a feature and I added it, please make sure it does what you were expecting it to do.

Thanks for your help everyone!

Confirm fixed. Thanks!

New issues found:

- Tab order is incorrect on Edit Constraint window (LVD)

- Another matrix issue: This one happened after I've inserted a DV maneuver. Here is a .mat showing the problem -> https://www.dropbox.com/s/ud7douvshctk7z1/LVD-Direct_ascent_to_duna4.mat?dl=0.  Event 10 is the problematic one. Seems to be related to the alternator stuff too, because it works when I disable the engine alternator.

Log:

Error using /
Matrix dimensions must agree.

Error in LaunchVehicleStateLogEntry.getTankMassFlowRatesDueToEngines (line 541)


Error in AddDeltaVAction/executeAction (line 61)


Error in LaunchVehicleEvent/cleanupEvent (line 151)


Error in LaunchVehicleScript/executeScript (line 298)


Error in ma_LvdMainGUI>propagateScript (line 173)


Error in ma_LvdMainGUI>runScriptMenu_Callback (line 1614)


Error in gui_mainfcn (line 95)


Error in ma_LvdMainGUI (line 42)


Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ma_LvdMainGUI('runScriptMenu_Callback',hObject,eventdata,guidata(hObject))

Error using waitforallfiguresclosed (line 9)
Error while evaluating Menu Callback.

- Weird error when optimizing that same .mat above (without engine alternator):

Error using getParentGM (line 13)
SWITCH expression must be a scalar or a character vector.

Error in getAbsPositBetweenSpacecraftAndBody (line 16)


Error in getSoITransitionOdeEvents (line 29)


Error in AbstractPropagator.odeEvents (line 77)


Error in TwoBodyPropagator.odeEvents (line 213)


Error in TwoBodyPropagator>@(t,y)TwoBodyPropagator.odeEvents(t,y,sma,ecc,inc,raan,arg,gmu,eventInitStateLogEntry,eventTermCondFuncHandle,termCondDir,maxT,checkForSoITrans,nonSeqTermConds,nonSeqTermCauses,minAltitude,celBodyData) (line 108)


Error in TwoBodyPropagator/callEventsFcn (line 128)


Error in LaunchVehicleSimulationDriver/integrateOneEvent (line 119)


Error in LaunchVehicleEvent/executeEvent (line 159)


Error in LaunchVehicleScript/executeScript (line 293)


Error in CompositeObjectiveFcn/evalObjFcn (line 39)


Error in FminconOptimizer>@(x)lvdOpt.objFcn.evalObjFcn(x,evtToStartScriptExecAt) (line 26)


Error in optimfcnchk/checkfun (line 228)


Error in finDiffEvalAndChkErr


Error in parfinitedifferences


Error in parfinitedifferences


Error in computeFinDiffGradAndJac


Error in sqpInterface


Error in fmincon (line 810)


Error in lvd_executeOptimProblem (line 26)


Error in FminconOptimizer/optimize (line 66)


Error in LvdOptimization/optimize (line 50)


Error in ma_LvdMainGUI>optimizeMissionMenu_Callback (line 519)


Error in gui_mainfcn (line 95)


Error in ma_LvdMainGUI (line 42)


Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ma_LvdMainGUI('optimizeMissionMenu_Callback',hObject,eventdata,guidata(hObject))

Error using waitforallfiguresclosed (line 9)
Error while evaluating Menu Callback.

Quality of life suggestion: On the LVD's event list, add a new menu entry when right-clicking the event: "Ensure continuity with previous event". Selecting that would create continuity constraints (position/velocity X/Y/Z + time continuity) between the selected and previous events. Creating all of them manually is really repetitive

 

Edited by vitorboschi
new issues cropped up
Link to comment
Share on other sites

8 hours ago, vitorboschi said:

Confirm fixed. Thanks!

New issues found:

- Tab order is incorrect on Edit Constraint window (LVD)

- Another matrix issue: This one happened after I've inserted a DV maneuver. Here is a .mat showing the problem -> https://www.dropbox.com/s/ud7douvshctk7z1/LVD-Direct_ascent_to_duna4.mat?dl=0.  Event 10 is the problematic one. Seems to be related to the alternator stuff too, because it works when I disable the engine alternator.

Log:


Error using /
Matrix dimensions must agree.

Error in LaunchVehicleStateLogEntry.getTankMassFlowRatesDueToEngines (line 541)


Error in AddDeltaVAction/executeAction (line 61)


Error in LaunchVehicleEvent/cleanupEvent (line 151)


Error in LaunchVehicleScript/executeScript (line 298)


Error in ma_LvdMainGUI>propagateScript (line 173)


Error in ma_LvdMainGUI>runScriptMenu_Callback (line 1614)


Error in gui_mainfcn (line 95)


Error in ma_LvdMainGUI (line 42)


Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ma_LvdMainGUI('runScriptMenu_Callback',hObject,eventdata,guidata(hObject))

Error using waitforallfiguresclosed (line 9)
Error while evaluating Menu Callback.

- Weird error when optimizing that same .mat above (without engine alternator):


Error using getParentGM (line 13)
SWITCH expression must be a scalar or a character vector.

Error in getAbsPositBetweenSpacecraftAndBody (line 16)


Error in getSoITransitionOdeEvents (line 29)


Error in AbstractPropagator.odeEvents (line 77)


Error in TwoBodyPropagator.odeEvents (line 213)


Error in TwoBodyPropagator>@(t,y)TwoBodyPropagator.odeEvents(t,y,sma,ecc,inc,raan,arg,gmu,eventInitStateLogEntry,eventTermCondFuncHandle,termCondDir,maxT,checkForSoITrans,nonSeqTermConds,nonSeqTermCauses,minAltitude,celBodyData) (line 108)


Error in TwoBodyPropagator/callEventsFcn (line 128)


Error in LaunchVehicleSimulationDriver/integrateOneEvent (line 119)


Error in LaunchVehicleEvent/executeEvent (line 159)


Error in LaunchVehicleScript/executeScript (line 293)


Error in CompositeObjectiveFcn/evalObjFcn (line 39)


Error in FminconOptimizer>@(x)lvdOpt.objFcn.evalObjFcn(x,evtToStartScriptExecAt) (line 26)


Error in optimfcnchk/checkfun (line 228)


Error in finDiffEvalAndChkErr


Error in parfinitedifferences


Error in parfinitedifferences


Error in computeFinDiffGradAndJac


Error in sqpInterface


Error in fmincon (line 810)


Error in lvd_executeOptimProblem (line 26)


Error in FminconOptimizer/optimize (line 66)


Error in LvdOptimization/optimize (line 50)


Error in ma_LvdMainGUI>optimizeMissionMenu_Callback (line 519)


Error in gui_mainfcn (line 95)


Error in ma_LvdMainGUI (line 42)


Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ma_LvdMainGUI('optimizeMissionMenu_Callback',hObject,eventdata,guidata(hObject))

Error using waitforallfiguresclosed (line 9)
Error while evaluating Menu Callback.

Quality of life suggestion: On the LVD's event list, add a new menu entry when right-clicking the event: "Ensure continuity with previous event". Selecting that would create continuity constraints (position/velocity X/Y/Z + time continuity) between the selected and previous events. Creating all of them manually is really repetitive

 

  • Tab order corrected for next release.
  • New matrix issue corrected for next release.
  • I couldn't reproduce the issue you saw while optimizing.  Could you check that it is reproducible and see if it occurs when parallel mode both is disabled and enabled?
  • Good QoL suggestion!  I implemented the feature on the script listbox.  Right click the event in the script listbox you want to create continuity constraints with, select the other event to create continuity with, and away you go.
Link to comment
Share on other sites

1 hour ago, Arrowstar said:
  • Tab order corrected for next release.
  • New matrix issue corrected for next release.
  • I couldn't reproduce the issue you saw while optimizing.  Could you check that it is reproducible and see if it occurs when parallel mode both is disabled and enabled?
  • Good QoL suggestion!  I implemented the feature on the script listbox.  Right click the event in the script listbox you want to create continuity constraints with, select the other event to create continuity with, and away you go.

Awesome!

I've tried to reproduce the problem a few times, but it doesn't happen in most of the tries. I'll keep an eye and report back if/when I find how to reproduce the problem reliably.

Link to comment
Share on other sites

8 minutes ago, vitorboschi said:

Awesome!

I've tried to reproduce the problem a few times, but it doesn't happen in most of the tries. I'll keep an eye and report back if/when I find how to reproduce the problem reliably.

Thanks!

As my current build is basically a bug fix release on top of PR4, I think I'm going to go ahead and start rebuilding that, and then simply reupload PR4.  I'll do that tonight and let everyone know when it's done.

Edited by Arrowstar
Link to comment
Share on other sites

16 hours ago, Arrowstar said:
  • Tab order corrected for next release.
  • New matrix issue corrected for next release.
  • I couldn't reproduce the issue you saw while optimizing.  Could you check that it is reproducible and see if it occurs when parallel mode both is disabled and enabled?
  • Good QoL suggestion!  I implemented the feature on the script listbox.  Right click the event in the script listbox you want to create continuity constraints with, select the other event to create continuity with, and away you go.

Tab order: fixed

Matrix issues: fixed

Constraints feature: Working, but there's a typo on the menu entry: "Create Continuity Constraints with Selected EveNt"

 

Question: do you have any modelling tips to avoid stiffness in the optimization problem? It looks like I keep getting warnings like the one below, even when using ODE23s or ODE15s integrators.

Warning: Failure at t=5.154408e+06.  Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.490116e-08) at time t.

Not sure it matters, but this is the .mat where I have this problem (just a simple direct injection to Duna) -> https://www.dropbox.com/s/ud7douvshctk7z1/LVD-Direct_ascent_to_duna4.mat?dl=0

Link to comment
Share on other sites

8 hours ago, vitorboschi said:

Tab order: fixed

Matrix issues: fixed

Constraints feature: Working, but there's a typo on the menu entry: "Create Continuity Constraints with Selected EveNt"

 

Question: do you have any modelling tips to avoid stiffness in the optimization problem? It looks like I keep getting warnings like the one below, even when using ODE23s or ODE15s integrators.


Warning: Failure at t=5.154408e+06.  Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.490116e-08) at time t.

Not sure it matters, but this is the .mat where I have this problem (just a simple direct injection to Duna) -> https://www.dropbox.com/s/ud7douvshctk7z1/LVD-Direct_ascent_to_duna4.mat?dl=0

Typo fixed, thanks.

As far as your issue goes, I figured out what it was.  In event 6, your boosters are running out of propellant and then being jettisoned when their booster tank is empty (mass = 0.0 mT).  However, engines cease to work if their connected tank has 0 or less mass in it, and this was causing some flip-flopping inside the integrator when it was trying to find the exact point at which the booster engine runs out of propellant.

The fix is easy: set the stage jettison tank mass triggers to something just above 0.0 mT, like 0.001 mT.  This does not incur any noticeable launch vehicle performance hit, resolved the integration issue for me, and your simulation propagates so much faster to boot!

EDIT: Another note.  You need to scale your continuity constraints to get better optimization performance.  Try 1E6 for the position, 1.0 or 10.0 for the velocity, and 1000 for the time constraint.

EDIT 2: Throw in a C3 constraint at Event 8 and set the lower bound to be just above 0.0, something like 0.01.  The upper bound should be large (1000 or more).  This will prevent the optimizer from getting trapped in the Kerbin system and throwing off the gradients.

EDIT 3: The other thing that will really help your optimization is using Duna-centric Universal Elements with the C3 element constrained to be greater than some small positive number (0.01).  Yours are currently Sun-centeric Keplerian, which is much harder for the optimizer to work with.

Edited by Arrowstar
Link to comment
Share on other sites

2 hours ago, Arrowstar said:

Typo fixed, thanks.

As far as your issue goes, I figured out what it was.  In event 6, your boosters are running out of propellant and then being jettisoned when their booster tank is empty (mass = 0.0 mT).  However, engines cease to work if their connected tank has 0 or less mass in it, and this was causing some flip-flopping inside the integrator when it was trying to find the exact point at which the booster engine runs out of propellant.

The fix is easy: set the stage jettison tank mass triggers to something just above 0.0 mT, like 0.001 mT.  This does not incur any noticeable launch vehicle performance hit, resolved the integration issue for me, and your simulation propagates so much faster to boot!

EDIT: Another note.  You need to scale your continuity constraints to get better optimization performance.  Try 1E6 for the position, 1.0 or 10.0 for the velocity, and 1000 for the time constraint.

EDIT 2: Throw in a C3 constraint at Event 8 and set the lower bound to be just above 0.0, something like 0.01.  The upper bound should be large (1000 or more).  This will prevent the optimizer from getting trapped in the Kerbin system and throwing off the gradients.

EDIT 3: The other thing that will really help your optimization is using Duna-centric Universal Elements with the C3 element constrained to be greater than some small positive number (0.01).  Yours are currently Sun-centeric Keplerian, which is much harder for the optimizer to work with.

Thanks, that makes sense! I assume a should use the tank mass constraint for all the other events too, right?

Also, it's not clear to me why use a C3 constraint with a big upper bound like that? The hyperbolic velocity vector should be around 0.85 in my case, so why not use a lower bound for C3 energy? Something like 10, or even 2?

Link to comment
Share on other sites

1 minute ago, vitorboschi said:

Thanks, that makes sense! I assume a should use the tank mass constraint for all the other events too, right?

Also, it's not clear to me why use a C3 constraint with a big upper bound like that? The hyperbolic velocity vector should be around 0.85 in my case, so why not use a lower bound for C3 energy? Something like 10, or even 2?

Use the 0.001 mT tank mass termination condition everywhere else you've got it, yes.

The point of the C3 constraint is to make sure the optimizer forces the trajectory to leave the system.  We only care about the lower bound in this case.  Since we don't know (nor care) what the actual C3 is ahead of time, we just set the upper bound to a large number to get it out of the way.  It's generally good to give your optimizer more room to work in unless you explicitly know the answer to something or you have a requirement that dictates a particular value.

Link to comment
Share on other sites

On 8/25/2020 at 2:55 PM, Arrowstar said:

Can you provide me universal time, altitude, latitude, longitude, pressure, temperature, and density for this "more basic" test?  A Google sheets doc would be fine for now.  Thank you! :)

As usual I went quite overboard with this but I really wanted to see also what the difference is between various KSP setups to really understand what the changes are to my install from stock, and confirm what mods are making the changes. Analysis Package link - includes plots for various things in 4k resolution

Full Mod - everything mod I have installed normally
No FAR/Kopernicus - I removed both these mods from my full modded install
No FAR - all mods installed but not FAR
No Kopernicus - all mods installed but not Kopernicus
Stock - nothing but Squad and kOS

Note that removing Kopernicus also nullifies any effect the Realistic Atmospheres mod has

LVD case files were built from scratch in the latest pre-release. Drag area image and Cd values (output from FAR) raw data included.

Flights were flown 3 times under each KSP version and the values of the runs were averaged for the final analysis document

All the raw data is included if you wish to replicate my final results in the analysis worksheet

All the mods relevant to the KSP versions I tested are included in the GameData folder. The /Script folder has the kOS script used and the vessel file is in the /Raw Data folder. If you want to recreate the flights, I will provide additional instructions to do so

Link to comment
Share on other sites

5 hours ago, Drew Kerman said:

As usual I went quite overboard with this but I really wanted to see also what the difference is between various KSP setups to really understand what the changes are to my install from stock, and confirm what mods are making the changes. Analysis Package link - includes plots for various things in 4k resolution

Full Mod - everything mod I have installed normally
No FAR/Kopernicus - I removed both these mods from my full modded install
No FAR - all mods installed but not FAR
No Kopernicus - all mods installed but not Kopernicus
Stock - nothing but Squad and kOS

Note that removing Kopernicus also nullifies any effect the Realistic Atmospheres mod has

LVD case files were built from scratch in the latest pre-release. Drag area image and Cd values (output from FAR) raw data included.

Flights were flown 3 times under each KSP version and the values of the runs were averaged for the final analysis document

All the raw data is included if you wish to replicate my final results in the analysis worksheet

All the mods relevant to the KSP versions I tested are included in the GameData folder. The /Script folder has the kOS script used and the vessel file is in the /Raw Data folder. If you want to recreate the flights, I will provide additional instructions to do so

Wow, thanks for all the data!  This is really a treasure trove.

It remains that temperature is the annoying one of the bunch.  Can you check something for me?  In the Stock data, why does temperature go crazy initially?  It's reading 2000 K at the first data point and 411 K at the next.  Something is wrong there, any ideas?

EDIT: Does kOS have the ability to output more fundamental data from KSP?  Can you ask it to evaluate methods on KSP classes?  If you look at this thread, you'll see a section near the top ("understanding the temperature curves") where there's a few equations that describe KSP's atmo temperature model.  Are these quantities something you can get out of kOS?  For example, can you evaluate currentMainBody.atmosphereTemperatureCurve.Evaluate(altitude)?

Edited by Arrowstar
Link to comment
Share on other sites

5 hours ago, Arrowstar said:

It remains that temperature is the annoying one of the bunch.  Can you check something for me?  In the Stock data, why does temperature go crazy initially?  It's reading 2000 K at the first data point and 411 K at the next.  Something is wrong there, any ideas?

I'm not sure, it may have something to do with how kOS is calculating the temperature values because the density also seems to oddly curve up and over rather than just start with a more linear decrease like you see the LVD data do. I think the initial readings are just a bit bogus and should be tossed out. I know who wrote the code from reddit, I will see if he can provide me more information about it in regards to this

5 hours ago, Arrowstar said:

EDIT: Does kOS have the ability to output more fundamental data from KSP?  Can you ask it to evaluate methods on KSP classes?  If you look at this thread, you'll see a section near the top ("understanding the temperature curves") where there's a few equations that describe KSP's atmo temperature model.  Are these quantities something you can get out of kOS?  For example, can you evaluate currentMainBody.atmosphereTemperatureCurve.Evaluate(altitude)?

fraid not. that may be possible via the kRPC mod or maybe I can get the FAR developer to add atmospheric logging data, since the full-spectrum analysis I did shows that the real culprit of any major change to atmospherics is Kopernicus (Real Atmospheres, really) and not FAR

Link to comment
Share on other sites

1 hour ago, Drew Kerman said:

I'm not sure, it may have something to do with how kOS is calculating the temperature values because the density also seems to oddly curve up and over rather than just start with a more linear decrease like you see the LVD data do. I think the initial readings are just a bit bogus and should be tossed out. I know who wrote the code from reddit, I will see if he can provide me more information about it in regards to this

So I did a ton of comparison today in KSP, using my KSPTOTConnect plugin to basically just display temperature data and evaluate to temperature curves.  I'm starting to believe that some of the differences you're seeing are:

  • A) Due to interpolation differences; and
  • B) An issue with the kOS temperature code. 

Most of my evaluations of those temperature curves were very close, within a Kelvin or so.  There's still something not quite right, but it's not nearly as big as the differences in your output data. 

If you learn anything from the programmer, please let me know. :)

Link to comment
Share on other sites

4 hours ago, Arrowstar said:

If you learn anything from the programmer, please let me know. :)

here's his response:

Quote

There are two forces that I do not account for in my script that might be throwing things off in the upper atmosphere, the first is centrifugal forces and the other is coriolis effects. Just at atmospheric interface the atmosphere is not yet the dominate forces the fact those forces are not accounted for could easy induce errors. Also the script I wrote was intended for all atmospheric calculations to occur with data from same physics tick I don't know how the adaption to the different logging style might change that. And lastly the initial few data sets will be off if there is a significant difference in time between when the file logger.ks is loaded and the function logTlm actually starts logging data as to get some of the forces there are globals that are initialized with the file but not updated when the function starts logging so if there is a time difference then the calculations would be off for a until the averaging smothers things out so the first few data points are likely wrong.

So not sure about the upper atmo data impact but he did mention two things I did not consider when using his script - time between initialization and logging (would explain the bogus early data) and not making sure it all occurs within a single physics tick (not sure of the impacts to that). I plan to fix both of these things and I can also re-run the tests if you'd like

Link to comment
Share on other sites

20 minutes ago, Drew Kerman said:

here's his response:

So not sure about the upper atmo data impact but he did mention two things I did not consider when using his script - time between initialization and logging (would explain the bogus early data) and not making sure it all occurs within a single physics tick (not sure of the impacts to that). I plan to fix both of these things and I can also re-run the tests if you'd like

Sure, give it a shot.  If you want to limit it to just stock KSP for now that would be fine with me.

Link to comment
Share on other sites

9 hours ago, Drew Kerman said:

I re-uploaded the analysis package, made the changes but not much of a difference. New data is "Stock New Logging"

Is this the method you're using in kOS?

Quote

.. method:: Atmosphere:ALTITUDETEMPERATURE(altitude)

    :parameter: altitude (:ref:`scalar <scalar>`) the altitude to query temperature at.
    :access: Get only

    Returns an approximate atmosphere temperature on this world at the given altitude.
    Note that this is only approximate because the temperature will vary depending
    on the sun position in the sky (i.e. your latitude and what time of day it is).

Because if so, it looks like it's not accurate either.  Here's the kOS code that this function calls:

Quote

AddSuffix(new string[] { "ALTITUDETEMPERATURE", "ALTTEMP" }, new OneArgsSuffix<ScalarValue, ScalarValue>((alt) => celestialBody.GetTemperature(alt)));

It's the celestialBody.GetTemperature(alt) bit that's important. If I look at the KSP API, it has this to say on that function:

Quote

baseValue += latitudeTemperatureBiasCurve.Evaluate(latitudeDot);

Assuming this is accurate, I'm guessing base value is the base temperature curve for the body that is only a function of altitude, plus somehow it gets the latitude of the vehicle and plugs that into just one of the elements of the temperature offset. 

Basically, I don't think kOS is accurate here because it doesn't seem to be calling the full temperature model of the atmosphere.  @NathanKell, do you have any idea how the celestialBody.GetTemperature(alt) method works?

Link to comment
Share on other sites

On 8/27/2020 at 4:22 PM, Arrowstar said:

Alright, everyone, here's KSPTOT v1.6.7 pre-release 4 with a bunch of bug fixes.  Namely:

  • MA/LVD: Added option to set number of parallel workers for optimization.
  • MA: Fixed bug with having more than one variable item in a variable (initial state).
  • MA: LWA can now import target orbit data from KSP.
  • MA: Added functionality to set launch site from ground target in Set State (estimate launch).
  • LVD: Fixed bug with power sources (wrong matrix size stuff).
  • MA: Resolved issue that causes error if an event does not have any states associated with it.

If I said I fixed your bug earlier, can you please check to see that it's actually resolved in this pre-release?  And if you asked for a feature and I added it, please make sure it does what you were expecting it to do.

Sorry for the delay, out of town for a bit.

I've checked, and the 2 MA files I posted earlier now seem to work.  Also tried out the number of parallel threads and it seems good - both from checking task monitor as well as seeing that init sped up pretty noticeably. Thanks for both of those.

 

Link to comment
Share on other sites

8 hours ago, Arrowstar said:

Is this the method you're using in kOS?

Nope, it's a custom calculation. Response from the author regarding how his code is getting temperature:

Quote

mine is better the results of :ALTITUDETEMPERATURE are missing a lot of factors that go into the temperature because the real thing we would like to use in the API is broken. :ALTITUDETEMPERATURE is missing the time of day heating, the latitude heating, and the heating from orbital eccentricity. As all of those other factors modify the base value of :ALTITUDETEMPERATUREjust using the return from that will be incorrect. The reason we have it at all is that any attempt to predict future drag of a craft requires some way to get future temperature and this is the only way we have, without resorting to a hard-coded function like what trajectories uses that would break if there is any change to what makes up temperature.

 

Link to comment
Share on other sites

1 hour ago, Drew Kerman said:

Nope, it's a custom calculation. Response from the author regarding how his code is getting temperature:

 

Okay cool.  Which kOS function are you using to grab atmospheric temp then?  I want to take a look at the code and see if there's a discrepancy in there somewhere between what it does and what I do.

Link to comment
Share on other sites

25 minutes ago, Arrowstar said:

Okay cool.  Which kOS function are you using to grab atmospheric temp then?  I want to take a look at the code and see if there's a discrepancy in there somewhere between what it does and what I do.

check the analysis packet, in /script/includes/logger.ks

Not exactly sure how it's being done to be honest I just scraped the code with permission from the author

Link to comment
Share on other sites

14 hours ago, Arrowstar said:

Is this the method you're using in kOS?

Because if so, it looks like it's not accurate either.  Here's the kOS code that this function calls:

It's the celestialBody.GetTemperature(alt) bit that's important. If I look at the KSP API, it has this to say on that function:

Assuming this is accurate, I'm guessing base value is the base temperature curve for the body that is only a function of altitude, plus somehow it gets the latitude of the vehicle and plugs that into just one of the elements of the temperature offset. 

Basically, I don't think kOS is accurate here because it doesn't seem to be calling the full temperature model of the atmosphere.  @NathanKell, do you have any idea how the celestialBody.GetTemperature(alt) method works?

IIRC, CB's GetTemp just gets the base temperature from the temperature curve (i.e. evaluate that float curve by altitude). You want CB.GetAtmoThermalStats(). It gives the offset to the (base) temperature at altitude, given a bunch of inputs. It calculates that offset by getting the dot product between the polar axis and the sunward vector, the latitude (acos of dot(upaxis, body polar axis) ), the sun's minimum and maximum height above the horizon given the body's position in its solar year (this is obvs less meaningful for stock with its lack of axial tilt :D ). From that it figures out how much of a day is in sunlight and how much not. It corrects max daytime temp to ~3pm (for a 12hr day--whatever ) since IRL max daytime temp is not at noon, but later (as more energy gets absorbed). Basically all that figures out a "normalized value" between minimum daily temperature and maximum daily temperature, which is used to multiply the offset given by the latitude sun mult curve, and the seasonal variation is added in (evaluating the sun bias curve), and finally eccentricity is taken into account if that curve is defined.

The function also figures out how much flux is coming from the body if you're in orbit, but that's not what you're asking about.

That's all I recall.

Link to comment
Share on other sites

hey @Arrowstar finally got to work on planning my upcoming second orbital mission (only 11 days away... no pressure...) and I have some bugs/feedback for you on the latest prerelease. Please download this package for the relevant files.

  • GA plots in LVD seem to now constrain the ability to move the data point cursor to within events only. It's a bit annoying to not be able to drag the data point cursor along the entire plot
  • Would you consider import/export of ground objects? Ground stations will be there every mission and ground bases too. Easier to import and delete what's not needed than to recreate every time
  • I did something in Ascension Mk2 #2 Ascent Optimized.mat that creates two problems I only notice after loading this file (neither happen with the default project loaded at LVD start):
    • Trying to add any additional objective function throws an error to the log
    • Going into the Celestial Body Catalog and clicking on Kerbin then selecting the atmosphere plot just locks up the whole program
  • Arrow buttons are no longer disabled in the LVD figure view when I don't have any additional SOI or anything to jump to
  • Is it possible for the figure view not to completely reset to the default view after a change is made to an event?
  • Been meaning to suggest for a while Camera Pan & Zoom be the default for the grabber and magnifying glass instead of Limits
  • Could there be an addition to the Settings->Integration Settings for Global Output Step that would set the output step for all events? Not an override to individual settings, it would modify all the individual event settings
  • When setting a TWR throttle model it won't let me do so unless I set min/max optimizer values
  • I can set a coast to Apokee using any of these three methods, and the last one doesn't make sense (I got TA for Ap/Pe backwards from memory which is why I found a way to set to 0 initially):
    • TA termination 180 increasing/decreasing
    • TA termination 180 increasing
    • TA termination 0 decreasing
  • Finally, there's an additional Ascension Mk2 #2 Orbit.mat file for MA which I used to create a circular orbit insertion burn. I then used the Maneuver Execution Assistant to tell me when to start the burn and its duration. I then attempted to recreate the burn in LVD (over time, not with a DV event) but did not get the same resulting orbit and am wondering what I did incorrectly
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...