From 0afdbf3ee5a0b6cd3d2da1c9d8dc1a9c3c3eeef0 Mon Sep 17 00:00:00 2001 From: Sarbian Date: Mon, 16 Nov 2026 00:35:57 +0100 Subject: [PATCH] Attitude Adjustment: controller read-outs folded under Diagnostics, Reset under the gains, spelled-out labels with tooltips, Clegg once as a row label --- Localization/en-us.cfg | 13 ++- Localization/zh-cn.cfg | 1 + MechJeb2.UI/src/AttitudeControllerPanels.cs | 120 +++++++++++--------- 3 files changed, 73 insertions(+), 61 deletions(-) diff --git a/Localization/en-us.cfg b/Localization/en-us.cfg index bb4470f52..fccacb3ad 100644 --- a/Localization/en-us.cfg +++ b/Localization/en-us.cfg @@ -1056,15 +1056,16 @@ Localization #MechJeb_Ascent_checkbox20 = Electric limit Lo #MechJeb_Ascent_srcmsg1 = [MechJeb]: Killing throttle to prevent unstable ignition - #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 diff --git a/Localization/zh-cn.cfg b/Localization/zh-cn.cfg index 0c5fd277c..d037f0a15 100644 --- a/Localization/zh-cn.cfg +++ b/Localization/zh-cn.cfg @@ -1059,6 +1059,7 @@ Localization #MechJeb_HybridController_label4 = 目标扭矩 #MechJeb_HybridController_label5 = 控制扭矩 #MechJeb_HybridController_label6 = 惯性 + #MechJeb_NewUI_Diagnostics = 诊断 #MechJeb_Actiongroup_label1 = 切换动作组 diff --git a/MechJeb2.UI/src/AttitudeControllerPanels.cs b/MechJeb2.UI/src/AttitudeControllerPanels.cs index 0543d0fe8..e0cf7201f 100644 --- a/MechJeb2.UI/src/AttitudeControllerPanels.cs +++ b/MechJeb2.UI/src/AttitudeControllerPanels.cs @@ -275,8 +275,8 @@ public void Sync(Action action) => w.AddSync(() => }); } - static void Magnitude(Panel p, string label, Func get) where T : BaseAttitudeController => - p.Vec(label, get, WithMagnitude, VectorTemplate); + static void Magnitude(Panel p, string label, Func 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; @@ -354,12 +354,13 @@ static void Factor(Panel p, string left, Func 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 ---- @@ -370,13 +371,14 @@ static void BuildHybrid(Panel 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 ---- @@ -397,56 +399,64 @@ static void BuildBetter(Panel 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); } /// A text in a cell of fixed width (or a flexible one), so the columns of a grid line up with its fields. - 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() ?? t.gameObject.AddComponent(); le.minWidth = flexible ? 60 : width; if (!flexible) le.preferredWidth = width; + return t; } + /// The controller's live read-outs, folded under "Diagnostics" (closed at first, remembered for the session per key). + static Layout Diagnostics(Panel p, string key) where T : BaseAttitudeController => + p.W.Section(p.Parent, KSP.Localization.Localizer.Format("#MechJeb_NewUI_Diagnostics"), false, key); //Diagnostics + /// A fixed-width column in a grid row, for a widget that would otherwise stretch (a toggle row). static Layout Column(UIObject row, float width) { @@ -459,11 +469,11 @@ static Layout Column(UIObject row, float width) return col; } - static void Grid(Panel p, string label, Func vel, + static void Grid(Panel p, string label, string tooltip, Func vel, Func 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); }