Skip to content

Commit

Permalink
Merged development branch
Browse files Browse the repository at this point in the history
  • Loading branch information
allista committed Feb 18, 2022
2 parents b79a737 + 1d4e862 commit 137ee77
Show file tree
Hide file tree
Showing 29 changed files with 1,408 additions and 231 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,4 @@ pip-log.txt
UserPrefs.xml
/ThrottleControlledAvionics.sln
/GameData/ThrottleControlledAvionics/Plugins/*.dll
/TCA.UI/TCA.UI.csproj.DotSettings
10 changes: 5 additions & 5 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

#if NIGHTBUILD
[assembly: AssemblyVersion("3.7.*")]
[assembly: AssemblyVersion("3.8.*")]
#else
[assembly: AssemblyVersion("3.7.2")]
[assembly: AssemblyVersion("3.8.0")]
#endif
[assembly: KSPAssembly("ThrottleControlledAvionics", 3, 7)]
[assembly: KSPAssembly("ThrottleControlledAvionics", 3, 8)]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand All @@ -46,8 +46,8 @@ public class ModInfo : KSP_AVC_Info
{
public ModInfo()
{
MinKSPVersion = new Version(1, 9, 0);
MaxKSPVersion = new Version(1, 10, 0);
MinKSPVersion = new Version(1, 11, 1);
MaxKSPVersion = new Version(1, 11, 1);

VersionURL = "https://raw.githubusercontent.com/allista/ThrottleControlledAvionics/master/GameData/ThrottleControlledAvionics/ThrottleControlledAvionics.version";
UpgradeURL = "http://spacedock.info/mod/198/Throttle%20Controlled%20Avionics";
Expand Down
28 changes: 27 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@

_**BUT** do not delete the ThrottleControlledAvionics.user and config.xml files to preserve your settings_

* **v3.7.2**
* **v3.8.0**
* KSP: 1.11.1
* UI
* Advanced Tab: added **Show CoM** toggle to visualize the CoM with an Icon
* Indicator sounds are paused with the game
* REN:
* improved calculation of the best in-plane ascent orbit
* fixed NRE
* ToOrbit:
* **reimplemented**
* gravity turn logic
* target correction logic
* added
* **Max AoA** and **Max Dyn.Pressure** settings
* **First ApA** setting
* correctly handling gravity turn in case we passed suborbital ApA
* Engines:
* fixed the order of calculations in InitState
* added WeightedThrustMod calculation
* added isThruster and thrustLimiterLocked flags
* ThrustM differentiates between throttleLocked and thrustLimiterLocked
* ThrustAtAlt respectes thrustLimiterLocked flag
* UpdateCurrentTorque sets throttle to 1 if engine.throttleLocked
* Merge pull request #102 from HebaruSan/patch-1
* Fix version file compatibility (KSP 1.10)

* v3.7.2
* **Taking aerodynamic forces into account**
* when balancing engines
* in vertical speed controller
Expand Down
38 changes: 26 additions & 12 deletions EngineWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ public class EngineWrapper : ThrusterWrapper
public float VSF; //vertical speed factor
public bool isVSC; //vertical speed controller
public bool isSteering;
public bool isThruster;
public bool thrustLimiterLocked;
public TCARole Role => info.Role;
public int Group => info.group;

Expand Down Expand Up @@ -330,14 +332,15 @@ float ratio_factor

public override void InitLimits()
{
isVSC = isSteering = false;
isVSC = isSteering = isThruster = thrustLimiterLocked = false;
switch(Role)
{
case TCARole.MAIN:
case TCARole.BALANCE:
case TCARole.UNBALANCE:
limit = best_limit = 1f;
isSteering = Role == TCARole.MAIN;
isThruster = true;
isVSC = true;
break;
case TCARole.MANEUVER:
Expand All @@ -346,6 +349,8 @@ public override void InitLimits()
break;
case TCARole.MANUAL:
limit = best_limit = thrustLimit;
thrustLimiterLocked = true;
isThruster = true;
break;
}
}
Expand Down Expand Up @@ -384,12 +389,16 @@ public override void InitState()
//update Role
if(engine.throttleLocked && info.Role != TCARole.MANUAL)
info.SetRole(TCARole.MANUAL);
InitLimits();
nominalFullThrust = nominalCurrentThrust(1);
// update rotation/translation flags that are used in InitLimits
rotationEnabled = info.Role != TCARole.MANEUVER
|| (info.Mode & ManeuverMode.TORQUE) == ManeuverMode.TORQUE;
translationEnabled = info.Role != TCARole.MANEUVER
|| (info.Mode & ManeuverMode.TRANSLATION) == ManeuverMode.TRANSLATION;
// update limits AND engine usage flags
InitLimits();
// update full thrust AFTER the throttleLocked flag is set in InitLimits
nominalFullThrust = nominalCurrentThrust(1);

// Utils.Log("Engine.InitState: {}\n" +
// "wThrustDir {}\n" +
// "wThrustPos {}\n" +
Expand All @@ -411,7 +420,7 @@ public override void RestoreState()

public override void UpdateCurrentTorque(float throttle)
{
this.throttle = throttle;
this.throttle = engine.throttleLocked ? 1 : throttle;
var thrust = ThrustM(throttle);
currentTorque = specificTorque * thrust;
currentTorque_m = currentTorque.magnitude;
Expand All @@ -429,9 +438,9 @@ public override void UpdateCurrentTorque(float throttle)

public override float ThrustM(float throttle)
{
return (Role != TCARole.MANUAL ?
nominalCurrentThrust(throttle) :
engine.finalThrust);
return (engine.throttleLocked ?
engine.finalThrust :
nominalCurrentThrust(throttle));
}

public Vector3 Thrust(float throttle, bool useDefDirection)
Expand Down Expand Up @@ -497,6 +506,8 @@ float GetFlowMod(float rel_density, float vel_mach)
public float ThrustAtAlt(float vel, float alt, out float mFlow)
{
mFlow = engine.maxFuelFlow;
if(thrustLimiterLocked)
mFlow *= thrustLimit;
var atm = vessel.mainBody.AtmoParamsAtAltitude(alt);
var rel_density = (float)(atm.Rho / 1.225);
var vel_mach = atm.Mach1 > 0 ? (float)(vel / atm.Mach1) : 0;
Expand All @@ -521,26 +532,29 @@ public float ThrustAtAlt(float vel, float alt, out float mFlow)

public float nominalCurrentThrust(float throttle)
{
return thrustMod * (engine.throttleLocked ?
engine.maxThrust : Mathf.Lerp(engine.minThrust, engine.maxThrust, throttle));
return thrustMod
* (engine.throttleLocked
? engine.maxThrust
: Mathf.Lerp(engine.minThrust,
engine.maxThrust,
thrustLimiterLocked ? thrustLimit : throttle));
}

public override float thrustLimit
{
get { return engine.thrustPercentage / 100f; }
set
{
if(engine.throttleLocked) return;
if(thrustLimiterLocked) return;
thrustController.Update(value * 100 - engine.thrustPercentage);
engine.thrustPercentage = Mathf.Clamp(engine.thrustPercentage + thrustController.Action, 0, 100);
}
}
public override void forceThrustPercentage(float value)
{
// here we only respect the native ModuleEngine.throttleLocked
if(!engine.throttleLocked)
engine.thrustPercentage = Mathf.Clamp(value, 0, 100);
// if(Role == TCARole.MANUAL && value.Equals(0))//debug
// Utils.Log("Manual engine was dethrottled.");
}

public override bool isOperational { get { return engine.isOperational; } }
Expand Down
8 changes: 8 additions & 0 deletions GUI/HUD/AttitudePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,13 @@ protected override void OnLateUpdate()
CFG.AT[Attitude.TargetCorrected]
);
}

#if DEBUG
protected override void OnRender()
{
base.OnRender();
ATC.DrawDebugLines();
}
#endif
}
}
4 changes: 2 additions & 2 deletions GUI/HUD/StatusPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ protected override void onGamePause()
{
base.onGamePause();
if(Controller != null)
Controller.EnableSound(false);
Controller.PauseSound(true);
}

protected override void onGameUnpause()
{
base.onGameUnpause();
if(Controller != null)
Controller.EnableSound(true);
Controller.PauseSound(false);
}

protected override void OnLateUpdate()
Expand Down
19 changes: 15 additions & 4 deletions GUI/TCAGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class TCAGui : AddonWindowBase<TCAGui>
public static DateTime StatusEndTime;

public static Blinker EnabledBlinker = new Blinker(0.5);

private static Texture2D CoM_Icon;
public bool ShowCoM;
#endregion

#pragma warning disable 169
Expand Down Expand Up @@ -103,6 +106,7 @@ public class TCAGui : AddonWindowBase<TCAGui>
public override void Awake()
{
base.Awake();
CoM_Icon = TextureCache.GetTexture(Globals.RADIATION_ICON);
AllTabFields = ControlTab.GetTabFields(GetType());
AllPanels.Add(VFlight_Panel);
AllPanels.Add(Attitude_Panel);
Expand Down Expand Up @@ -422,10 +426,17 @@ protected override void draw_gui()
draw_main_window = true;
//draw waypoints
NAV?.DrawWaypoints();
if(RemoteControl
&& Event.current.type == EventType.Repaint)
Markers.DrawWorldMarker(TCA.vessel.transform.position, Colors.Good,
"Remotely Controlled Vessel", NavigationTab.PathNodeMarker, 8);
if(Event.current.type == EventType.Repaint)
{
if(RemoteControl)
Markers.DrawWorldMarker(TCA.vessel.transform.position,
Colors.Good,
"Remotely Controlled Vessel",
NavigationTab.PathNodeMarker,
8);
if(ShowCoM)
Markers.DrawWorldMarker(TCA.vessel.CurrentCoM, Colors.Active, "Center of Mass", CoM_Icon);
}
}

public void Update()
Expand Down
3 changes: 3 additions & 0 deletions GUI/Tabs/AdvancedTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ public override void Draw()
Utils.ButtonSwitch("AutoShow", ref UI.ShowOnHover,
"Show collapsed TCA window when mouse hovers over it",
GUILayout.ExpandWidth(true));
Utils.ButtonSwitch("Show CoM", ref UI.ShowCoM,
"Show CoM of the current vessel",
GUILayout.ExpandWidth(true));
if(GUILayout.Button(new GUIContent("InfoPanel",
"Show test info message to change the position of the info panel"),
GUILayout.ExpandWidth(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,12 @@ ToOrbitExecutor
MaxDynPressure = 35 //kPa
AscentEccentricity = 0.3
AtmDensityOffset = 1
GTurnOffset = 0.014
AtmDensityCutoff = 0.01
GravityTurnAngle = 45 // deg
GTurnOffset = 0.1
MinThrustMod = 0.8
MaxThrustMod = 0.99
FirstApA = 10 // km above min ApA
PitchPID
{
P = 1
Expand All @@ -584,6 +589,13 @@ ToOrbitExecutor
D = 0
Tau = 1
}
ApAPID
{
P = 0.1
I = 0.01
D = 0
Tau = 1
}
NormCorrectionPID
{
P = 20
Expand Down Expand Up @@ -616,7 +628,6 @@ TargetedToOrbitExecutor
ToOrbitAutopilot
{
Dtol = 100 //m
RadiusOffset = 10000 //m
LaunchSlope = 30 //deg
InclinationPID
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
"VERSION":
{
"MAJOR":3,
"MINOR":7,
"PATCH":2,
"MINOR":8,
"PATCH":0,
"BUILD":0
},
"KSP_VERSION_MIN":
{
"MAJOR":1,
"MINOR":10,
"PATCH":0
"MINOR":11,
"PATCH":1
},
"KSP_VERSION_MAX":
{
"MAJOR":1,
"MINOR":10,
"PATCH":0
"MINOR":11,
"PATCH":1
}
}
16 changes: 10 additions & 6 deletions Modules/AttitudeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,16 @@ public void DrawDebugLines()
{
if(!CFG.AT || VSL == null || VSL.vessel == null || VSL.refT == null) return;
// Utils.GLVec(VSL.refT.position, VSL.OnPlanetParams.Heading.normalized*2500, Color.white);
Utils.GLVec(VSL.refT.position, VSL.WorldDir(lthrust.normalized) * 20, Color.yellow);
Utils.GLVec(VSL.refT.position, VSL.WorldDir(needed_lthrust.normalized) * 20, Color.red);
Utils.GLVec(VSL.refT.position, VSL.WorldDir(VSL.vessel.angularVelocity * 20), Color.cyan);
Utils.GLVec(VSL.refT.position, VSL.WorldDir(new Vector3(pid_pitch.atPID.Action * rotation_axis.x,
pid_roll.atPID.Action * rotation_axis.y,
pid_yaw.atPID.Action * rotation_axis.z) * 20), Color.green);
var position = VSL.refT.position;
Utils.GLVec(position, VSL.WorldDir(lthrust.normalized) * 20, Color.yellow);
Utils.GLVec(position, VSL.WorldDir(needed_lthrust.normalized) * 20, Color.red);
Utils.GLVec(position, VSL.WorldDir(VSL.vessel.angularVelocity * 20), Color.cyan);
Utils.GLVec(position,
VSL.WorldDir(new Vector3(pid_pitch.atPID.Action * rotation_axis.x,
pid_roll.atPID.Action * rotation_axis.y,
pid_yaw.atPID.Action * rotation_axis.z)
* 20),
Color.green);
// Utils.GLVec(VSL.refT.position, VSL.WorldDir(steering*20), Color.cyan);
// Utils.GLVec(VSL.refT.position, VSL.WorldDir(steering_pid.Action*20), Color.magenta);

Expand Down
Loading

0 comments on commit 137ee77

Please sign in to comment.