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

Added Dynamic Deflection for Control Surfaces Option #110

Merged
merged 2 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion FerramAerospaceResearch/LEGACYferram4/FARControllableSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,45 @@ public class FARControllableSurface : FARWingAerodynamicModel, ITorqueProvider
stepIncrement = 0.5f)]
public float maxdeflectFlap = 15;

[KSPField(guiName = "FARCtrlShowDynamicDeflection", guiActiveEditor = true, guiActive = true),
UI_Toggle(affectSymCounterparts = UI_Scene.All,
scene = UI_Scene.All,
disabledText = "FARCtrlSurfStdText",
enabledText = "FARCtrlSurfStdText")]
private bool showDynamicDeflection = false;

[KSPField(guiName = "FARCtrlDynamicDeflection", isPersistant = true, guiActiveEditor = false, guiActive = false),
UI_Toggle(affectSymCounterparts = UI_Scene.All,
enabledText = "FARCtrlSurfFlapActive",
scene = UI_Scene.All,
disabledText = "FARCtrlSurfFlapInActive")]
public bool isDynamicDeflection = false;
public bool isPrevDynamicDeflection = true;

[KSPField(guiName = "FARCtrlDynamicStartSpeed", isPersistant = true, guiActiveEditor = true, guiActive = true),
UI_FloatRange(affectSymCounterparts = UI_Scene.All,
maxValue = 1000.0f,
minValue = 0f,
scene = UI_Scene.All,
stepIncrement = 10f)]
public float dynamicControlStartSpeed = 200.0f;

[KSPField(guiName = "FARCtrlDynamicExponent", isPersistant = true, guiActiveEditor = true, guiActive = true),
UI_FloatRange(affectSymCounterparts = UI_Scene.All,
maxValue = 4.0f,
minValue = 0.0f,
scene = UI_Scene.All,
stepIncrement = 0.1f)]
public float exponent = 2f;

[KSPField(guiName = "FARCtrlDynamicMinControl", isPersistant = true, guiActiveEditor = true, guiActive = true),
UI_FloatRange(affectSymCounterparts = UI_Scene.All,
maxValue = 1f,
minValue = 0f,
scene = UI_Scene.All,
stepIncrement = 0.05f)]
public float minControl = 0.1f;

protected double PitchLocation;
protected double YawLocation;
protected double RollLocation;
Expand Down Expand Up @@ -326,6 +365,20 @@ private void CheckFieldVisibility()
prevStdCtrl = showStdCtrl;
}

if (showDynamicDeflection != isPrevDynamicDeflection)
{
Fields["dynamicControlStartSpeed"].guiActiveEditor = showDynamicDeflection;
Fields["exponent"].guiActiveEditor = showDynamicDeflection;
Fields["minControl"].guiActiveEditor = showDynamicDeflection;
Fields["isDynamicDeflection"].guiActiveEditor = showDynamicDeflection;

Fields["dynamicControlStartSpeed"].guiActive = showDynamicDeflection;
Fields["exponent"].guiActive = showDynamicDeflection;
Fields["minControl"].guiActive = showDynamicDeflection;
Fields["isDynamicDeflection"].guiActive = showDynamicDeflection;
isPrevDynamicDeflection = showDynamicDeflection;
}

if (showFlpCtrl != prevFlpCtrl)
{
Fields["isFlap"].guiActiveEditor = showFlpCtrl;
Expand Down Expand Up @@ -571,9 +624,21 @@ private void AoAOffsetFromControl()
}

AoAdesiredControl *= AoAsign;
AoAdesiredControl *= CalculateDynamicControlFactor();
AoAdesiredControl = AoAdesiredControl.Clamp(-Math.Abs(maxdeflect), Math.Abs(maxdeflect));
}

private double CalculateDynamicControlFactor()
{
double factor = 1;
if (vessel.atmDensity > 0.01 && isDynamicDeflection)
{
factor = Math.Pow(dynamicControlStartSpeed / vessel.srfSpeed, exponent) / (vessel.atmDensity / vessel.lastBody.atmDensityASL);
}

return factor.Clamp(minControl,1);
}

public override double CalculateAoA(Vector3d velocity)
{
// Use the vector computed by DeflectionAnimation
Expand Down Expand Up @@ -603,7 +668,7 @@ bool forceSetToDesired
)
{
double error = desired - current;
if (!forceSetToDesired && Math.Abs(error) >= 0.1
if (!forceSetToDesired && Math.Abs(error) >= 0.01
) // DaMichel: i changed the threshold since i noticed a "bump" at max deflection
{
double tmp1 = error / blendTimeConstant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@
FARCtrlActionDecFlap = Decrease Flap Deflection
FARCtrlEventIncFlap = Deflect more
FARCtrlEventDecFlap = Deflect less

FARCtrlShowDynamicDeflection = Dynamic Deflection
FARCtrlDynamicDeflection = Toggle Dynamic Deflection
FARCtrlDynamicStartSpeed = Start Speed
FARCtrlDynamicExponent = Reduction Exponent
FARCtrlDynamicMinControl = Minimal Control

FARWingMassStrength = Mass-Strength Multiplier %
FARWingStalled = Stalled %
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ Localization
FARCtrlActionDecFlap = Verringere Klappenauslenkung
FARCtrlEventIncFlap = Mehr auslenken
FARCtrlEventDecFlap = Weniger auslenken

FARCtrlShowDynamicDeflection = Dynamische Aslnk Einst.
FARCtrlDynamicDeflection = Aktiviere Dynamische Aslnk
FARCtrlDynamicStartSpeed = Start Geschw.
FARCtrlDynamicExponent = Reduktionsexponent
FARCtrlDynamicMinControl = Minimale Kontrolle

FARWingMassStrength = Gewicht-Kraft Multiplikator %
FARWingStalled = Stalled %
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@
FARCtrlActionDecFlap = Уменьш. откл. закрылков
FARCtrlEventIncFlap = Увелич. откл.
FARCtrlEventDecFlap = Уменьш. откл.

FARCtrlShowDynamicDeflection = Dynamic Deflection
FARCtrlDynamicDeflection = Toggle Dynamic Deflection
FARCtrlDynamicStartSpeed = Start Speed
FARCtrlDynamicExponent = Reduction Exponent
FARCtrlDynamicMinControl = Minimal Control

FARWingMassStrength = Коэфф-т массы+прочности
FARWingStalled = % сваливания
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@
FARCtrlActionDecFlap = 减少襟翼偏转
FARCtrlEventIncFlap = 偏转增加
FARCtrlEventDecFlap = 偏转减少

FARCtrlShowDynamicDeflection = Dynamic Deflection
FARCtrlDynamicDeflection = Toggle Dynamic Deflection
FARCtrlDynamicStartSpeed = Start Speed
FARCtrlDynamicExponent = Reduction Exponent
FARCtrlDynamicMinControl = Minimal Control

FARWingMassStrength = 质量-强度 因子 %
FARWingStalled = 失速 %
Expand Down