Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
allista committed Jul 5, 2020
2 parents a08945a + df3d208 commit ea4c28f
Show file tree
Hide file tree
Showing 24 changed files with 1,050 additions and 979 deletions.
6 changes: 3 additions & 3 deletions AssemblyInfo.cs
Expand Up @@ -28,11 +28,11 @@
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

#if NIGHTBUILD
[assembly: AssemblyVersion("3.6.*")]
[assembly: AssemblyVersion("3.7.*")]
#else
[assembly: AssemblyVersion("3.6.2.2")]
[assembly: AssemblyVersion("3.7.0")]
#endif
[assembly: KSPAssembly("ThrottleControlledAvionics", 3, 6)]
[assembly: KSPAssembly("ThrottleControlledAvionics", 3, 7)]

// 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 Down
41 changes: 40 additions & 1 deletion ChangeLog.md
Expand Up @@ -2,7 +2,46 @@

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

* **v3.6.2.2**
* **v3.7.0 - Maneuver Engines Reloaded**
* **Manual engines are no longer used for horizontal thrust**,
instead _the maneuver engines are used_.
* Added *Mode* of operation *of maneuver engines*
* Rotation & Translation -- a maneuver engine in this
(default) mode responses to both rotation and translation
controls and may be used for horizontal thrust.
* Rotation -- a maneuver engine in this mode only responses
to rotation controls and is never used for horizontal thrust.
* Translation -- a maneuver engine in this mode only responses
to translation controls and may be used for horizontal thrust.
* Fixed balancing of engine profiles that have only maneuver engines
active.
* Improved handling of R&T maneuver engines that provide more thrust
than torque (i.e. they're more or less in line with CoM).
Even if you don't set such engines to Translation mode, they won't be
firing much during rotation. Such engines are also no longer switched
to UnBalanced mode.
* Added two new settings to **Advanced Tab**:
* **Hor. Thrust** switch toggles the use of translation-capable
maneuver engines for horizontal thrust by on-planet navigation
autopilots
* **Minimum specific horizontal thrust** (which is the same as
acceleration) - this number limits the use of maneuver engines
for horizontal thrust by the acceleration they can produce. So
if your ship has maneuver thrusters for normal rotation/translation
purposes and you don't want the TCA to try to use them as
horizontal thrusters, just set this limit high enough.
* Added **support for Cargo Accelerators**:
* ModuleTCA now handles the ExecuteManeuverNode message,
which allows it to continue maneuvers that were only partially
executed by an accelerator.
* Added **support for Hangar**:
* ModuleTCA now handles onLaunchedFromHangar KSPEvent and, in case
of launching from fairings hangar, continues what the TCA of the
previous stage was doing (e.g. the To Orbit program).
* Various bug fixes, including TCA WayPoints, Landing from orbit
targeted on another vessel and more

* v3.6.2.2
* Fixed HUD panels disappearing after scene switch
* Compiled against AT_Utils 1.9.2

Expand Down
54 changes: 41 additions & 13 deletions EngineConfig.cs
Expand Up @@ -25,6 +25,7 @@ public class EngineConfig : ConfigNodeObject
[Persistent] public float Limit;
[Persistent] string role;
public TCARole Role;
[Persistent] public ManeuverMode Mode = ManeuverMode.ALL;
public bool Changed, Edit;

// bool changed; //debug
Expand Down Expand Up @@ -55,6 +56,7 @@ public void Update(EngineWrapper e, bool with_On = false)
{
Limit = e.thrustLimit;
Role = e.Role;
Mode = e.info.Mode;
if(with_On) On = e.engine.EngineIgnited;
else Changed |= On != e.engine.EngineIgnited;
}
Expand Down Expand Up @@ -85,7 +87,7 @@ public override void Save (ConfigNode node)
public void Apply(EngineWrapper e)
{
if(e == null || e.info == null) return;
e.SetRole(Role);
e.info.SetRoleAndMode(Role, Mode);
if(HighLogic.LoadedSceneIsFlight)
{
if(On && !e.engine.EngineIgnited) e.engine.Activate();
Expand All @@ -97,17 +99,26 @@ public void Apply(EngineWrapper e)

public bool DiffersFrom(EngineWrapper e)
{
return On != e.engine.EngineIgnited || Role != e.Role ||
return On != e.engine.EngineIgnited || Role != e.Role || Mode != e.info.Mode ||
(Role == TCARole.MANUAL && Mathf.Abs(e.thrustLimit-Limit) > lim_eps);
}

void RoleControl()
{
if(GUILayout.Button("<", Styles.normal_button, GUILayout.Width(15)))
{ Role = TCAEngineInfo.PrevRole(Role); Changed = true; }
GUILayout.Label(TCAEngineInfo.RoleNames[(int)Role], GUILayout.Width(120));
{ Role = TCAEngineInfo.Roles.Prev(Role); Changed = true; }
GUILayout.Label(TCAEngineInfo.Roles[Role], GUILayout.Width(130));
if(GUILayout.Button(">", Styles.normal_button, GUILayout.Width(15)))
{ Role = TCAEngineInfo.NextRole(Role); Changed = true; }
{ Role = TCAEngineInfo.Roles.Next(Role); Changed = true; }
}

void ModeControl()
{
if(GUILayout.Button("<", Styles.normal_button, GUILayout.Width(15)))
{ Mode = TCAEngineInfo.Modes.Prev(Mode); Changed = true; }
GUILayout.Label(TCAEngineInfo.Modes[Mode], GUILayout.Width(130));
if(GUILayout.Button(">", Styles.normal_button, GUILayout.Width(15)))
{ Mode = TCAEngineInfo.Modes.Next(Mode); Changed = true; }
}

void NameControl(string comment)
Expand All @@ -131,21 +142,38 @@ public bool Draw(string comment = null, bool with_role = true)
NameControl(comment);
if(GUILayout.Button(On? "On" : "Off", On? Styles.enabled_button : Styles.close_button, GUILayout.Width(30)))
{ On = !On; Changed = true; }
if(with_role) RoleControl();
if(with_role)
RoleControl();
GUILayout.EndHorizontal();
if(Role == TCARole.MANUAL)
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
switch(Role)
{
GUILayout.BeginHorizontal();
var lim = Utils.FloatSlider("", Limit, 0f, 1f, "P1", 50, "Throttle");
if(lim <= lim_eps) lim = 0;
if(Mathf.Abs(lim-Limit) > lim_eps) { Limit = lim; Changed = true; }
GUILayout.EndHorizontal();
case TCARole.MANEUVER:
GUILayout.BeginHorizontal();
GUILayout.Space(168);
ModeControl();
GUILayout.EndHorizontal();
break;
case TCARole.MANUAL:
{
GUILayout.BeginHorizontal();
var lim = Utils.FloatSlider("", Limit, 0f, 1f, "P1", 50, "Throttle");
if(lim <= lim_eps)
lim = 0;
if(Mathf.Abs(lim - Limit) > lim_eps)
{
Limit = lim;
Changed = true;
}
GUILayout.EndHorizontal();
break;
}
}
return Changed;
}

public override string ToString()
{ return string.Format("[{0}]: Role {1}, Limit {2}, On: {3}", Name, Role, Limit, On); }
{ return $"[{Name}]: Role {Role}, Mode {Mode}, Limit {Limit}, On: {On}"; }
}

public abstract class EngineConfigDB<K> : ConfigNodeObject
Expand Down
83 changes: 67 additions & 16 deletions EngineWrapper.cs
Expand Up @@ -23,13 +23,15 @@ public abstract class ThrusterWrapper
public Vector3 wThrustLever = Vector3.zero;
public float currentTorque_m;
public float torqueRatio;
public float thrustRatio;
public float limit, best_limit, limit_tmp;
public float preset_limit = -1;
public float thrustMod;
protected float zeroIsp;

public abstract Vessel vessel { get; }
public abstract Part part { get; }
public uint flightID => part.flightID;

public bool Valid(VesselWrapper VSL)
{ return part != null && vessel != null && vessel.id == VSL.vessel.id; }
Expand Down Expand Up @@ -60,14 +62,25 @@ public Vector3 Torque(float throttle)
public void ApplyPreset() { if(preset_limit >= 0) limit = best_limit = limit_tmp = preset_limit; }

public void InitTorque(VesselWrapper VSL, float ratio_factor)
{ InitTorque(VSL.refT, VSL.Physics.wCoM, ratio_factor); }
{ InitTorque(VSL.refT, VSL.Physics.wCoM, VSL.Physics.M, VSL.Physics.MoI, ratio_factor); }

public virtual void InitTorque(Transform vesselTransform, Vector3 CoM, float ratio_factor)
public virtual void InitTorque(Transform vesselTransform, Vector3 CoM, float mass, Vector3 MoI, float ratio_factor)
{
wThrustLever = wThrustPos - CoM;
thrustDirection = vesselTransform.InverseTransformDirection(wThrustDir);
specificTorque = vesselTransform.InverseTransformDirection(Vector3.Cross(wThrustLever, wThrustDir));
torqueRatio = Mathf.Pow(Mathf.Clamp01(1 - Mathf.Abs(Vector3.Dot(wThrustLever.normalized, wThrustDir))), ratio_factor);
torqueRatio = computeTorqueRatio(wThrustLever, wThrustDir, specificTorque, mass, MoI, ratio_factor, out thrustRatio);
}

protected static float computeTorqueRatio(Vector3 lever, Vector3 thrustDir, Vector3 specTorque, float mass, Vector3 MoI, float ratio_factor, out float specificThrustToCom)
{
specificThrustToCom = Vector3.Dot(lever.normalized, thrustDir);
var specificLinearAccel = Mathf.Abs(specificThrustToCom / mass);
var specificAngularAccel = TorqueProps.AngularAcceleration(specTorque, MoI).magnitude;
var ratio = specificLinearAccel > 0
? Mathf.Clamp01(1 - 1 / (1 + specificAngularAccel * ratio_factor / specificLinearAccel))
: 0;
return ratio;
}
}

