Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with MJ's handling of gimbalResponseSpeed #1859

Open
Starwaster opened this issue Jan 31, 2024 · 1 comment
Open

Issue with MJ's handling of gimbalResponseSpeed #1859

Starwaster opened this issue Jan 31, 2024 · 1 comment

Comments

@Starwaster
Copy link
Contributor

Starwaster commented Jan 31, 2024

Looking at how MJ factors in gimbalResponseSpeed into torqueReactionSpeed6

torqueReactionSpeed6.Add(Mathf.Abs(g.gimbalRange) / g.gimbalResponseSpeed * Vector3d.Max(pos.Abs(), neg.Abs()));

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants