Skip to content

Commit

Permalink
ComputerModule breaking API changes
Browse files Browse the repository at this point in the history
Cleanup the API.  Like other PRs similar to this the name changes
are intended to be breaking changes, the visibility changes can be
reversed and aren't intended to force people to use reflection to
call private APIs (please don't) and can be switched back to public.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Jun 19, 2023
1 parent 1bcbef0 commit 00891f8
Show file tree
Hide file tree
Showing 80 changed files with 2,438 additions and 2,443 deletions.
12 changes: 6 additions & 6 deletions MechJeb2/AttitudeControllers/BaseAttitudeController.cs
Expand Up @@ -24,16 +24,16 @@ public virtual void OnStart()
public virtual void OnLoad(ConfigNode local, ConfigNode type, ConfigNode global)
{
if (global != null && global.HasNode(GetType().Name))
ConfigNode.LoadObjectFromConfig(this, global.GetNode(GetType().Name), (int)Pass.Global);
if (type != null && type.HasNode(GetType().Name)) ConfigNode.LoadObjectFromConfig(this, type.GetNode(GetType().Name), (int)Pass.Type);
if (local != null && local.HasNode(GetType().Name)) ConfigNode.LoadObjectFromConfig(this, local.GetNode(GetType().Name), (int)Pass.Local);
ConfigNode.LoadObjectFromConfig(this, global.GetNode(GetType().Name), (int)Pass.GLOBAL);
if (type != null && type.HasNode(GetType().Name)) ConfigNode.LoadObjectFromConfig(this, type.GetNode(GetType().Name), (int)Pass.TYPE);
if (local != null && local.HasNode(GetType().Name)) ConfigNode.LoadObjectFromConfig(this, local.GetNode(GetType().Name), (int)Pass.LOCAL);
}

public virtual void OnSave(ConfigNode local, ConfigNode type, ConfigNode global)
{
if (global != null) ConfigNode.CreateConfigFromObject(this, (int)Pass.Global, null).CopyTo(global.AddNode(GetType().Name));
if (type != null) ConfigNode.CreateConfigFromObject(this, (int)Pass.Type, null).CopyTo(type.AddNode(GetType().Name));
if (local != null) ConfigNode.CreateConfigFromObject(this, (int)Pass.Local, null).CopyTo(local.AddNode(GetType().Name));
if (global != null) ConfigNode.CreateConfigFromObject(this, (int)Pass.GLOBAL, null).CopyTo(global.AddNode(GetType().Name));
if (type != null) ConfigNode.CreateConfigFromObject(this, (int)Pass.TYPE, null).CopyTo(type.AddNode(GetType().Name));
if (local != null) ConfigNode.CreateConfigFromObject(this, (int)Pass.LOCAL, null).CopyTo(local.AddNode(GetType().Name));
}

public virtual void ResetConfig()
Expand Down
46 changes: 23 additions & 23 deletions MechJeb2/AttitudeControllers/BetterController.cs
Expand Up @@ -8,67 +8,67 @@ namespace MuMech.AttitudeControllers
internal class BetterController : BaseAttitudeController
{
private static readonly Vector3d _vector3dnan = new Vector3d(double.NaN, double.NaN, double.NaN);
private Vessel Vessel => ac.vessel;
private Vessel Vessel => ac.Vessel;

/* FIXME: when you do that look at ModuleGimbal gimbalResponseSpeed and model the time delay and use the XLR11 since it has slow gimbal */
[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble PosKp = new EditableDouble(1.98);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble PosDeadband = new EditableDouble(0.002);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelKp = new EditableDouble(10);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelKi = new EditableDouble(20);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelKd = new EditableDouble(0.425);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelN = new EditableDouble(84.1994541201249);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelB = new EditableDouble(0.994);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelC = new EditableDouble(0.0185);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelDeadband = new EditableDouble(0.0001);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private bool VelClegg;

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelSmoothIn = new EditableDouble(1);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelSmoothOut = new EditableDouble(1);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble PosSmoothIn = new EditableDouble(1);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble maxStoppingTime = new EditableDouble(2.0);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble minFlipTime = new EditableDouble(120);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble rollControlRange = new EditableDouble(5);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private bool useControlRange = true;

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private bool useFlipTime = true;

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private bool useStoppingTime = true;

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private int _version = -1;

private void Defaults()
Expand Down Expand Up @@ -188,7 +188,7 @@ private void UpdatePredictionPI()
Vector3d controlTorque = ac.torque;

// needed to stop wiggling at higher phys warp
double warpFactor = ac.vesselState.deltaT / 0.02;
double warpFactor = ac.VesselState.deltaT / 0.02;

// see https://archive.is/NqoUm and the "Alt Hold Controller", the acceleration PID is not implemented so we only
// have the first two PIDs in the cascade.
Expand Down Expand Up @@ -243,7 +243,7 @@ private void UpdatePredictionPI()
_pid[i].N = VelN;
_pid[i].B = VelB;
_pid[i].C = VelC;
_pid[i].Ts = ac.vesselState.deltaT;
_pid[i].Ts = ac.VesselState.deltaT;
_pid[i].SmoothIn = MuUtils.Clamp01(VelSmoothIn);
_pid[i].SmoothOut = MuUtils.Clamp01(VelSmoothOut);
_pid[i].MinOutput = -1;
Expand Down
20 changes: 10 additions & 10 deletions MechJeb2/AttitudeControllers/HybridController.cs
Expand Up @@ -6,13 +6,13 @@ namespace MuMech.AttitudeControllers
{
internal class HybridController : BaseAttitudeController
{
[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
private readonly EditableDouble maxStoppingTime = new EditableDouble(2);

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
private readonly EditableDoubleMult rollControlRange = new EditableDoubleMult(5 * Mathf.Deg2Rad, Mathf.Deg2Rad);

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
private bool useControlRange = true;

public TorquePI pitchPI = new TorquePI();
Expand All @@ -23,7 +23,7 @@ internal class HybridController : BaseAttitudeController
public KosPIDLoop yawRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);
public KosPIDLoop rollRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public bool useInertia = true;

private Vector3d Actuation = Vector3d.zero;
Expand Down Expand Up @@ -59,7 +59,7 @@ public override void DrivePre(FlightCtrlState s, out Vector3d act, out Vector3d

public void UpdatePhi()
{
Transform vesselTransform = ac.vessel.ReferenceTransform;
Transform vesselTransform = ac.Vessel.ReferenceTransform;

// 1. The Euler(-90) here is because the unity transform puts "up" as the pointy end, which is wrong. The rotation means that
// "forward" becomes the pointy end, and "up" and "right" correctly define e.g. AoA/pitch and AoS/yaw. This is just KSP being KSP.
Expand Down Expand Up @@ -97,13 +97,13 @@ public void UpdatePhi()

private void UpdatePredictionPI()
{
Omega = -ac.vessel.angularVelocity;
Omega = -ac.Vessel.angularVelocity;

UpdatePhi();

for (int i = 0; i < 3; i++)
{
MaxOmega[i] = ControlTorque[i] * maxStoppingTime / ac.vesselState.MoI[i];
MaxOmega[i] = ControlTorque[i] * maxStoppingTime / ac.VesselState.MoI[i];
}

TargetOmega[0] = pitchRatePI.Update(phiVector[0], 0, MaxOmega[0]);
Expand All @@ -116,9 +116,9 @@ private void UpdatePredictionPI()
rollRatePI.ResetI();
}

TargetTorque[0] = pitchPI.Update(Omega[0], TargetOmega[0], ac.vesselState.MoI[0], ControlTorque[0]);
TargetTorque[1] = rollPI.Update(Omega[1], TargetOmega[1], ac.vesselState.MoI[1], ControlTorque[1]);
TargetTorque[2] = yawPI.Update(Omega[2], TargetOmega[2], ac.vesselState.MoI[2], ControlTorque[2]);
TargetTorque[0] = pitchPI.Update(Omega[0], TargetOmega[0], ac.VesselState.MoI[0], ControlTorque[0]);
TargetTorque[1] = rollPI.Update(Omega[1], TargetOmega[1], ac.VesselState.MoI[1], ControlTorque[1]);
TargetTorque[2] = yawPI.Update(Omega[2], TargetOmega[2], ac.VesselState.MoI[2], ControlTorque[2]);
}

public override void Reset()
Expand Down
16 changes: 8 additions & 8 deletions MechJeb2/AttitudeControllers/KosAttitudeController.cs
Expand Up @@ -5,10 +5,10 @@ namespace MuMech.AttitudeControllers
{
internal class KosAttitudeController : BaseAttitudeController
{
[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
private readonly EditableDouble maxStoppingTime = new EditableDouble(2);

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
private readonly EditableDoubleMult rollControlRange = new EditableDoubleMult(5 * Mathf.Deg2Rad, Mathf.Deg2Rad);
//public double RollControlRange {
// get { return this.rollControlRange; }
Expand Down Expand Up @@ -67,7 +67,7 @@ public override void DrivePre(FlightCtrlState s, out Vector3d act, out Vector3d
private void UpdateStateVectors()
{
/* FIXME: may get called more than once per tick */
vesselRotation = ac.vessel.ReferenceTransform.rotation * Quaternion.Euler(-90, 0, 0);
vesselRotation = ac.Vessel.ReferenceTransform.rotation * Quaternion.Euler(-90, 0, 0);
vesselForward = vesselRotation * Vector3d.forward;
vesselTop = vesselRotation * Vector3d.up;
vesselStarboard = vesselRotation * Vector3d.right;
Expand All @@ -76,7 +76,7 @@ private void UpdateStateVectors()
targetTop = ac.RequestedAttitude * Vector3d.up;
/* targetStarboard = target * Vector3d.right; */

Omega = -ac.vessel.angularVelocity;
Omega = -ac.Vessel.angularVelocity;
}

public double PhiTotal()
Expand Down Expand Up @@ -115,7 +115,7 @@ private void UpdatePredictionPI()

for (int i = 0; i < 3; i++)
{
MaxOmega[i] = ControlTorque[i] * maxStoppingTime / ac.vesselState.MoI[i];
MaxOmega[i] = ControlTorque[i] * maxStoppingTime / ac.VesselState.MoI[i];
}

TargetOmega[0] = pitchRatePI.Update(-phiVector[0], 0, MaxOmega[0]);
Expand All @@ -128,9 +128,9 @@ private void UpdatePredictionPI()
rollRatePI.ResetI();
}

TargetTorque[0] = pitchPI.Update(Omega[0], TargetOmega[0], ac.vesselState.MoI[0], ControlTorque[0]);
TargetTorque[1] = rollPI.Update(Omega[1], TargetOmega[1], ac.vesselState.MoI[1], ControlTorque[1]);
TargetTorque[2] = yawPI.Update(Omega[2], TargetOmega[2], ac.vesselState.MoI[2], ControlTorque[2]);
TargetTorque[0] = pitchPI.Update(Omega[0], TargetOmega[0], ac.VesselState.MoI[0], ControlTorque[0]);
TargetTorque[1] = rollPI.Update(Omega[1], TargetOmega[1], ac.VesselState.MoI[1], ControlTorque[1]);
TargetTorque[2] = yawPI.Update(Omega[2], TargetOmega[2], ac.VesselState.MoI[2], ControlTorque[2]);
}

public override void Reset()
Expand Down
34 changes: 17 additions & 17 deletions MechJeb2/AttitudeControllers/MJAttitudeController.cs
Expand Up @@ -12,37 +12,37 @@ internal class MJAttitudeController : BaseAttitudeController
public Vector3d pidAction; //info
public Vector3d error; //info

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public bool Tf_autoTune = true;

public Vector3d TfV = new Vector3d(0.3, 0.3, 0.3);

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
private Vector3 TfVec = new Vector3(0.3f, 0.3f, 0.3f); // use the serialize since Vector3d does not

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public double TfMin = 0.1;

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public double TfMax = 0.5;

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public bool lowPassFilter = true;

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public double kpFactor = 3;

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public double kiFactor = 6;

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public double kdFactor = 0.5;

[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public double deadband = 0.0001;

//Lower value of "kWlimit" reduces maximum angular velocity
[Persistent(pass = (int)Pass.Global)]
[Persistent(pass = (int)Pass.GLOBAL)]
public EditableDouble kWlimit = 0.15;

private readonly Vector3d defaultTfV = new Vector3d(0.3, 0.3, 0.3);
Expand Down Expand Up @@ -110,14 +110,14 @@ public void setPIDParameters()
public void tuneTf(Vector3d torque)
{
var ratio = new Vector3d(
torque.x != 0 ? ac.vesselState.MoI.x / torque.x : 0,
torque.y != 0 ? ac.vesselState.MoI.y / torque.y : 0,
torque.z != 0 ? ac.vesselState.MoI.z / torque.z : 0
torque.x != 0 ? ac.VesselState.MoI.x / torque.x : 0,
torque.y != 0 ? ac.VesselState.MoI.y / torque.y : 0,
torque.z != 0 ? ac.VesselState.MoI.z / torque.z : 0
);

TfV = 0.05 * ratio;

Vector3d delayFactor = Vector3d.one + 2 * ac.vesselState.torqueReactionSpeed;
Vector3d delayFactor = Vector3d.one + 2 * ac.VesselState.torqueReactionSpeed;


TfV.Scale(delayFactor);
Expand Down Expand Up @@ -149,7 +149,7 @@ public override void Reset()

public override void DrivePre(FlightCtrlState s, out Vector3d act, out Vector3d deltaEuler)
{
Transform vesselTransform = ac.vessel.ReferenceTransform;
Transform vesselTransform = ac.Vessel.ReferenceTransform;

// Find out the real shorter way to turn where we wan to.
// Thanks to HoneyFox
Expand Down Expand Up @@ -184,12 +184,12 @@ public override void DrivePre(FlightCtrlState s, out Vector3d act, out Vector3d
Math.Max(-Math.PI, Math.Min(Math.PI, err.z)));

// ( MoI / available torque ) factor:
var NormFactor = Vector3d.Scale(ac.vesselState.MoI, ac.torque.InvertNoNaN());
var NormFactor = Vector3d.Scale(ac.VesselState.MoI, ac.torque.InvertNoNaN());

err.Scale(NormFactor);

// angular velocity:
Vector3d omega = ac.vessel.angularVelocity;
Vector3d omega = ac.Vessel.angularVelocity;
//omega.x = vessel.angularVelocity.x;
//omega.y = vessel.angularVelocity.z; // y <=> z
//omega.z = vessel.angularVelocity.y; // z <=> y
Expand Down

0 comments on commit 00891f8

Please sign in to comment.