Skip to content

Commit 512ae9b

Browse files
committed
1.1 bugfixes
1 parent ed35ee7 commit 512ae9b

File tree

7 files changed

+59
-14
lines changed

7 files changed

+59
-14
lines changed
512 Bytes
Binary file not shown.

MandatoryRCS-Source/DebugInfo.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using UnityEngine;
6+
7+
namespace MandatoryRCS
8+
{
9+
class DebugInfo : PartModule
10+
{
11+
VesselModuleRotation vm;
12+
ModuleTorqueController tc;
13+
ModuleReactionWheel rw;
14+
15+
[KSPField(guiActive = true, guiName = "Ang. Velocity", guiFormat = "00.00")]
16+
public float angularVelocity;
17+
18+
[KSPField(guiActive = true, guiName = "rollTorque", guiFormat = "00.00")]
19+
public float rollTorque;
20+
21+
[KSPField(guiActive = true, guiName = "pitchTorque", guiFormat = "00.00")]
22+
public float pitchTorque;
23+
24+
[KSPField(guiActive = true, guiName = "yawTorque", guiFormat = "00.00")]
25+
public float yawTorque;
26+
27+
public void FixedUpdate()
28+
{
29+
if (!(HighLogic.LoadedSceneIsFlight && FlightGlobals.ready))
30+
{
31+
return;
32+
}
33+
34+
vm = vessel.vesselModules.OfType<VesselModuleRotation>().First();
35+
tc = part.Modules.GetModule<ModuleTorqueController>();
36+
rw = part.Modules.GetModule<ModuleReactionWheel>();
37+
38+
angularVelocity = vessel.angularVelocity.magnitude;
39+
rollTorque = rw.RollTorque;
40+
pitchTorque = rw.PitchTorque;
41+
yawTorque = rw.YawTorque;
42+
43+
}
44+
}
45+
}

MandatoryRCS-Source/MandatoryRCS.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
</Reference>
4848
</ItemGroup>
4949
<ItemGroup>
50+
<Compile Include="DebugInfo.cs" />
5051
<Compile Include="ModuleTorqueController.cs" />
5152
<Compile Include="Properties\AssemblyInfo.cs" />
5253
<Compile Include="MandatoryRCSEvents.cs" />

MandatoryRCS-Source/ModuleTorqueController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void Start()
7474

7575
public void FixedUpdate()
7676
{
77-
if (!(HighLogic.LoadedSceneIsFlight && FlightGlobals.ready))
77+
if (!(HighLogic.LoadedSceneIsFlight && FlightGlobals.ready && this.vessel.loaded && !this.vessel.packed))
7878
{
7979
return;
8080
}
@@ -108,7 +108,7 @@ public void FixedUpdate()
108108
physicsTorqueFactor = vessel.vesselModules.OfType<VesselModuleRotation>().First().wheelsPhysicsTorqueFactor;
109109
rwmodule.enabled = true;
110110
rwmodule.isEnabled = true;
111-
rwmodule.RollTorque = maxRollTorque * torqueFactor; //To prevent SAS overshooting and perpetual rolling, do not apply angular velocity nerf to roll
111+
rwmodule.RollTorque = maxRollTorque * torqueFactor * physicsTorqueFactor;
112112
rwmodule.PitchTorque = maxPitchTorque * torqueFactor * physicsTorqueFactor;
113113
rwmodule.YawTorque = maxYawTorque * torqueFactor * physicsTorqueFactor;
114114
}
@@ -119,7 +119,7 @@ public void FixedUpdate()
119119
physicsTorqueFactor = vessel.vesselModules.OfType<VesselModuleRotation>().First().wheelsPhysicsTorqueFactor;
120120
rwmodule.enabled = true;
121121
rwmodule.isEnabled = true;
122-
rwmodule.RollTorque = maxRollTorque; //To prevent SAS overshooting and perpetual rolling, do not apply angular velocity nerf to roll
122+
rwmodule.RollTorque = maxRollTorque * physicsTorqueFactor;
123123
rwmodule.PitchTorque = maxPitchTorque * physicsTorqueFactor;
124124
rwmodule.YawTorque = maxYawTorque * physicsTorqueFactor;
125125
}

MandatoryRCS-Source/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("1.1.0.0")]
36+
[assembly: AssemblyFileVersion("1.1.0.0")]