Expand Down Expand Up @@ -151,6 +164,23 @@ public override void forceThrustPercentage(float value)

public override bool isOperational
{ get { return rcs.rcsEnabled && rcs.thrusterTransforms.Count > 0 && rcs.thrusterTransforms.Count == rcs.thrustForces.Length; } }

public override string ToString()
{
return Utils.Format("[{}, Stage {}, flameout {}]\n" +
"finalThrust: {}, thrustLimit: {}, isOperational: {}\n" +
"limit: {}, best_limit: {}, limit_tmp: {}, preset: {}\n" +
"thrust: {}\ndir {}\npos {}\nlever: {}\ntorque: {}\n"
+ "torqueRatio: {}\n"
+ "thrustRatio: {}\n",
part.GetID(), part.inverseStage, rcs.flameout,
finalThrust, thrustLimit, isOperational,
limit, best_limit, limit_tmp, preset_limit,
current_max_thrust,
wThrustDir, wThrustPos, wThrustLever,
currentTorque, torqueRatio,
thrustRatio);
}
}

public class EngineID
Expand Down Expand Up @@ -184,16 +214,18 @@ public class EngineWrapper : ThrusterWrapper
public string name { get; private set; }

public uint ID { get; private set; }
public uint flightID { get { return part.flightID; } }

