Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ dotnet_naming_symbols.constants_symbols.required_modifiers = const
dotnet_naming_symbols.constants_symbols.resharper_applicable_kinds = constant_field
dotnet_naming_symbols.constants_symbols.resharper_required_modifiers = any
dotnet_naming_symbols.enum_member_symbols.applicable_accessibilities = *
dotnet_naming_symbols.enum_member_symbols.applicable_kinds =
dotnet_naming_symbols.enum_member_symbols.applicable_kinds =
dotnet_naming_symbols.enum_member_symbols.resharper_applicable_kinds = enum_member
dotnet_naming_symbols.enum_member_symbols.resharper_required_modifiers = any
dotnet_naming_symbols.local_constants_symbols.applicable_accessibilities = *
Expand Down Expand Up @@ -235,23 +235,23 @@ dotnet_naming_symbols.static_readonly_symbols.required_modifiers = readonly, sta
dotnet_naming_symbols.static_readonly_symbols.resharper_applicable_kinds = readonly_field
dotnet_naming_symbols.static_readonly_symbols.resharper_required_modifiers = static
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_accessibilities = *
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds = unity_serialised_field
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers = instance
dotnet_naming_symbols.unity_serialized_field_symbols_2.applicable_accessibilities = *
dotnet_naming_symbols.unity_serialized_field_symbols_2.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols_2.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols_2.resharper_applicable_kinds = unity_serialised_field
dotnet_naming_symbols.unity_serialized_field_symbols_2.resharper_required_modifiers = instance
dotnet_naming_symbols.unity_serialized_field_symbols_3.applicable_accessibilities = *
dotnet_naming_symbols.unity_serialized_field_symbols_3.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols_3.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols_3.resharper_applicable_kinds = unity_serialised_field
dotnet_naming_symbols.unity_serialized_field_symbols_3.resharper_required_modifiers = instance
dotnet_naming_symbols.unity_serialized_field_symbols_4.applicable_accessibilities = *
dotnet_naming_symbols.unity_serialized_field_symbols_4.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols_4.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols_4.resharper_applicable_kinds = unity_serialised_field
dotnet_naming_symbols.unity_serialized_field_symbols_4.resharper_required_modifiers = instance
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
Expand Down
222 changes: 111 additions & 111 deletions MechJeb2/AttitudeControllers/BetterController.cs

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions MechJeb2/AttitudeControllers/DirectionTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MuMech.AttitudeControllers
public class DirectionTracker
{
private QuaternionD _previousRotation;
public Vector3d TrackedRotation;
public Vector3d TrackedRotation;

private bool NeedsInitialization() => _previousRotation == new QuaternionD(0, 0, 0, 0);

Expand All @@ -21,18 +21,18 @@ public Vector3d Update(QuaternionD currentRotation)
if (NeedsInitialization())
{
_previousRotation = currentRotation;
TrackedRotation = Vector3d.zero;
TrackedRotation = Vector3d.zero;
return TrackedRotation;
}

// Calculate the change in rotation and the change in euler angles
QuaternionD deltaRotation = QuaternionD.Inverse(_previousRotation) * currentRotation;
Vector3d deltaEuler = MathExtensions.EulerAngles(deltaRotation);
Vector3d deltaEuler = MathExtensions.EulerAngles(deltaRotation);

// Convert to radians and clamp to [-pi, pi]
double deltaPitch = ClampPi(Deg2Rad(deltaEuler.x));
double deltaYaw = -ClampPi(Deg2Rad(deltaEuler.y));
double deltaRoll = ClampPi(Deg2Rad(deltaEuler.z));
double deltaYaw = -ClampPi(Deg2Rad(deltaEuler.y));
double deltaRoll = ClampPi(Deg2Rad(deltaEuler.z));

// Apply in the KSP/MJ pitch/roll/yaw order
TrackedRotation.x += deltaPitch;
Expand All @@ -48,12 +48,12 @@ public Vector3d Update(QuaternionD currentRotation)
public (Vector3d desired, Vector3d error, double distance) Desired(QuaternionD desiredRotation)
{
QuaternionD deltaRotation = QuaternionD.Inverse(_previousRotation) * desiredRotation;
Vector3d deltaEuler = MathExtensions.EulerAngles(deltaRotation);
Vector3d deltaEuler = MathExtensions.EulerAngles(deltaRotation);

// Convert to radians and clamp to [-pi, pi]
double deltaPitch = ClampPi(Deg2Rad(deltaEuler.x));
double deltaYaw = -ClampPi(Deg2Rad(deltaEuler.y));
double deltaRoll = ClampPi(Deg2Rad(deltaEuler.z));
double deltaYaw = -ClampPi(Deg2Rad(deltaEuler.y));
double deltaRoll = ClampPi(Deg2Rad(deltaEuler.z));

var error = new Vector3d(deltaPitch, deltaRoll, deltaYaw);

Expand All @@ -66,7 +66,7 @@ public Vector3d Update(QuaternionD currentRotation)
public void Reset()
{
_previousRotation = new QuaternionD(0, 0, 0, 0);
TrackedRotation = Vector3d.zero;
TrackedRotation = Vector3d.zero;
}

// This method is used to reset the accumulated rotation for a specific axis
Expand Down
32 changes: 16 additions & 16 deletions MechJeb2/AttitudeControllers/HybridController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ namespace MuMech.AttitudeControllers
{
internal class HybridController : BaseAttitudeController
{
[UsedImplicitly] [Persistent(pass = (int)Pass.GLOBAL)]
[UsedImplicitly, Persistent(pass = (int)Pass.GLOBAL)]
public readonly EditableDouble MaxStoppingTime = new EditableDouble(2);

[UsedImplicitly] [Persistent(pass = (int)Pass.GLOBAL)]
[UsedImplicitly, Persistent(pass = (int)Pass.GLOBAL)]
public readonly EditableDoubleMult RollControlRange = new EditableDoubleMult(5 * Mathf.Deg2Rad, Mathf.Deg2Rad);

[UsedImplicitly] [Persistent(pass = (int)Pass.GLOBAL)]
[UsedImplicitly, Persistent(pass = (int)Pass.GLOBAL)]
public bool UseControlRange = true;

private readonly TorquePI _pitchPI = new TorquePI();
private readonly TorquePI _yawPI = new TorquePI();
private readonly TorquePI _rollPI = new TorquePI();
private readonly TorquePI _yawPI = new TorquePI();
private readonly TorquePI _rollPI = new TorquePI();

private readonly KosPIDLoop _pitchRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);
private readonly KosPIDLoop _yawRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);
private readonly KosPIDLoop _rollRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);
private readonly KosPIDLoop _yawRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);
private readonly KosPIDLoop _rollRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);