MandatoryRCS-Source/VesselModuleRotation.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace MandatoryRCS
1919
public class VesselModuleRotation : VesselModule
2020
{
2121
private const float lowVelocityThreesold = 0.025f;
22+
private const float wheelsMinAngularVelocity = 0.1f; // The angular velocity after witch wheels will begin too loose torque
2223
private const float wheelsMaxAngularVelocity = 0.785f; // Max angular velocity reaction wheels can fight against (rad/s), 0.785 = 45°/sec
2324
private const float wheelsMinTorqueFactor = 0.05f; // Reaction wheels torque output at max angular velocity (%)
2425

@@ -78,7 +79,7 @@ private void FixedUpdate()
7879
if (Vessel.packed)
7980
{
8081
// Check if target / maneuver is modified/deleted during timewarp
81-
if (TimeWarp.WarpMode == TimeWarp.Modes.HIGH && TimeWarp.CurrentRateIndex > 0)
82+
if (autopilotTargetHold && TimeWarp.WarpMode == TimeWarp.Modes.HIGH && TimeWarp.CurrentRateIndex > 0)
8283
{
8384
autopilotTargetHold = TargetHoldValidity();
8485
}
@@ -200,7 +201,7 @@ private void RotateTowardTarget()
200201
return;
201202
}
202203

203-
Vessel.SetRotation(Quaternion.FromToRotation(Vessel.GetTransform().up, AutopilotTargetDirection()) * Vessel.transform.rotation, true);
204+
Vessel.SetRotation(Quaternion.FromToRotation(Vessel.GetTransform().up, AutopilotTargetDirection()) * Vessel.transform.rotation, false); // false seems to fix the "infinite roll bug"
204205
}
205206

206207
private void RotatePacked()
@@ -210,7 +211,7 @@ private void RotatePacked()
210211
return;
211212
}
212213

213-
Vessel.SetRotation(Quaternion.AngleAxis(angularVelocity.magnitude * TimeWarp.CurrentRate, Vessel.ReferenceTransform.rotation * angularVelocity) * Vessel.transform.rotation, true);
214+
Vessel.SetRotation(Quaternion.AngleAxis(angularVelocity.magnitude * TimeWarp.CurrentRate, Vessel.ReferenceTransform.rotation * angularVelocity) * Vessel.transform.rotation, false); // false seems to fix the "infinite roll bug"
214215
}
215216

216217
private bool RestoreSASMode(int mode)
@@ -249,7 +250,7 @@ private void SaveOffRailsStatus()
249250
}
250251

251252
// Determine the wheelsPhysicsTorqueFactor
252-
wheelsPhysicsTorqueFactor = Math.Max(1.0f - Math.Min((angularVelocity.magnitude * wheelsMaxAngularVelocity), 1.0f), wheelsMinTorqueFactor);
253+
wheelsPhysicsTorqueFactor = Math.Max(1.0f - Math.Min((Math.Max(angularVelocity.magnitude - wheelsMinAngularVelocity, 0.0f) * wheelsMaxAngularVelocity), 1.0f), wheelsMinTorqueFactor);
253254

254255
// Checking if the autopilot hold mode should be enabled
255256
if (Vessel.Autopilot.Enabled

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,19 @@ So public domain, feel free to do anything, especially updating this plugin if I
5757
## Changelog and bugs
5858

5959
#### Known bugs and glitches
60-
- The reaction wheels nerf cause the SAS to overshoot when trying to stabilize roll. This is problematic for large vessels and may cause them to roll back and forth forever, I'm working on this.
60+
- The reaction wheels nerf cause the SAS to overshoot when trying to stabilize roll. This is problematic for large vessels and may cause them to roll back and forth forever. Should be a lot better if not fixed in 1.1
6161
- When switching to an unloaded vessel with its SAS in "target", "antitarget" or "maneuver" mode, the orientation change is applied a few frames after the vessel is unpacked, leading to the rotation event being visible to the player. Won't fix as this is minor, purely cosmetic and fixing would require massive modifications.
6262

6363
#### v1.1 for KSP 1.2.2
64-
- (bugfix) Removed reaction wheels roll torque being nerfed by angular velocity to prevent SAS perpetual overshooting.
64+
- (bugfix) Fixed SAS orientation being applied when not reached on initiating timewarp (woops)
65+
- (bugfix) Tweaked a few things to prevent the perpetual SAS roll overshoot.
6566

6667
#### v1.0 for KSP 1.2.2
6768
- (feature) The torque output from reaction wheels is now affected by the vessel angular velocity : the torque output decrease when the angular velocity increase, down to a minimum of 5% when the angular velocity reach 45° / second.
6869
- (bugfix) Fixed reaction wheels providing a bit of torque when switching SAS from stability assist mode to a target hold mode after loading a vessel (fixed by forcing module desactivation every fixedupdate)
6970
- (bugfix) Fixed SAS overshooting its target when using RCS (Fixed by explicitly setting reaction wheels torque to 0 when the module is disabled)
7071
- (bugfix) Irrelevant reaction wheels action groups options are now hidden
7172

72-
#### v1.0-pre1 for KSP 1.2.2
73-
First test build
74-
7573
#### Perhaps planned features
7674

7775
- Ingame settings in the difficulty options menu

0 commit comments

Comments
 (0)