Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
Fix -ve torque, nullref
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Apr 4, 2015
1 parent 5322c78 commit a9d0eb4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
2 changes: 2 additions & 0 deletions GameData/RW Saturatable/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Plugin is licensed under GPL v3
Credit for the basic idea goes to KSP forum user alecdacyczyn
Binary file modified GameData/RW Saturatable/SaturatableRW.dll
Binary file not shown.
Binary file added RW SAturatable v1.5.zip
Binary file not shown.
Binary file removed RWSaturatable v1.4.zip
Binary file not shown.
22 changes: 8 additions & 14 deletions SaturatableRW/RWSaturatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public override void OnAwake()

public void OnDestroy()
{
Window.Instance.wheelsToDraw.Remove(this);
if (HighLogic.LoadedSceneIsFlight && Window.Instance != null)
Window.Instance.wheelsToDraw.Remove(this);
}

public override void OnStart(StartState state)
Expand All @@ -129,17 +130,9 @@ public override void OnStart(StartState state)
averageTorque = (this.PitchTorque + this.YawTorque + this.RollTorque) / 3;
saturationLimit = averageTorque * saturationScale;

// debug check
print("0% saturation: " + torqueCurve.Evaluate(pctSaturation(0f, 1)));
print("25% saturation: " + torqueCurve.Evaluate(pctSaturation(0.25f, 1)));
print("50% saturation: " + torqueCurve.Evaluate(pctSaturation(0.5f, 1)));
print("75% saturation: " + torqueCurve.Evaluate(pctSaturation(0.75f, 1)));
print("100% saturation: " + torqueCurve.Evaluate(pctSaturation(1f, 1)));

LoadConfig();
////////////////////////////////////////////////////////////////////////////
/// logging worker /////////////////////////////////////////////////////////
LoadConfig();

if (config.GetValue("LogDump", false))
StartCoroutine(loggingRoutine());
if (!config.GetValue("DefaultStateIsActive", true))
Expand All @@ -149,8 +142,9 @@ public override void OnStart(StartState state)
config["LogDump"] = config.GetValue("LogDump", false);
config["DefaultStateIsActive"] = config.GetValue("DefaultStateIsActive", true);
config.save();

StartCoroutine(registerWheel());
}
StartCoroutine(registerWheel());
}

IEnumerator registerWheel()
Expand Down Expand Up @@ -241,15 +235,15 @@ private void updateTorque()
// this.{*}Torque = actual control value

// Roll
availableRollTorque = calcAvailableTorque(this.vessel.transform.up, maxRollTorque);
availableRollTorque = Math.Abs(calcAvailableTorque(this.vessel.transform.up, maxRollTorque));
this.RollTorque = availableRollTorque;

// Pitch
availablePitchTorque = calcAvailableTorque(this.vessel.transform.right, maxPitchTorque);
availablePitchTorque = Math.Abs(calcAvailableTorque(this.vessel.transform.right, maxPitchTorque));
this.PitchTorque = availablePitchTorque;

// Yaw
availableYawTorque = calcAvailableTorque(this.vessel.transform.forward, maxYawTorque);
availableYawTorque = Math.Abs(calcAvailableTorque(this.vessel.transform.forward, maxYawTorque));
this.YawTorque = availableYawTorque;
}

Expand Down
3 changes: 1 addition & 2 deletions SaturatableRW/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static Window Instance

void Start()
{
instance = this;
InitWindow();
}

Expand Down Expand Up @@ -81,7 +80,7 @@ void drawWheel(RWSaturatable rw)
bool state = GUILayout.Toggle(rw.State == ModuleReactionWheel.WheelState.Active ? true : false, "Toggle Torque");
rw.State = state ? ModuleReactionWheel.WheelState.Active : ModuleReactionWheel.WheelState.Disabled;

GUILayout.Label("\t\tAxis\t\tAvailable\t\tMax");
GUILayout.Label("\t\t<b>Axis</b>\t\t<b>Available</b>\t\t<b>Max</b>");
GUILayout.Label(string.Format("\t\t{0}\t\t{1:0.0}kN\t\t\t{2:0.0}kN", "Pitch", rw.availablePitchTorque, rw.maxPitchTorque));
GUILayout.Label(string.Format("\t\t{0}\t\t{1:0.0}kN\t\t\t{2:0.0}kN", "Yaw", rw.availableYawTorque, rw.maxYawTorque));
GUILayout.Label(string.Format("\t\t{0}\t\t{1:0.0}kN\t\t\t{2:0.0}kN", "Roll", rw.availableRollTorque, rw.maxRollTorque));
Expand Down

0 comments on commit a9d0eb4

Please sign in to comment.