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
13 changes: 7 additions & 6 deletions Localization/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1056,15 +1056,16 @@ Localization
#MechJeb_Ascent_checkbox20 = Electric limit Lo
#MechJeb_Ascent_srcmsg1 = <color=orange>[MechJeb]: Killing throttle to prevent unstable ignition</color>

#MechJeb_HybridController_checkbox1 = useInertia
#MechJeb_HybridController_checkbox2 = RollControlRange
#MechJeb_HybridController_checkbox1 = Use inertia
#MechJeb_HybridController_checkbox2 = Roll control range

#MechJeb_HybridController_label1 = MaxStoppingTime
#MechJeb_HybridController_label1 = Max stopping time
#MechJeb_HybridController_label2 = Actuation
#MechJeb_HybridController_label3 = phiVector
#MechJeb_HybridController_label4 = TargetTorque
#MechJeb_HybridController_label5 = ControlTorque
#MechJeb_HybridController_label3 = Phi vector
#MechJeb_HybridController_label4 = Target torque
#MechJeb_HybridController_label5 = Control torque
#MechJeb_HybridController_label6 = Inertia
#MechJeb_NewUI_Diagnostics = Diagnostics

#MechJeb_Actiongroup_label1 = Toggle action group

Expand Down
1 change: 1 addition & 0 deletions Localization/zh-cn.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ Localization
#MechJeb_HybridController_label4 = 目标扭矩
#MechJeb_HybridController_label5 = 控制扭矩
#MechJeb_HybridController_label6 = 惯性
#MechJeb_NewUI_Diagnostics = 诊断

#MechJeb_Actiongroup_label1 = 切换动作组

Expand Down
120 changes: 65 additions & 55 deletions MechJeb2.UI/src/AttitudeControllerPanels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ public void Sync(Action<T> action) => w.AddSync(() =>
});
}

static void Magnitude<T>(Panel<T> p, string label, Func<T, Vector3d> get) where T : BaseAttitudeController =>
p.Vec(label, get, WithMagnitude, VectorTemplate);
static void Magnitude<T>(Panel<T> p, string label, Func<T, Vector3d> get, UIObject parent = null) where T : BaseAttitudeController =>
p.Vec(label, get, WithMagnitude, VectorTemplate, parent);

static Vector3d Moi(Vessel v) => v == null ? Vector3d.zero : (Vector3d)v.MOI;

Expand Down Expand Up @@ -354,12 +354,13 @@ static void Factor(Panel<MJAttitudeController> p, string left, Func<MJAttitudeCo

static void BuildKos(Panel<KosAttitudeController> p)
{
p.Edit("MaxStoppingTime", c => c.MaxStoppingTime, 40);
p.Edit("RollControlRange", c => c.RollControlRange, 40);
p.Vec("Actuation", c => c._actuation);
p.Vec("phiVector", c => c._phiVector);
p.Vec("TargetTorque", c => c._targetTorque);
p.Vec("ControlTorque", c => c._controlTorque);
p.Edit("Max stopping time", c => c.MaxStoppingTime, 40);
p.Edit("Roll control range", c => c.RollControlRange, 40);
Layout diag = Diagnostics(p, "KosControllerDiagnostics");
p.Vec("Actuation", c => c._actuation, parent: diag);
p.Vec("Phi vector", c => c._phiVector, parent: diag);
p.Vec("Target torque", c => c._targetTorque, parent: diag);
p.Vec("Control torque", c => c._controlTorque, parent: diag);
}

// ---- HybridController ----
Expand All @@ -370,13 +371,14 @@ static void BuildHybrid(Panel<HybridController> p)
p.Edit("#MechJeb_HybridController_label1", c => c.MaxStoppingTime, 60); //"MaxStoppingTime"
p.ToggleEdit("#MechJeb_HybridController_checkbox2", c => c.UseControlRange, (c, v) => c.UseControlRange = v, //"RollControlRange"
c => c.RollControlRange, 60);
p.Vec("#MechJeb_HybridController_label2", c => c._actuation); //"Actuation"
p.Vec("#MechJeb_HybridController_label3", c => c._phiVector); //"phiVector"
p.Vec("Omega", c => c._omega);
p.Vec("MaxOmega", c => c._maxOmega);
p.Vec("#MechJeb_HybridController_label4", c => c._targetTorque); //"TargetTorque"
p.Vec("#MechJeb_HybridController_label5", c => c._controlTorque); //"ControlTorque"
Magnitude(p, "#MechJeb_HybridController_label6", c => p.Att.Inertia); //"Inertia"
Layout diag = Diagnostics(p, "HybridControllerDiagnostics");
p.Vec("#MechJeb_HybridController_label2", c => c._actuation, parent: diag); //"Actuation"
p.Vec("#MechJeb_HybridController_label3", c => c._phiVector, parent: diag); //"Phi vector"
p.Vec("Omega", c => c._omega, parent: diag);
p.Vec("Max omega", c => c._maxOmega, parent: diag);
p.Vec("#MechJeb_HybridController_label4", c => c._targetTorque, parent: diag); //"Target torque"
p.Vec("#MechJeb_HybridController_label5", c => c._controlTorque, parent: diag); //"Control torque"
Magnitude(p, "#MechJeb_HybridController_label6", c => p.Att.Inertia, diag); //"Inertia"
}