[UsedImplicitly] [Persistent(pass = (int)Pass.GLOBAL)]
[UsedImplicitly, Persistent(pass = (int)Pass.GLOBAL)]
public bool UseInertia = true;

private Vector3d _actuation = Vector3d.zero;
private Vector3d _actuation = Vector3d.zero;
private Vector3d _targetTorque = Vector3d.zero;
private Vector3d _omega = Vector3d.zero;
private Vector3d _omega = Vector3d.zero;

/* error */
private double _phiTotal;

/* error in pitch, roll, yaw */
private Vector3d _phiVector = Vector3d.zero;
private Vector3d _phiVector = Vector3d.zero;
private Vector3d _targetOmega = Vector3d.zero;

/* max angular rotation */
Expand All @@ -56,7 +56,7 @@ public override void DrivePre(FlightCtrlState s, out Vector3d act, out Vector3d
UpdateControl();

deltaEuler = _phiVector * Mathf.Rad2Deg;
act = _actuation;
act = _actuation;
}

private void UpdatePhi()
Expand All @@ -69,10 +69,10 @@ private void UpdatePhi()
QuaternionD deltaRotation = QuaternionD.Inverse((QuaternionD)vesselTransform.transform.rotation * MathExtensions.Euler(-90, 0, 0)) * Ac.RequestedAttitude;

// get us some euler angles for the target transform
Vector3d ea = MathExtensions.EulerAngles(deltaRotation);
double pitch = ea[0] * UtilMath.Deg2Rad;
double yaw = ea[1] * UtilMath.Deg2Rad;
double roll = ea[2] * UtilMath.Deg2Rad;
Vector3d ea = MathExtensions.EulerAngles(deltaRotation);
double pitch = ea[0] * UtilMath.Deg2Rad;
double yaw = ea[1] * UtilMath.Deg2Rad;
double roll = ea[2] * UtilMath.Deg2Rad;

