Autostage fails to stage
blnk2007 opened this issue ยท 6 comments
I have been having the issue of autostage sometimes failing to stage. It's usually around the second or third stage.
bink2007: I've root-caused a similar failure-to-stage issue in the mechjeb dev branch -- refusing to stage unless all resources (for instance, both fuel and oxidizer) go to zero. Can you show the current fuel and oxidizer levels in the failed stage?
I think this is where the issue lies:
//detect if a part is above an active or idle engine in the part tree
public static bool HasActiveOrIdleEngineOrTankDescendant(Part p, List<int> tankResources)
{
if ((p.State == PartStates.ACTIVE || p.State == PartStates.IDLE)
&& p.IsEngine() && !p.IsSepratron() && p.EngineHasFuel())
{
return true; // TODO: properly check if ModuleEngines is active
}
if ((p is FuelTank) && (((FuelTank)p).fuel > 0)) return true;
if (!p.IsSepratron())
{
for (int i = 0; i < p.Resources.Count; i++)
{
PartResource r = p.Resources[i];
if (r.amount > 0 && r.info.name != "ElectricCharge" && tankResources.Contains(r.info.id))
{
return true;
}
}
}
for (int i = 0; i < p.children.Count; i++)
{
if (HasActiveOrIdleEngineOrTankDescendant(p.children[i], tankResources))
{
return true;
}
}
return false;
}
I have hot rockets and it seems that some rockets are failing to shutdown even after they are out of fuel.
Exact same issue... In fact i have many strange behavior.
Autopilot not doing anything.... not TimeWorping, not triggering engines on Q for the nodes he creates, ... and not staging.
Usually doesn't stage after the first one... For the past hour, doesn't stage at all !... Weird... as if he was emotionally motivated !
I installed very recently !...MechJeb2-2.5.1.0
Thanks for any help.
After writing my message above, i took a second to read the code pasted by blnk2007... it made me realize what the problem is... There's a sort of mismatch in your heuristic... You use both "Stage Structure" and the actual "Rocket Structure"...
To prove this i went back to the game and edited the rocket that was causing all the failures mentioned in my previous message. I simply changed the "Root Part" so that the root becomes the tip of the rocket... (Yes i sometimes need to set the central first engine as the root... the engine of the very last stage.)
Now in this particular rocket, the root was the engine of the last stage and then with the root now being the tip and stage 0, everything in MechJeb becomes functional again !
This is a work around as i do not thing that having assembly roots set like i did should cause these issues...