Jump to content

[old thread] Trajectories : atmospheric predictions


Youen

Recommended Posts

I too am hoping this gets updated to 0.90, but the changes to the tracking station probably made it harder to implement this feature. Patched conics is unavailable at the start, so my guess is that there was a major change to the code this plugin runs on. We should give Youen plenty of time to look into things and see what it will take to update. I might be wrong and it's an easy fix... but it would surprise me if it is simple.

Link to comment
Share on other sites

There was a similar problem with Enhanced Navball. All markers glued to the heading pointer untill you've upgraded tracking station from lvl1 to lvl2. Yet still it did produce quite a bit of warnings while functioning.

Link to comment
Share on other sites

I wasn't even aware a new version of KSP was out :-/

I've stopped playing KSP for some time now. I'll take a look if I find some time and motivation, but honestly, if someone wants to take over the development of this mod, let me know :-)

Some info if anyone is interested:

- there are a few modifications that are already on gihub but not released as a binary yet

- I'd suggest to drop the automated testing part, it's already broken and requires too much work to upgrade to new KSP versions

- Compiling the code should be simple in visual studio : clone the repository, set the references to kerbal DLLs depending on where you installed the game, and build.

- To speed up the development cycle, you can set the path of your game in the .csproj file, then pressing ctrl+f5 in visual studio (while in debug mode) will compile, place the mod in the game, start the game, and automatically load the default save game and fly the first ship in the list

- the version of the assembly must be incremented before each release, updated on http://ksp-avc.cybutek.net, and the Trajectories.version file must be overwriten by the new one

- when building in release mode (visual studio), a zip is automatically created, next to the sln file, that can be uploaded as a new release on github and kerbal stuff

Link to comment
Share on other sites

I wasn't even aware a new version of KSP was out :-/

I've stopped playing KSP for some time now. I'll take a look if I find some time and motivation, but honestly, if someone wants to take over the development of this mod, let me know :-)

That's not-so-great news. Your mod was a nice alternative to MechJebs landing predictions.

Anyway, I'm a programmer myself, and I have interest in getting involved with KSP mods. I am a complete Unity/C#/Modding noob however. I wanted to start out easy and contribute to existing mods, but your mod might be a good a starting point as any.

If you could stick around a while and give me some pointers, I could try getting it to work for .90. Interested?

Edit:

Ok, so I

- forked your Repo

- disabled AutomatedTesting and TestAutomation

- Bumped the version number

- Recompiled and uploaded to here: https://github.com/fat-lobyte/KSPTrajectories/releases/download/v1.1.0.0-pre3/Trajectories-1.1.0.0-pre.zip

- Tested it.

All seems to work. No crashes, no errors in the log file, all GUI is available and since I figured out that you should check "Body-Fixed mode", it's even super-accurate (landed at the KSC after making a deorbit burn at phase angle ~330°) :)

I don't know how this AVC / CKAN busyness all works, but since it's working nicely, I'd recommend that you upload it so people can make use of it.

Edit 2: Does not work with Ferram Aerospace yet.

Moderator edit:

Source: https://github.com/fat-lobyte/KSPTrajectories

License: MIT

Edited by Master Tao
Link to comment
Share on other sites

Sure, sounds good :-)

Let me know if you have issues getting the code, building it, etc.

I don't have any clue as to what goes wrong with 0.90 though. Also, I'm afraid debugging KSP mods is really a pain, because there is no debugger that works (as far as I know). So you have to write stuff in the log file, or on the screen.

Link to comment
Share on other sites

That's not-so-great news. Your mod was a nice alternative to MechJebs landing predictions.

Edit:

Ok, so I

- forked your Repo

All seems to work. No crashes, no errors in the log file, all GUI is available and since I figured out that you should check "Body-Fixed mode", it's even super-accurate (landed at the KSC after making a deorbit burn at phase angle ~330°) :)

Edit 2: Does not work with Ferram Aerospace yet.

Awesome news. I'll keep my eye on this for when it has FAR support

Link to comment
Share on other sites

Awesome news. I'll keep my eye on this for when it has FAR support
Kobymaru's version seems to work perfectly with stock air at least. Thanks for keeping this going.