// ---- BetterController ----
Expand All @@ -397,56 +399,64 @@ static void BuildBetter(Panel<BetterController> p)
Cell(head, "Velocity", COL, false);
Cell(head, "Position", COL, false);

Grid(p, "Kp", c => c.VelKp, c => c.PosKp);
Grid(p, "Ti", c => c.VelTi, c => c.PosTi);
Grid(p, "Td", c => c.VelTd, c => c.PosTd);
Grid(p, "N", c => c.VelN, c => c.PosN);
Grid(p, "B", c => c.VelB, c => c.PosB);
Grid(p, "C", c => c.VelC, c => c.PosC);
Grid(p, "Deadband", c => c.VelDeadband, c => c.PosDeadband);
Grid(p, "SmoothIn", c => c.VelSmoothIn, c => c.PosSmoothIn);
Grid(p, "SmoothOut", c => c.VelSmoothOut, c => c.PosSmoothOut);

// each Clegg toggle in its column, under the Velocity and Position fields
Grid(p, "Gain (Kp)", "Proportional gain of the PID.", c => c.VelKp, c => c.PosKp);
Grid(p, "Integral time (Ti)", "Integral time constant, in seconds: smaller corrects a lasting error faster.", c => c.VelTi, c => c.PosTi);
Grid(p, "Derivative time (Td)", "Derivative time constant, in seconds: larger damps more.", c => c.VelTd, c => c.PosTd);
Grid(p, "Filter (N)", "Derivative filter: the derivative term is low-pass filtered at N / Td.", c => c.VelN, c => c.PosN);
Grid(p, "P weight (B)", "Setpoint weight of the proportional term.", c => c.VelB, c => c.PosB);
Grid(p, "D weight (C)", "Setpoint weight of the derivative term.", c => c.VelC, c => c.PosC);
Grid(p, "Deadband", "Errors smaller than this are treated as zero.", c => c.VelDeadband, c => c.PosDeadband);
Grid(p, "Smooth in", "Smoothing of the input.", c => c.VelSmoothIn, c => c.PosSmoothIn);
Grid(p, "Smooth out", "Smoothing of the output.", c => c.VelSmoothOut, c => c.PosSmoothOut);

// "Clegg" once, as the row's label, a toggle under each of the Velocity and Position fields
Layout clegg = p.Row();
Cell(clegg, "", COL1, true);
p.Tog(Column(clegg, COL), "Clegg", c => c.VelClegg, (c, v) => c.VelClegg = v);
p.Tog(Column(clegg, COL), "Clegg", c => c.PosClegg, (c, v) => c.PosClegg = v);

p.Vec("Pos PTerm", c => new Vector3d(c._posPID[0].PTerm, c._posPID[1].PTerm, c._posPID[2].PTerm), PlainSci, SciTemplate);
p.Vec("Pos ITerm", c => new Vector3d(c._posPID[0].ITerm, c._posPID[1].ITerm, c._posPID[2].ITerm), PlainSci, SciTemplate);
p.Vec("Pos DTerm", c => new Vector3d(c._posPID[0].DTerm, c._posPID[1].DTerm, c._posPID[2].DTerm), PlainSci, SciTemplate);
p.Vec("Vel PTerm", c => new Vector3d(c._velPID[0].PTerm, c._velPID[1].PTerm, c._velPID[2].PTerm), PlainSci, SciTemplate);
p.Vec("Vel ITerm", c => new Vector3d(c._velPID[0].ITerm, c._velPID[1].ITerm, c._velPID[2].ITerm), PlainSci, SciTemplate);
p.Vec("Vel DTerm", c => new Vector3d(c._velPID[0].DTerm, c._velPID[1].DTerm, c._velPID[2].DTerm), PlainSci, SciTemplate);

p.Edit("Smooth Torque", c => c.SmoothTorque, 50);
Tooltips.Add(Cell(clegg, "Clegg", COL1, true).gameObject, "Clegg integrator: the integral term resets when the error changes sign.");
p.Tog(Column(clegg, COL), "", c => c.VelClegg, (c, v) => c.VelClegg = v);
p.Tog(Column(clegg, COL), "", c => c.PosClegg, (c, v) => c.PosClegg = v);

p.Edit("Smooth torque", c => c.SmoothTorque, 50);
p.Edit("Soften", c => c.Soften, 50);
p.Button("Reset Tuning Values", c => c.Defaults());

