MuMech / MechJeb2

MechJeb2 - KSP mod
Other
982 stars 250 forks source link

Issue with MJ's handling of gimbalResponseSpeed #1859

Open Starwaster opened 5 months ago

Starwaster commented 5 months ago

Looking at how MJ factors in gimbalResponseSpeed into torqueReactionSpeed6

https://github.com/MuMech/MechJeb2/blob/7ebb844a5363ae000792710b1756dc03a2f3bc23/MechJeb2/VesselState.cs#L1081

This code is making wrong assumptions that are compounded by bad stock code. The first problem is that gimbalRange is irrelevant to how long it takes the gimbal to reach maximum deflection. It actually takes the same amount of time no matter how far it has to gimbal.

ModuleGimbal does: lerp(current pos, goal pos, gimbalResponseSpeed * fixedDeltaTime)

Because of the way lerp works, the default speed of 10 means that gimbaling happens in 5 frames (1/10th of a second) It also means that the gimbal rate is not constant. Highest rate is on the first frame. Assuming gimbal range of 10, that looks something like:

Frame 1 = 2 (100 deg/sec) Frame 2 = 5.2 (80 deg/sec) Frame 3 = 8.08 (48 deg/sec) Frame 4 = 9.616 (19.2 deg/sec) Frame 5 = 10 (3.84 deg/sec)

Removing gimbalRange from MJ's handling will help, but I'm not sure what the answer is to ModuleGimbal's implementation. lerp shouldn't be used the way they're using it. (using the current value to lerp FROM guarantees the rate can't be constant and multiplying a clamped value by speed means it's converging on its goal a lot sooner than we think it is)

lamont-granquist commented 4 months ago

I don't see a lot in MJ that depends on the torqueReactionSpeed other than the old MJ PID, but this is definitely useful information to have about how gimbal response works in KSP since there's some deficiencies in the "bettercontroller" that i think could get fixed by adjustments to take into account gimbal repsonse (which it entirely ignores). By knowing what KSP does I can probably simulate the response speed delays in matlab/simulink and get some PID scheduling out of it. Unfortunately, I'm hacking on PVG stuff right now and burned out on PID things awhile back and need some time to pass before I start wanting to scratch that itch again. This is definitely good research though.