Thanks guys. Don't expect to much though, I don't have any Aerodynamics knowledge :(

And now for some tech talk... Do we have an Add-On development Thread for this?

Let me know if you have issues getting the code, building it, etc.

I don't have any clue as to what goes wrong with 0.90 though. Also, I'm afraid debugging KSP mods is really a pain, because there is no debugger that works (as far as I know). So you have to write stuff in the log file, or on the screen.

About FAR:

So I fixed the obvious method loading error in b1e5a9 . Now it "kinda" works. That means that as long as you're suborbital, you get a nice trajectory. But:

- If the trajectories are enabled, I get tons of "FAR Error: Aerodynamic force = NaN ". What's up with that?

- When you are Orbital and either actually go Suborbital or make a Maneuver node that does that and having Trajectories active, the game freezes up without any errors in the logs. Not cool. Any Idea how to debug this?

Link to comment
Share on other sites

Thanks guys. Don't expect to much though, I don't have any Aerodynamics knowledge :(

And now for some tech talk... Do we have an Add-On development Thread for this?

About FAR:

So I fixed the obvious method loading error in b1e5a9 . Now it "kinda" works. That means that as long as you're suborbital, you get a nice trajectory. But:

- If the trajectories are enabled, I get tons of "FAR Error: Aerodynamic force = NaN ". What's up with that?

- When you are Orbital and either actually go Suborbital or make a Maneuver node that does that and having Trajectories active, the game freezes up without any errors in the logs. Not cool. Any Idea how to debug this?

Might shoot a PM to ferram and see if he has any ideas. Perhaps post something in general development thread. Sounds like it is not interpreting the data from FAR correctly.

Link to comment
Share on other sites

Kobymaru,

Thanks for picking this up. And thanks Youen for allowing such a transition.

Your rebuild works well for me on everything except early career when Patched Conics haven't been unlocked in the Tracking Station due to an existing bug exposed by the new Upgradeable Facilities. In Trajectory.cs, Line #228

bool finished = !partialComputation_.MoveNext();

attempts to do a MoveNext() on partialComputation_, in a situation where partialComputation_ has already been Dispose()ed (3 lines above, #225). (At least I think that's what's up based on my quick skimming of the code.) I fixed this by repeating the null check on partialComputation_ after exiting the block that Dispose()ed it, returning if null, but there might be a more elegant or correct solution.

A different issue occurs when pressing the "Update Now" button, MapGUI.cs in MainWindow line #152 where it performs an InvalidateAerodynamicModel(). I've not looked into why, but it would appear aerodynamicModel_ is null at that point. (Possibly because it was never instantiated because it wasn't valid for the vessel? (Trajectory.cs, line #253.))

The above two can be replicated by starting a fresh Career game, launching a vessel, going to the Map View and enabling Trajectories. I can send you an output log if you need it, but it was a reliably repeatable NRE for me.

I'm wondering if most of the plugin should be disabled when Patched Conics haven't been unlocked through TrackingStation upgrades, and got as much working last night, but doing that might be adding complexity to solve a problem that goes away on its own. The code seems robust enough to handle such a situation already.

Anyway, hope that helps.

Edited by Cydonian Monk
Link to comment
Share on other sites

That's not-so-great news. Your mod was a nice alternative to MechJebs landing predictions.

Anyway, I'm a programmer myself, and I have interest in getting involved with KSP mods. I am a complete Unity/C#/Modding noob however. I wanted to start out easy and contribute to existing mods, but your mod might be a good a starting point as any.

If you could stick around a while and give me some pointers, I could try getting it to work for .90. Interested?

Edit:

Ok, so I

- forked your Repo

- disabled AutomatedTesting and TestAutomation

- Bumped the version number

- Recompiled and uploaded to here: https://github.com/fat-lobyte/KSPTrajectories/releases/download/v1.1.0.0-pre1/Trajectories-v1.1.0.0.zip

- Tested it.

All seems to work. No crashes, no errors in the log file, all GUI is available and since I figured out that you should check "Body-Fixed mode", it's even super-accurate (landed at the KSC after making a deorbit burn at phase angle ~330°) :)

I don't know how this AVC / CKAN busyness all works, but since it's working nicely, I'd recommend that you upload it so people can make use of it.

Edit 2: Does not work with Ferram Aerospace yet.

I noticed you are packaging this with MM 2.5.1. That version is not compatible with KSP .90. Might want to update that.

Link to comment
Share on other sites

I noticed you are packaging this with MM 2.5.1. That version is not compatible with KSP .90. Might want to update that.

I'd noticed this as well, my GameData folder has both MM 2.5.1 and 2.5.4 because one or two mods (this being one) comes with the 2.5.1 instead of the 2.5.4 version.

Link to comment
Share on other sites

Kobymaru,

Thanks for picking this up. And thanks Youen for allowing such a transition.

Your rebuild works well for me on everything except early career when Patched Conics haven't been unlocked in the Tracking Station due to an existing bug exposed by the new Upgradeable Facilities. In Trajectory.cs, Line #228

bool finished = !partialComputation_.MoveNext();

attempts to do a MoveNext() on partialComputation_, in a situation where partialComputation_ has already been Dispose()ed (3 lines above, #225). (At least I think that's what's up based on my quick skimming of the code.) I fixed this by repeating the null check on partialComputation_ after exiting the block that Dispose()ed it, returning if null, but there might be a more elegant or correct solution.

Okay, now what the heck?



if (partialComputation_ == null)
UnityEngine.Debug.LogError("Trajectories: partialComputation_ is null but shouldnt be");
else
UnityEngine.Debug.LogWarning("Trajectories: partialComputation_ is not null");


bool finished = !partialComputation_.MoveNext();

produces

Trajectories: partialComputation_ is not null

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

Trajectories: partialComputation_ is not null

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

NullReferenceException: Object reference not set to an instance of an object

at Trajectories.Trajectory+<computeTrajectoryIncrement>d__7.MoveNext () [0x00000] in <filename unknown>:0

at Trajectories.Trajectory.ComputeTrajectory (.Vessel vessel, Trajectories.DescentProfile profile, Boolean incremental) [0x00000] in <filename unknown>:0

(Filename: Line: -1)

How is that even possible? What is going on? NRE if its not even Null? SEND HELP :confused:

I would give my firstborn to the Devil for a working debugger :(

Where exactly did you put the return statement?

A different issue occurs when pressing the "Update Now" button, MapGUI.cs in MainWindow line #152 where it performs an InvalidateAerodynamicModel(). I've not looked into why, but it would appear aerodynamicModel_ is null at that point. (Possibly because it was never instantiated because it wasn't valid for the vessel? (Trajectory.cs, line #253.))

The above two can be replicated by starting a fresh Career game, launching a vessel, going to the Map View and enabling Trajectories. I can send you an output log if you need it, but it was a reliably repeatable NRE for me.

Can't reproduce the second one (or It's so spammed with the first one that even Ctrl-F can't find it in the log ;) ) A log would actually be nice.
I'm wondering if most of the plugin should be disabled when Patched Conics haven't been unlocked through TrackingStation upgrades, and got as much working last night, but doing that might be adding complexity to solve a problem that goes away on its own. The code seems robust enough to handle such a situation already.

That might be a good idea. What do you by mean "a problem that goes away on its own"? Since I am not familiar with the code, you will probably have better ideas than me.

Your help is very appreciated, by the way!

Link to comment
Share on other sites

I noticed you are packaging this with MM 2.5.1. That version is not compatible with KSP .90. Might want to update that.
I'd noticed this as well, my GameData folder has both MM 2.5.1 and 2.5.4 because one or two mods (this being one) comes with the 2.5.1 instead of the 2.5.4 version.

Finally something I can fix :D

Thanks for the note, I updated the MM version in the latest build.

Do not use with FAR, it will freeze up your game though.

Link to comment
Share on other sites

Debugging without a debugger is one of those joys those of us that do lots of embedded development get to practice. ;) It's a good day when the system has gdb, and gdb actually works. Anyway....

Where exactly did you put the return statement?

Let me preface this by saying that caffeine should not be used as a replacement for sleep. ;) Apparently I was skipping out of that code when partialComputation_ was not null, opposed to what I claimed this morning. (Doing that might cause other issues by not cleaning up the partial computations?) I blame 0.90 and some glitchy RFID stuff at work.

So, working through this....

I split up the block of code that checks if partialComputation_ is null or if the vessel has changed to see if that would tell me more. Not really - every time it was null (as expected), and only when patched conics aren't unlocked does the MoveNext() cause the NRE. So then the issue is in the execution of computeTrajectoryIncrement performed by the MoveNext(). Digging into that revealed an issue in that function's for() loop.

There's a line in computeTrajectoryIncrement that attempts to get the Vessel.patchedConicSolver.maneuverNodes (line #267), yet patchedConicSolver is null. Makes sense as we're not even supposed to have Patched Conics yet. No reason for the game to instantiate that object. The most direct fix from there is self-evident:

Trajectory.cs Line#267-278 get wrapped in a null check as such:


if (null != vessel_.patchedConicSolver)
{
var maneuverNodes = vessel_.patchedConicSolver.maneuverNodes;
foreach (var node in maneuverNodes)
{
if (node.UT == state.time)
{
state.velocity += node.GetBurnVector(createOrbitFromState(state));
break;
}
}
foreach (var result in AddPatch(state, profile))
yield return false;
}

There is a similar issue in AddPatch, so that call must also be protected. Yet let's go ahead and fix that issue too instead of just hiding it. To do that, I added a check to the start of AddPatch() to see if the patchedConicsSolver exists, as such:

Trajectory.cs code added above Line#325:


if (null == vessel_.patchedConicSolver)
{
UnityEngine.Debug.LogWarning("Trajectories: AddPatch() attempted when patchedConicsSolver is null; Skipping.");
yield break;
}

There are still the usual number of executions on Update(), so this fix doesn't help so much with the (admittedly negligible) CPU load, but at least it resolves the logspam and the NREs.

Feel free to use the above code snippets however you like.

Can't reproduce the second one (or It's so spammed with the first one that even Ctrl-F can't find it in the log ;) ) A log would actually be nice.

That issue seems to have resolved itself by patching one of the other two functions.

That might be a good idea. What do you by mean "a problem that goes away on its own"?

Well, the problem as I see it are the NREs that end up causing the logspam. If we resolve the NREs, which in turn prevents the trajectory from being displayed when PatchedConics aren't unlocked, then there's no need to disable the plugin. The "problem" at that point becomes one of feedback to the user, who probably just wants to know why their trajectory isn't being displayed. A simple message in either the Trajectories window or an on-screen message might be enough to fix that.

If you want to start checking facility status, you're looking at some checks along the lines of:

GameVariables.OrbitDisplayMode.PatchedConics.Equals(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation))

That probably needs to be a range check though, for states that exist beyond PatchedConics. I've not done much with the facility upgrade checks yet, so others might have better pointers.

Hope that helps.

Edited by Cydonian Monk
Link to comment
Share on other sites

since I figured out that you should check "Body-Fixed mode", it's even super-accurate

I'm not sure to understand what you mean here. Body-fixed mode only changes how the trajectory is displayed (relative to the rotating frame of the body, instead of the inertial frame), but doesn't change the impact position (indicated by the red cross which is at the same place in both cases).

I don't know how this AVC / CKAN busyness all works, but since it's working nicely, I'd recommend that you upload it so people can make use of it.

Edit 2: Does not work with Ferram Aerospace yet.

Maybe would be worth waiting for it to work with FAR before releasing on AVC and Kerbal Stuff ? (people can still download version 1.1 on github in the meantime).

And now for some tech talk... Do we have an Add-On development Thread for this?

Not yet, feel free to create one :-)

About FAR:

So I fixed the obvious method loading error in b1e5a9 . Now it "kinda" works. That means that as long as you're suborbital, you get a nice trajectory. But:

- If the trajectories are enabled, I get tons of "FAR Error: Aerodynamic force = NaN ". What's up with that?

- When you are Orbital and either actually go Suborbital or make a Maneuver node that does that and having Trajectories active, the game freezes up without any errors in the logs. Not cool. Any Idea how to debug this?

No idea yet... Didn't have these issues with previous versions of FAR. The mod should not try to call FAR functions with out-of-atmosphere parameters, but maybe something changed and now it fails with almost 0 or 0 air density ?

Link to comment
Share on other sites

There are still the usual number of executions on Update(), so this fix doesn't help so much with the (admittedly negligible) CPU load, but at least it resolves the logspam and the NREs.

Feel free to use the above code snippets however you like.

That issue seems to have resolved itself by patching one of the other two functions.

Glad you found the root cause :-) I don't think the CPU load is an issue, because it doesn't degrade the worst case (which is when trajectories are actually displayed).

Link to comment
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.

×
×
  • Create New...