p.Vec("Current", c => c._current);
p.Vec("Desired", c => c._desired);
p.Vec("Error", c => c._error);
p.Vec("TargetOmega", c => c._targetOmega);
p.Vec("Omega", c => c._vessel == null ? Vector3d.zero : c._vessel.angularVelocityD);
p.Vec("#MechJeb_HybridController_label2", c => c._actuation); //"Actuation"
p.Vec("#MechJeb_HybridController_label4", c => c._targetTorque); //"TargetTorque"
p.Vec("#MechJeb_HybridController_label5", c => c._controlTorque); //"ControlTorque"
p.Vec("TargetAlpha", c => c._targetAlpha);
p.Vec("MaxAlpha", c => c._maxAlpha);
p.Vec("MOI", c => Moi(c._vessel));
p.Vec("Response Speed", c => p.Att.VesselState == null ? Vector3d.zero : p.Att.VesselState.TorqueResponseSpeed);
p.Button("Reset tuning values", c => c.Defaults());

Layout diag = Diagnostics(p, "BetterControllerDiagnostics");
p.Vec("Pos P term", c => new Vector3d(c._posPID[0].PTerm, c._posPID[1].PTerm, c._posPID[2].PTerm), PlainSci, SciTemplate, diag);
p.Vec("Pos I term", c => new Vector3d(c._posPID[0].ITerm, c._posPID[1].ITerm, c._posPID[2].ITerm), PlainSci, SciTemplate, diag);
p.Vec("Pos D term", c => new Vector3d(c._posPID[0].DTerm, c._posPID[1].DTerm, c._posPID[2].DTerm), PlainSci, SciTemplate, diag);
p.Vec("Vel P term", c => new Vector3d(c._velPID[0].PTerm, c._velPID[1].PTerm, c._velPID[2].PTerm), PlainSci, SciTemplate, diag);
p.Vec("Vel I term", c => new Vector3d(c._velPID[0].ITerm, c._velPID[1].ITerm, c._velPID[2].ITerm), PlainSci, SciTemplate, diag);
p.Vec("Vel D term", c => new Vector3d(c._velPID[0].DTerm, c._velPID[1].DTerm, c._velPID[2].DTerm), PlainSci, SciTemplate, diag);

// a second grid under the first, in the same fold
Layout state = KodeWindow.Panel(diag);
p.Vec("Current", c => c._current, parent: state);
p.Vec("Desired", c => c._desired, parent: state);
p.Vec("Error", c => c._error, parent: state);
p.Vec("Target omega", c => c._targetOmega, parent: state);
p.Vec("Omega", c => c._vessel == null ? Vector3d.zero : c._vessel.angularVelocityD, parent: state);
p.Vec("#MechJeb_HybridController_label2", c => c._actuation, parent: state); //"Actuation"
p.Vec("#MechJeb_HybridController_label4", c => c._targetTorque, parent: state); //"Target torque"
p.Vec("#MechJeb_HybridController_label5", c => c._controlTorque, parent: state); //"Control torque"
p.Vec("Target alpha", c => c._targetAlpha, parent: state);
p.Vec("Max alpha", c => c._maxAlpha, parent: state);
p.Vec("MOI", c => Moi(c._vessel), parent: state);
p.Vec("Response speed", c => p.Att.VesselState == null ? Vector3d.zero : p.Att.VesselState.TorqueResponseSpeed, parent: state);
}

/// <summary>A text in a cell of fixed width (or a flexible one), so the columns of a grid line up with its fields.</summary>
static void Cell(UIObject row, string text, float width, bool flexible)
static UIText Cell(UIObject row, string text, float width, bool flexible)
{
UIText t = KodeWindow.Label(row, text, flexible);
var le = t.gameObject.GetComponent<LayoutElement>() ?? t.gameObject.AddComponent<LayoutElement>();
le.minWidth = flexible ? 60 : width;
if (!flexible) le.preferredWidth = width;
return t;
}

/// <summary>The controller's live read-outs, folded under "Diagnostics" (closed at first, remembered for the session per key).</summary>
static Layout Diagnostics<T>(Panel<T> p, string key) where T : BaseAttitudeController =>
p.W.Section(p.Parent, KSP.Localization.Localizer.Format("#MechJeb_NewUI_Diagnostics"), false, key); //Diagnostics

/// <summary>A fixed-width column in a grid row, for a widget that would otherwise stretch (a toggle row).</summary>
static Layout Column(UIObject row, float width)
{
Expand All @@ -459,11 +469,11 @@ static Layout Column(UIObject row, float width)
return col;
}

static void Grid(Panel<BetterController> p, string label, Func<BetterController, EditableDoubleMult> vel,
static void Grid(Panel<BetterController> p, string label, string tooltip, Func<BetterController, EditableDoubleMult> vel,
Func<BetterController, EditableDoubleMult> pos)
{
Layout row = p.Row();
Cell(row, label, 100, true);
Tooltips.Add(Cell(row, label, 100, true).gameObject, tooltip);
p.Fld(row, vel, 56);
p.Fld(row, pos, 56);
}
Expand Down
Loading