// law of cosines for the "distance" of the miss in radians
_phiTotal = Math.Acos(MuUtils.Clamp(Math.Cos(pitch) * Math.Cos(yaw), -1, 1));
Expand Down
38 changes: 19 additions & 19 deletions MechJeb2/AttitudeControllers/KosAttitudeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ namespace MuMech.AttitudeControllers
{
internal class KosAttitudeController : BaseAttitudeController
{
[UsedImplicitly] [Persistent(pass = (int)Pass.GLOBAL)]
[UsedImplicitly, Persistent(pass = (int)Pass.GLOBAL)]
public readonly EditableDouble MaxStoppingTime = new EditableDouble(2);

[UsedImplicitly] [Persistent(pass = (int)Pass.GLOBAL)]
[UsedImplicitly, Persistent(pass = (int)Pass.GLOBAL)]
public readonly EditableDoubleMult RollControlRange = new EditableDoubleMult(5 * Mathf.Deg2Rad, Mathf.Deg2Rad);
//public double RollControlRange {
// get { return this.rollControlRange; }
// set { this.rollControlRange.val = Math.Max(EPSILON, Math.Min(Math.PI, value)); }
//}

private readonly TorquePI _pitchPI = new TorquePI();
private readonly TorquePI _yawPI = new TorquePI();
private readonly TorquePI _rollPI = new TorquePI();
private readonly TorquePI _yawPI = new TorquePI();
private readonly TorquePI _rollPI = new TorquePI();

private readonly KosPIDLoop _pitchRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);
private readonly KosPIDLoop _yawRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);
private readonly KosPIDLoop _rollRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);
private readonly KosPIDLoop _yawRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);
private readonly KosPIDLoop _rollRatePI = new KosPIDLoop(1, 0.1, 0, extraUnwind: true);

private Vector3d _actuation = Vector3d.zero;
private Vector3d _actuation = Vector3d.zero;
private Vector3d _targetTorque = Vector3d.zero;
private Vector3d _omega = Vector3d.zero;
private Vector3d _omega = Vector3d.zero;

/* error */
private double _phiTotal;

/* error in pitch, roll, yaw */
private Vector3d _phiVector = Vector3d.zero;
private Vector3d _phiVector = Vector3d.zero;
private Vector3d _targetOmega = Vector3d.zero;

/* max angular rotation */
Expand All @@ -53,29 +53,29 @@ public override void DrivePre(FlightCtrlState s, out Vector3d act, out Vector3d
UpdateControl();

deltaEuler = _phiVector * Mathf.Rad2Deg;
act = _actuation;
act = _actuation;
}

/* temporary state vectors */
private QuaternionD _vesselRotation;
private Vector3d _vesselForward;
private Vector3d _vesselTop;
private Vector3d _vesselStarboard;
private Vector3d _targetForward;
private Vector3d _targetTop;
private Vector3d _vesselForward;
private Vector3d _vesselTop;
private Vector3d _vesselStarboard;
private Vector3d _targetForward;
private Vector3d _targetTop;

/* private Vector3d targetStarboard; */

private void UpdateStateVectors()
{
/* FIXME: may get called more than once per tick */
_vesselRotation = (QuaternionD)Ac.Vessel.ReferenceTransform.rotation * MathExtensions.Euler(-90, 0, 0);
_vesselForward = _vesselRotation * Vector3d.forward;
_vesselTop = _vesselRotation * Vector3d.up;
_vesselRotation = (QuaternionD)Ac.Vessel.ReferenceTransform.rotation * MathExtensions.Euler(-90, 0, 0);
_vesselForward = _vesselRotation * Vector3d.forward;
_vesselTop = _vesselRotation * Vector3d.up;
_vesselStarboard = _vesselRotation * Vector3d.right;

_targetForward = Ac.RequestedAttitude * Vector3d.forward;
_targetTop = Ac.RequestedAttitude * Vector3d.up;
_targetTop = Ac.RequestedAttitude * Vector3d.up;
/* targetStarboard = target * Vector3d.right; */

_omega = -Ac.Vessel.angularVelocity;
Expand Down
Loading
Loading