MechJeb2

MechJeb2

4M Downloads

Request: PersistentRotation mod support

formicant opened this issue · 3 comments

commented

It would be nice if MechJeb was compatible with MarcusA380’s PersistentRotation plugin.
My guess is that turning on SAS during autowarp will fix the issue. I can be wrong though.

commented

I think it would be nice too!

SAS and Mechjeb are probably mutually exclusive.
What's happening is that Mechjeb is basically flinging itself at the target and relying on the 'stop-rotating-under-warp' bug/cheat, when it should be spending a few more seconds aligning carefully before warping.
Should be a relatively simple fix - just add an appropriate wait before warping (would be less than 2s unless the ship is rotating wildly or has poor attitude control).

commented

Actually I don't think that would work as a fix. Mechjeb can't completely zero any craft's rotation due to KSP's rounding issues, so no matter how long it tries to wait to orient the craft correctly it'll still have some minuscule amount of rotation. That doesn't happen when warping using SAS under this plugin because, as far as I can tell, activating SAS tells Persistent Rotation to treat the craft's rotation as zero through the warp, whereas Smart A.S.S. isn't keyed to do the same. To fix this you'd either need to have Mechjeb "spoof" SAS as being on whenever it uses it's own Smart A.S.S. or PersistentRotation itself would have to somehow know whenever Mechjeb is holding a position.

commented

I succeeded with this straightforward way:

First, I added an if in the SetFlightCtrlState method in MechJebModuleAttitudeController.cs

. . .
private void SetFlightCtrlState(Vector3d act, Vector3d deltaEuler, FlightCtrlState s, float drive_limit)
{
    . . .
    // Disable the new SAS so it won't interfere. 
    // Todo : enable it when it's a good idea or the user had it enabled before
    if(TimeWarp.WarpMode != TimeWarp.Modes.HIGH || TimeWarp.CurrentRateIndex == 0)
        part.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, false);
    . . .
}

Then, I added a new method to MechJebModuleWarpController.cs

// Turn SAS on during regular warp
void SetTimeWarpRate(int rateIndex, bool instant)
{
    if(rateIndex != TimeWarp.CurrentRateIndex)
    {
        if(TimeWarp.WarpMode == TimeWarp.Modes.HIGH && TimeWarp.CurrentRateIndex == 0)
            part.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true);
        TimeWarp.SetRate(rateIndex, instant);
        if(rateIndex == 0)
            part.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, false);
    }
}

And replaced TimeWarp.SetRate invocations with SetTimeWarpRate everywhere in the class.