public float throttle;
public float realIsp;
public float flowMod;
public float VSF; //vertical speed factor
public bool isVSC; //vertical speed controller
public bool isSteering;
public TCARole Role { get { return info.Role; } }
public int Group { get { return info.Group; } }
public TCARole Role => info.Role;
public int Group => info.group;

public bool rotationEnabled = true;
public bool translationEnabled = true;

Vector3 act_thrust_dir;
Vector3 act_thrust_pos;
Expand All @@ -206,6 +238,7 @@ public class EngineWrapper : ThrusterWrapper
public Vector3 defCurrentTorque { get; private set; }
public float defCurrentTorque_m { get; private set; }
public float defTorqueRatio { get; private set; }
public float defThrustRatio;

public float nominalFullThrust { get; private set; }

Expand Down Expand Up @@ -264,23 +297,34 @@ public EngineWrapper(ModuleEngines engine)
}

#region methods
public void SetRole(TCARole role) { info.SetRole(role); }
public void SetGroup(int group) { info.group = group; }

public override void InitTorque(Transform vesselTransform, Vector3 CoM, float ratio_factor)
public override void InitTorque(
Transform vesselTransform,
Vector3 CoM,
float mass,
Vector3 MoI,
float ratio_factor
)
{
base.InitTorque(vesselTransform, CoM, ratio_factor);
base.InitTorque(vesselTransform, CoM, mass, MoI, ratio_factor);
if(gimbal != null)
{
defThrustDirL = vesselTransform.InverseTransformDirection(defThrustDir);
defSpecificTorque = vesselTransform.InverseTransformDirection(Vector3.Cross(wThrustLever, defThrustDir));
defTorqueRatio = Mathf.Pow(Mathf.Clamp01(1 - Mathf.Abs(Vector3.Dot(wThrustLever.normalized, defThrustDir))), ratio_factor);
defSpecificTorque =
vesselTransform.InverseTransformDirection(Vector3.Cross(wThrustLever, defThrustDir));
defTorqueRatio = computeTorqueRatio(wThrustLever,
defThrustDir,
defSpecificTorque,
mass,
MoI,
ratio_factor,
out defThrustRatio);
}
else
{
defThrustDirL = thrustDirection;
defSpecificTorque = specificTorque;
defTorqueRatio = torqueRatio;
defThrustRatio = thrustRatio;
}
}

