MechJeb2

MechJeb2

4M Downloads

[Enhacement] StageManager alternative to be able to run autostage on non-active vessels.

jrodrigv opened this issue ยท 16 comments

commented

Hi,

I think the title is enough descriptive but basically I think it would be very nice to be able to ascent vessels remotely even without focus on them.

Currently the StageManager is a limitation to achieve this because is bound to the active vessel and also couple with the UI.

commented

So what you're saying is that all the occurrences of StageManager.CurrentStage (being a horrible KSP global bound to the active vessel) should be replaced by vessel.currentStage instance attributes.

Looks like StageManager.ActivateNextStage and StageManager.ActivateStage are also called though and I don't know what APIs could replace those.

commented

@lamont-granquist Yes, I'm trying to enhance Mechjeb so it can be used not only on the active vessel but also for other non-active vessels in parallel.
For example we can imagine the scenario of the SpaceX Falcon Heavy where there are up to 4 vessels executing Mechjeb, 3 of them doing a Landing Autopilot and 1 doing an Ascent Autopilot.

One stopper for this is the use of the StageManager class because it is meant to only be used for the active vessel. I have decompiled the code and there are specific checks for the active vessel.

I will do a more deep investigation to see if it is possible to implement a custom StageManager.

commented

Thank you @lamont-granquist . I will give it a go. Although as you mention maybe the easiest way would be to add a check in MJ when is trying to Stage so if the vessel is not the active one, it switch to that vessel, then Stage and finally it comes back to the previous vessel.

In fact I think that solution would be better from a user perspective because it will provide information about important events on other vessels.

commented

I don't think you want to "write a custom StageManager" you just want to use the APIs that touch the vessel the MechJebCore is attached to. I just don't know what APIs KSP offers to trigger staging on a particular Vessel object. If you want to hunt around in the kOS codebase they might have hit and fixed this problem there.

commented

A skim of kOS's docs suggest that kOS can only stage when the cpu vessel is the active vessel.

Also turned up this forum thread from years past:

https://forum.kerbalspaceprogram.com/index.php?/topic/64728-remote-staging/

That algorithm seems slightly dubious.

I'm not sure if that is what you meant by "write a custom StageManager".

commented

kRPC also just uses StageManager.ActivateNextStage() on the active vessel.

this may be "easier" to implement as a feature to have MJ automatically switch to the active vessel for staging.

commented

Although apparently the way to roll your own is:

  • set vessel.updateResourcesOnEvent = false
  • loop through all the parts in the stage and fire OnStage on all of those parts
  • set vessel.updateResourcesOnEvent = true
  • call UpdateResourceSetsIfDirty
  • then decrement the vessel's current stage
commented

I'll with the "power that be" if they are willing to move the staging code into Vessel. It would make sense to decouple it from the UI anyaway...

commented

Also, it is easy to duplicate the stock functionality in MJ (and I have done it many times) but the real problem is making sure that the code stays up to date with stock...

commented

@sarbian yeah, that gives me pause as well... best solution is if they'd just hang an interface off of Vessel in KSP itself...

commented

Yes I agree. I think KSP was not designed for remote staging although it support flybywire ? Lol. It is not very coherent.

BTW In BDArmory I implemented autostaging capabilities for misiles but based on action groups (each Custom Action group is one stage) instead of StageManager.

commented

did the really really trivially easy bit.

There's also StageManager.LastStage and StageManager.StageCount and StageManager.ActivateStage(num) plus still some StageManager.CurrentStage references in FuelFlowSimulation.

commented

I have been implementing the method of auto switching to the vessel that needs to stage and then switching back to the original active vessel.

It seems to work fine :) I still doing testing.

I will upload a demo video soon.

commented

@sarbian @lamont-granquist
After few weeks of testing and fixing things. I not only managed to make the autostage to work on remote vessels but also to enable the landing maneuver to be executed on different non-active vessels.
I have recorded a quite epic video as demo.
https://youtu.be/9jTMiJbdX7o

I have added a couple of new actions to Mechjeb. One for Landing somewhere and one to Land at target
I will open a Pull Request with all this stuff

commented

Sorry.... this was a year ago...

commented

I really hope this gets integrated into MJ.
I have tested it as well, and it is an excellent addition.