Skip to content

Commit

Permalink
More PID tuning
Browse files Browse the repository at this point in the history
This uses a "balanced" auto tuning for a 75 degree phase margin and
lets at least a few rockets i tested get through MaxQ at max warp.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Jun 10, 2023
1 parent 3ac9488 commit 0c1ff26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions MechJeb2/AttitudeControllers/BetterController.cs
Expand Up @@ -18,22 +18,22 @@ internal class BetterController : BaseAttitudeController
private readonly EditableDouble PosDeadband = new EditableDouble(0.0001);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
private readonly EditableDouble VelKp = new EditableDouble(9.18299345180006);
private readonly EditableDouble VelKp = new EditableDouble(35);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
private readonly EditableDouble VelKi = new EditableDouble(16.2833478287224);
private readonly EditableDouble VelKi = new EditableDouble(16.6);

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

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

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

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

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
private readonly EditableDouble VelDeadband = new EditableDouble(0.0001);
Expand Down Expand Up @@ -68,28 +68,28 @@ internal class BetterController : BaseAttitudeController
[Persistent(pass = (int)(Pass.Type | Pass.Global))]
private bool useStoppingTime = true;

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

private void Defaults()
{
PosKp.val = 1.98;
PosDeadband.val = 0.0001;
VelKp.val = 9.18299345180006;
VelKi.val = 16.2833478287224;
VelKd.val = -0.0921320503942923;
VelN.val = 99.6720838459594;
VelB.val = 0.596313214751797;
VelC.val = 0.596313214751797;
VelDeadband.val = 0.001;
VelKp.val = 35;
VelKi.val = 16.6;
VelKd.val = 0.425;
VelN.val = 84.1994541201249;
VelB.val = 0.994;
VelC.val = 0.0185;
VelDeadband.val = 0.0001;
VelClegg = false;
VelSmoothIn.val = 1.0;
VelSmoothOut.val = 1.0;
PosSmoothIn.val = 1.0;
maxStoppingTime.val = 2;
minFlipTime.val = 120;
rollControlRange.val = 5;
_version = 2;
_version = 3;
}

private readonly PIDLoop[] _pid = { new PIDLoop(), new PIDLoop(), new PIDLoop() };
Expand Down
4 changes: 2 additions & 2 deletions MechJeb2/MechJebLib/Control/PIDLoop.cs
Expand Up @@ -16,12 +16,12 @@ public class PIDLoop
public double Ki { get; set; }
public double Kd { get; set; }
public double Ts { get; set; } = 0.02;
public double N { get; set; } = 50;
public double N { get; set; } = 50; // N = (4/Ts) * (1 - e^(-Ts/(2*Tf))) (trapezoidal discretization)
public double B { get; set; } = 1;
public double C { get; set; } = 1;
public double SmoothIn { get; set; } = 1.0;
public double SmoothOut { get; set; } = 1.0;
public double Deadband { get; set; } = 0;
public double Deadband { get; set; }
public double MinOutput { get; set; } = double.MinValue;
public double MaxOutput { get; set; } = double.MaxValue;
public bool Clegg { get; set; } = true;
Expand Down

0 comments on commit 0c1ff26

Please sign in to comment.