Expand All @@ -298,7 +342,7 @@ public override void InitLimits()
break;
case TCARole.MANEUVER:
limit = best_limit = 0f;
isSteering = true;
isSteering = rotationEnabled;
break;
case TCARole.MANUAL:
limit = best_limit = thrustLimit;
Expand Down Expand Up @@ -342,6 +386,10 @@ public override void InitState()
info.SetRole(TCARole.MANUAL);
InitLimits();
nominalFullThrust = nominalCurrentThrust(1);
rotationEnabled = info.Role != TCARole.MANEUVER
|| (info.Mode & ManeuverMode.TORQUE) == ManeuverMode.TORQUE;
translationEnabled = info.Role != TCARole.MANEUVER
|| (info.Mode & ManeuverMode.TRANSLATION) == ManeuverMode.TRANSLATION;
// Utils.Log("Engine.InitState: {}\n" +
// "wThrustDir {}\n" +
// "wThrustPos {}\n" +
Expand Down Expand Up @@ -504,14 +552,17 @@ public override string ToString()
"useEngineResponseTime: {}, engineAccelerationSpeed={}, engineDecelerationSpeed={}\n" +
"finalThrust: {}, thrustLimit: {}, isOperational: {}\n" +
"limit: {}, best_limit: {}, limit_tmp: {}, preset: {}\n" +
"thrust: {}\ndir {}\ndef dir: {}\npos {}\nlever: {}\ntorque: {}\ntorqueRatio: {}\n",
"thrust: {}\ndir {}\ndef dir: {}\npos {}\nlever: {}\ntorque: {}\n"
+ "torqueRatio: {} defTorqueRatio: {}\n"
+ "thrustRatio: {} defThrustRatio: {}\n",
name, ID, flightID, part.inverseStage, Role, isVSC, Group, engine.flameout,
useEngineResponseTime, engineAccelerationSpeed, engineDecelerationSpeed,
finalThrust, thrustLimit, isOperational,
limit, best_limit, limit_tmp, preset_limit,
nominalFullThrust,
wThrustDir, defThrustDir, wThrustPos, wThrustLever,
currentTorque, torqueRatio
currentTorque, torqueRatio, defTorqueRatio,
thrustRatio, defThrustRatio
);
}
}
Expand Down

0 comments on commit ea4c28f

Please sign in to comment.