public virtual Vector3d Lift(Vector3d vesselVelocity, double liftFactor) { if (shieldedFromAirstream || hasLiftModule) { return(Vector3d.zero); } // direction of the lift in a vessel centric reference Vector3d liftV = partToVessel * ((Vector3d)cubes.LiftForce * bodyLiftMultiplier * liftFactor); Vector3d liftVector = liftV.ProjectOnPlane(vesselVelocity); #if DEBUG && false if (vesselVelocity.sqrMagnitude > 1 && oPart.DragCubes.LiftForce.sqrMagnitude > 0.001) { string msg = oPart.name; Vector3 bodyL = oPart.transform.rotation * (oPart.bodyLiftScalar * oPart.DragCubes.LiftForce); Vector3 bodyLift = Vector3.ProjectOnPlane(bodyL, -oPart.dragVectorDir); msg += "\n liftDir " + MuUtils.PrettyPrint(liftVector) + " vs " + MuUtils.PrettyPrint(bodyLift) + " " + Vector3.Angle(liftVector, bodyLift).ToString("F3") + "°"; Vector3 localBodyL = oPart.vessel.transform.InverseTransformDirection(bodyL); msg += "\n liftV " + MuUtils.PrettyPrint(liftV) + " vs " + MuUtils.PrettyPrint(localBodyL) + " " + Vector3.Angle(liftV, localBodyL).ToString("F3") + "°"; msg += "\n liftForce " + MuUtils.PrettyPrint(cubes.LiftForce) + " vs " + MuUtils.PrettyPrint(oPart.DragCubes.LiftForce) + " " + Vector3.Angle(cubes.LiftForce, oPart.DragCubes.LiftForce).ToString("F3") + "°"; msg += "\n Normals " + MuUtils.PrettyPrint(-vesselVelocity) + " vs " + MuUtils.PrettyPrint(-oPart.dragVectorDir) + " " + Vector3.Angle(-vesselVelocity, -oPart.dragVectorDir).ToString("F3") + "°"; msg += "\n vals " + bodyLiftMultiplier.ToString("F5") + " " + dynamicPressurekPa.ToString("F5") + " " + liftCurves.liftMachCurve.Evaluate(mach).ToString("F5"); Log.dbg(msg); } #endif return(liftVector); }
public string ToString(string format) { return(MuUtils.PrettyPrint(value, format)); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); //core.GetComputerModule<MechJebModuleCustomWindowEditor>().registry.Find(i => i.id == "Toggle:AttitudeController.useSAS").DrawItem(); core.attitude.RCS_auto = GUILayout.Toggle(core.attitude.RCS_auto, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox1"));//RCS auto mode int currentController = core.attitude.activeController; if (GUILayout.Toggle(currentController == 0, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox2")))//MJAttitudeController { currentController = 0; } if (GUILayout.Toggle(currentController == 1, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox3")))//KosAttitudeController { currentController = 1; } if (GUILayout.Toggle(currentController == 2, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox4")))//HybridController { currentController = 2; } GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); core.attitude.Controller.GUI(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (currentController != core.attitude.activeController) { core.attitude.SetActiveController(currentController); } showInfos = GUILayout.Toggle(showInfos, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox5"));//Show Numbers if (showInfos) { GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_AttitudeAdjust_Label1"), GUILayout.ExpandWidth(true));//Axis Control GUILayout.Label(MuUtils.PrettyPrint(core.attitude.AxisState, "F0"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_AttitudeAdjust_Label2"), GUILayout.ExpandWidth(true));//Torque GUILayout.Label("|" + core.attitude.torque.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(core.attitude.torque), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_AttitudeAdjust_Label3"), GUILayout.ExpandWidth(true));//torqueReactionSpeed GUILayout.Label( "|" + vesselState.torqueReactionSpeed.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vesselState.torqueReactionSpeed), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d ratio = Vector3d.Scale(vesselState.MoI, core.attitude.torque.InvertNoNaN()); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_AttitudeAdjust_Label4"), GUILayout.ExpandWidth(true));//MOI / torque GUILayout.Label("|" + ratio.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(ratio), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_AttitudeAdjust_Label5"), GUILayout.ExpandWidth(true));//MOI GUILayout.Label("|" + vesselState.MoI.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vesselState.MoI), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_AttitudeAdjust_Label6"), GUILayout.ExpandWidth(true));//Angular Velocity GUILayout.Label("|" + vessel.angularVelocity.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vessel.angularVelocity), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_AttitudeAdjust_Label7"), GUILayout.ExpandWidth(true));//"Angular M" GUILayout.Label( "|" + vesselState.angularMomentum.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vesselState.angularMomentum), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_AttitudeAdjust_Label8"), GUILayout.ExpandWidth(true));//fixedDeltaTime GUILayout.Label(TimeWarp.fixedDeltaTime.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } MechJebModuleDebugArrows arrows = core.GetComputerModule <MechJebModuleDebugArrows>(); GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_AttitudeAdjust_Label9"), arrows.arrowsLength, "", 50); //Arrows length arrows.seeThrough = GUILayout.Toggle(arrows.seeThrough, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox6")); //Visible through object arrows.comSphereActive = GUILayout.Toggle(arrows.comSphereActive, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox7"), GUILayout.ExpandWidth(false)); //Display the CoM arrows.colSphereActive = GUILayout.Toggle(arrows.colSphereActive, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox8"), GUILayout.ExpandWidth(false)); //Display the CoL arrows.cotSphereActive = GUILayout.Toggle(arrows.cotSphereActive, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox9"), GUILayout.ExpandWidth(false)); //Display the CoT GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_AttitudeAdjust_Label10"), GUILayout.ExpandWidth(true)); //Radius of Sphere arrows.comSphereRadius.text = GUILayout.TextField(arrows.comSphereRadius.text, GUILayout.Width(40)); GUILayout.EndHorizontal(); arrows.displayAtCoM = GUILayout.Toggle(arrows.displayAtCoM, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox10")); //Arrows origins at the CoM arrows.srfVelocityArrowActive = GUILayout.Toggle(arrows.srfVelocityArrowActive, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox11")); //Pod Surface Velocity (green) arrows.obtVelocityArrowActive = GUILayout.Toggle(arrows.obtVelocityArrowActive, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox12")); //Pod Orbital Velocity (red) arrows.dotArrowActive = GUILayout.Toggle(arrows.dotArrowActive, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox13")); //Direction of Thrust (purple pink) arrows.forwardArrowActive = GUILayout.Toggle(arrows.forwardArrowActive, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox14")); //Command Pod Forward (electric blue) //arrows.avgForwardArrowActive = GUILayout.Toggle(arrows.avgForwardArrowActive, "Forward Avg (blue)"); arrows.requestedAttitudeArrowActive = GUILayout.Toggle(arrows.requestedAttitudeArrowActive, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox15")); //Requested Attitude (gray) arrows.debugArrowActive = GUILayout.Toggle(arrows.debugArrowActive, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox16")); //Debug (magenta) arrows.debugArrow2Active = GUILayout.Toggle(arrows.debugArrow2Active, Localizer.Format("#MechJeb_AttitudeAdjust_checkbox17")); //Debug2 (light blue) GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); if (GUILayout.Button("Reset")) { core.attitude.ResetConfig(); OnStart(PartModule.StartState.None); } core.GetComputerModule <MechJebModuleCustomWindowEditor>().registry.Find(i => i.id == "Toggle:AttitudeController.useSAS").DrawItem(); if (!core.attitude.useSAS) { core.attitude.Tf_autoTune = GUILayout.Toggle(core.attitude.Tf_autoTune, " Tf auto-tuning"); if (!core.attitude.Tf_autoTune) { GUILayout.Label("Larger ship do better with a larger Tf"); GUILayout.BeginHorizontal(); GUILayout.Label("Tf (s)", GUILayout.ExpandWidth(true)); GUILayout.Label("P", GUILayout.ExpandWidth(false)); TfX.text = GUILayout.TextField(TfX.text, GUILayout.ExpandWidth(true), GUILayout.Width(40)); GUILayout.Label("Y", GUILayout.ExpandWidth(false)); TfY.text = GUILayout.TextField(TfY.text, GUILayout.ExpandWidth(true), GUILayout.Width(40)); GUILayout.Label("R", GUILayout.ExpandWidth(false)); TfZ.text = GUILayout.TextField(TfZ.text, GUILayout.ExpandWidth(true), GUILayout.Width(40)); GUILayout.EndHorizontal(); TfX = Math.Max(0.01, TfX); TfY = Math.Max(0.01, TfY); TfZ = Math.Max(0.01, TfZ); } else { GUILayout.BeginHorizontal(); GUILayout.Label("Tf", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.TfV), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Tf range"); GuiUtils.SimpleTextBox("min", TfMin, "", 50); TfMin = Math.Max(TfMin, 0.01); GuiUtils.SimpleTextBox("max", TfMax, "", 50); TfMax = Math.Max(TfMax, 0.01); GUILayout.EndHorizontal(); } GUILayout.Label("PID factors"); GuiUtils.SimpleTextBox("Kd = ", kdFactor, " / Tf", 50); kdFactor = Math.Max(kdFactor, 0.01); GuiUtils.SimpleTextBox("Kp = pid.Kd / (", kpFactor, " * Math.Sqrt(2) * Tf)", 50); kpFactor = Math.Max(kpFactor, 0.01); GuiUtils.SimpleTextBox("Ki = pid.Kp / (", kiFactor, " * Math.Sqrt(2) * Tf)", 50); kiFactor = Math.Max(kiFactor, 0.01); GuiUtils.SimpleTextBox("Deadband = ", deadband, "", 50); core.attitude.deadband = Math.Max(deadband, 0.0); core.attitude.RCS_auto = GUILayout.Toggle(core.attitude.RCS_auto, " RCS auto mode"); //Lower value of "kWlimit" reduces maximum angular velocity double kWlimit = core.attitude.kWlimit; var nextkWlimit = new EditableDoubleMult(kWlimit, 0.01); GuiUtils.SimpleTextBox("Maximum Relative Angular Velocity", nextkWlimit, "%"); nextkWlimit = (EditableDouble)GUILayout.HorizontalSlider((float)nextkWlimit, 0.0F, 1.0F); const int sliderPrecision = 3; if (Math.Round(Math.Abs(nextkWlimit - kWlimit), sliderPrecision) > 0) { core.attitude.kWlimit = Math.Round(nextkWlimit, sliderPrecision); } showInfos = GUILayout.Toggle(showInfos, "Show Numbers"); if (showInfos) { GUILayout.BeginHorizontal(); GUILayout.Label("Kp", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.Kp), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Ki", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.Ki), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Kd", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.Kd), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Error", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.error * Mathf.Rad2Deg), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("prop. action.", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.propAct), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("deriv. action", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.derivativeAct), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("integral action.", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.intAccum), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("PID Action", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pidAction), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Axis Control ", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.AxisState, "F0"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Torque", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + core.attitude.torque.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(core.attitude.torque), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("torqueReactionSpeed", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + vesselState.torqueReactionSpeed.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vesselState.torqueReactionSpeed), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Inertia", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + core.attitude.inertia.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(core.attitude.inertia), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d ratio = Vector3d.Scale(vesselState.MoI, core.attitude.torque.Invert()); GUILayout.BeginHorizontal(); GUILayout.Label("MOI / torque", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + ratio.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(ratio), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("MOI", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + vesselState.MoI.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vesselState.MoI), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("MOI stock", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + vessel.MOI.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vessel.MOI), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Angular Velocity", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + vessel.angularVelocity.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vessel.angularVelocity), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("fixedDeltaTime", GUILayout.ExpandWidth(true)); GUILayout.Label(TimeWarp.fixedDeltaTime.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } } MechJebModuleAttitudeController.useCoMVelocity = GUILayout.Toggle(MechJebModuleAttitudeController.useCoMVelocity, "Use CoM velocity instead of stock"); MechJebModuleDebugArrows arrows = core.GetComputerModule <MechJebModuleDebugArrows>(); GuiUtils.SimpleTextBox("Arrows length", arrows.arrowsLength, "", 50); arrows.seeThrough = GUILayout.Toggle(arrows.seeThrough, "Visible through object"); GUILayout.BeginHorizontal(); arrows.comSphereActive = GUILayout.Toggle(arrows.comSphereActive, "Display the CoM. Radius of ", GUILayout.ExpandWidth(false)); arrows.comSphereRadius.text = GUILayout.TextField(arrows.comSphereRadius.text, GUILayout.Width(40)); GUILayout.EndHorizontal(); arrows.displayAtCoM = GUILayout.Toggle(arrows.displayAtCoM, "Arrows origins at the CoM"); arrows.podSrfVelocityArrowActive = GUILayout.Toggle(arrows.podSrfVelocityArrowActive, "Pod Surface Velocity (yellow)"); arrows.comSrfVelocityArrowActive = GUILayout.Toggle(arrows.comSrfVelocityArrowActive, "CoM Surface Velocity (green)"); arrows.podObtVelocityArrowActive = GUILayout.Toggle(arrows.podObtVelocityArrowActive, "Pod Orbital Velocity (red)"); arrows.comObtVelocityArrowActive = GUILayout.Toggle(arrows.comObtVelocityArrowActive, "CoM Orbital Velocity (orange)"); arrows.forwardArrowActive = GUILayout.Toggle(arrows.forwardArrowActive, "Command Pod Forward (electric blue)"); //arrows.avgForwardArrowActive = GUILayout.Toggle(arrows.avgForwardArrowActive, "Forward Avg (blue)"); arrows.requestedAttitudeArrowActive = GUILayout.Toggle(arrows.requestedAttitudeArrowActive, "Requested Attitude (gray)"); arrows.debugArrowActive = GUILayout.Toggle(arrows.debugArrowActive, "Debug (magenta)"); arrows.debugArrow2Active = GUILayout.Toggle(arrows.debugArrow2Active, "Debug (light blue)"); GUILayout.EndVertical(); if (!core.attitude.Tf_autoTune) { if (core.attitude.TfV.x != TfX || core.attitude.TfV.y != TfY || core.attitude.TfV.z != TfZ) { core.attitude.TfV.x = TfX; core.attitude.TfV.y = TfY; core.attitude.TfV.z = TfZ; core.attitude.setPIDParameters(); } } else { if (core.attitude.TfMin != TfMin || core.attitude.TfMax != TfMax) { core.attitude.TfMin = TfMin; core.attitude.TfMax = TfMax; core.attitude.setPIDParameters(); } if (core.attitude.kpFactor != kpFactor || core.attitude.kiFactor != kiFactor || core.attitude.kdFactor != kdFactor) { core.attitude.kpFactor = kpFactor; core.attitude.kiFactor = kiFactor; core.attitude.kdFactor = kdFactor; core.attitude.setPIDParameters(); } } base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); core.GetComputerModule <MechJebModuleCustomWindowEditor>().registry.Find(i => i.id == "Toggle:AttitudeController.useSAS").DrawItem(); if (!core.attitude.useSAS) { core.attitude.Tf_autoTune = GUILayout.Toggle(core.attitude.Tf_autoTune, " Tf auto tunning"); if (!core.attitude.Tf_autoTune) { GUILayout.Label("Larger ship do better with a larger Tf"); GuiUtils.SimpleTextBox("Tf (s)", Tf); Tf = Math.Max(0.01, Tf); } else { // pid.Kd = kpFactor / Tf; // pid.Kp = pid.Kd / (kiFactor * Math.Sqrt(2) * Tf); // pid.Ki = pid.Kp / (kpFactor * Math.Sqrt(2) * Tf); GUILayout.BeginHorizontal(); GUILayout.Label("Tf", GUILayout.ExpandWidth(true)); GUILayout.Label(core.attitude.Tf.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Tf range"); GuiUtils.SimpleTextBox("min", TfMin, "", 50); TfMin = Math.Max(TfMin, 0.01); GuiUtils.SimpleTextBox("max", TfMax, "", 50); TfMax = Math.Max(TfMax, 0.01); GUILayout.EndHorizontal(); GUILayout.Label("PID factors"); GuiUtils.SimpleTextBox("Kd = ", kdFactor, " / Tf", 50); kdFactor = Math.Max(kdFactor, 0.01); GuiUtils.SimpleTextBox("Kp = pid.Kd / (", kpFactor, " * Math.Sqrt(2) * Tf)", 50); kpFactor = Math.Max(kpFactor, 0.01); GuiUtils.SimpleTextBox("Ki = pid.Kp / (", kiFactor, " * Math.Sqrt(2) * Tf)", 50); kiFactor = Math.Max(kiFactor, 0.01); } core.attitude.RCS_auto = GUILayout.Toggle(core.attitude.RCS_auto, " RCS auto mode"); core.rcs.rcsThrottle = GUILayout.Toggle(core.rcs.rcsThrottle, " RCS throttle when 0k thrust"); GUILayout.BeginHorizontal(); GUILayout.Label("Kp, Ki, Kd", GUILayout.ExpandWidth(true)); GUILayout.Label(core.attitude.pid.Kp.ToString("F3") + ", " + core.attitude.pid.Ki.ToString("F3") + ", " + core.attitude.pid.Kd.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("prop. action.", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.propAct), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("deriv. action", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.derivativeAct), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("integral action.", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.intAccum), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("PID Action", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pidAction), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("AttitudeRollMatters ", GUILayout.ExpandWidth(true)); GUILayout.Label(core.attitude.attitudeRollMatters ? "true" : "false", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d torque = new Vector3d( vesselState.torqueAvailable.x + vesselState.torqueThrustPYAvailable * vessel.ctrlState.mainThrottle, vesselState.torqueAvailable.y, vesselState.torqueAvailable.z + vesselState.torqueThrustPYAvailable * vessel.ctrlState.mainThrottle ); GUILayout.BeginHorizontal(); GUILayout.Label("torque", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(torque), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|torque|", GUILayout.ExpandWidth(true)); GUILayout.Label(torque.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d inertia = Vector3d.Scale( vesselState.angularMomentum.Sign(), Vector3d.Scale( Vector3d.Scale(vesselState.angularMomentum, vesselState.angularMomentum), Vector3d.Scale(torque, vesselState.MoI).Invert() ) ); GUILayout.BeginHorizontal(); GUILayout.Label("inertia", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(inertia), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|inertia|", GUILayout.ExpandWidth(true)); GUILayout.Label(inertia.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d ratio = Vector3d.Scale(vesselState.MoI, torque.Invert()); GUILayout.BeginHorizontal(); GUILayout.Label("|MOI| / |Torque|", GUILayout.ExpandWidth(true)); GUILayout.Label(ratio.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("fixedDeltaTime", GUILayout.ExpandWidth(true)); GUILayout.Label(TimeWarp.fixedDeltaTime.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); if (!core.attitude.Tf_autoTune) { if (core.attitude.Tf != Tf) { core.attitude.Tf = Tf; core.attitude.setPIDParameters(); } } else { if (core.attitude.TfMin != TfMin || core.attitude.TfMax != TfMax) { core.attitude.TfMin = TfMin; core.attitude.TfMax = TfMax; core.attitude.setPIDParameters(); } if (core.attitude.kpFactor != kpFactor || core.attitude.kiFactor != kiFactor || core.attitude.kdFactor != kdFactor) { core.attitude.kpFactor = kpFactor; core.attitude.kiFactor = kiFactor; core.attitude.kdFactor = kdFactor; core.attitude.setPIDParameters(); } } base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); core.GetComputerModule <MechJebModuleCustomWindowEditor>().registry.Find(i => i.id == "Toggle:AttitudeController.useSAS").DrawItem(); if (!core.attitude.useSAS) { core.attitude.Tf_autoTune = GUILayout.Toggle(core.attitude.Tf_autoTune, " Tf auto-tuning"); if (!core.attitude.Tf_autoTune) { GUILayout.Label("Larger ship do better with a larger Tf"); GuiUtils.SimpleTextBox("Tf (s)", Tf); Tf = Math.Max(0.01, Tf); } else { // pid.Kd = kpFactor / Tf; // pid.Kp = pid.Kd / (kiFactor * Math.Sqrt(2) * Tf); // pid.Ki = pid.Kp / (kpFactor * Math.Sqrt(2) * Tf); GUILayout.BeginHorizontal(); GUILayout.Label("Tf", GUILayout.ExpandWidth(true)); GUILayout.Label(core.attitude.Tf.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Tf range"); GuiUtils.SimpleTextBox("min", TfMin, "", 50); TfMin = Math.Max(TfMin, 0.01); GuiUtils.SimpleTextBox("max", TfMax, "", 50); TfMax = Math.Max(TfMax, 0.01); GUILayout.EndHorizontal(); GUILayout.Label("PID factors"); GuiUtils.SimpleTextBox("Kd = ", kdFactor, " / Tf", 50); kdFactor = Math.Max(kdFactor, 0.01); GuiUtils.SimpleTextBox("Kp = pid.Kd / (", kpFactor, " * Math.Sqrt(2) * Tf)", 50); kpFactor = Math.Max(kpFactor, 0.01); GuiUtils.SimpleTextBox("Ki = pid.Kp / (", kiFactor, " * Math.Sqrt(2) * Tf)", 50); kiFactor = Math.Max(kiFactor, 0.01); } core.attitude.RCS_auto = GUILayout.Toggle(core.attitude.RCS_auto, " RCS auto mode"); showInfos = GUILayout.Toggle(showInfos, "Show Numbers"); if (showInfos) { GUILayout.BeginHorizontal(); GUILayout.Label("Kp, Ki, Kd", GUILayout.ExpandWidth(true)); GUILayout.Label( core.attitude.pid.Kp.ToString("F3") + ", " + core.attitude.pid.Ki.ToString("F3") + ", " + core.attitude.pid.Kd.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("prop. action.", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.propAct), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("deriv. action", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.derivativeAct), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("integral action.", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.intAccum), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("PID Action", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pidAction), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("AttitudeRollMatters ", GUILayout.ExpandWidth(true)); GUILayout.Label(core.attitude.attitudeRollMatters ? "true" : "false", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d torque = vesselState.torqueAvailable + vesselState.torqueFromEngine * vessel.ctrlState.mainThrottle; GUILayout.BeginHorizontal(); GUILayout.Label("torque", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(torque), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|torque|", GUILayout.ExpandWidth(true)); GUILayout.Label(torque.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d inertia = Vector3d.Scale( vesselState.angularMomentum.Sign(), Vector3d.Scale( Vector3d.Scale(vesselState.angularMomentum, vesselState.angularMomentum), Vector3d.Scale(torque, vesselState.MoI).Invert() ) ); GUILayout.BeginHorizontal(); GUILayout.Label("inertia", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(inertia), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|inertia|", GUILayout.ExpandWidth(true)); GUILayout.Label(inertia.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d ratio = Vector3d.Scale(vesselState.MoI, torque.Invert()); GUILayout.BeginHorizontal(); GUILayout.Label("|MOI| / |Torque|", GUILayout.ExpandWidth(true)); GUILayout.Label(ratio.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("fixedDeltaTime", GUILayout.ExpandWidth(true)); GUILayout.Label(TimeWarp.fixedDeltaTime.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } } MechJebModuleAttitudeController.useCoMVelocity = GUILayout.Toggle(MechJebModuleAttitudeController.useCoMVelocity, "Use CoM velocity instead of stock"); MechJebModuleDebugArrows arrows = core.GetComputerModule <MechJebModuleDebugArrows>(); GuiUtils.SimpleTextBox("Arrows length", arrows.arrowsLength, "", 50); arrows.seeThrough = GUILayout.Toggle(arrows.seeThrough, "Visible through object"); GUILayout.BeginHorizontal(); arrows.comSphereActive = GUILayout.Toggle(arrows.comSphereActive, "Display the CoM. Radius of ", GUILayout.ExpandWidth(false)); arrows.comSphereRadius.text = GUILayout.TextField(arrows.comSphereRadius.text, GUILayout.Width(40)); GUILayout.EndHorizontal(); arrows.displayAtCoM = GUILayout.Toggle(arrows.displayAtCoM, "Arrows origins at the CoM"); arrows.podSrfVelocityArrowActive = GUILayout.Toggle(arrows.podSrfVelocityArrowActive, "Pod Surface Velocity (yellow)"); arrows.comSrfVelocityArrowActive = GUILayout.Toggle(arrows.comSrfVelocityArrowActive, "CoM Surface Velocity (green)"); arrows.podObtVelocityArrowActive = GUILayout.Toggle(arrows.podObtVelocityArrowActive, "Pod Orbital Velocity (red)"); arrows.comObtVelocityArrowActive = GUILayout.Toggle(arrows.comObtVelocityArrowActive, "CoM Orbital Velocity (orange)"); arrows.forwardArrowActive = GUILayout.Toggle(arrows.forwardArrowActive, "Command Pod Forward (Navy Blue)"); //arrows.avgForwardArrowActive = GUILayout.Toggle(arrows.avgForwardArrowActive, "Forward Avg (blue)"); arrows.requestedAttitudeArrowActive = GUILayout.Toggle(arrows.requestedAttitudeArrowActive, "Requested Attitude (Gray)"); arrows.debugArrowActive = GUILayout.Toggle(arrows.debugArrowActive, "Debug (Magenta)"); GUILayout.EndVertical(); if (!core.attitude.Tf_autoTune) { if (core.attitude.Tf != Tf) { core.attitude.Tf = Tf; core.attitude.setPIDParameters(); } } else { if (core.attitude.TfMin != TfMin || core.attitude.TfMax != TfMax) { core.attitude.TfMin = TfMin; core.attitude.TfMax = TfMax; core.attitude.setPIDParameters(); } if (core.attitude.kpFactor != kpFactor || core.attitude.kiFactor != kiFactor || core.attitude.kdFactor != kdFactor) { core.attitude.kpFactor = kpFactor; core.attitude.kiFactor = kiFactor; core.attitude.kdFactor = kdFactor; core.attitude.setPIDParameters(); } } base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); core.GetComputerModule <MechJebModuleCustomWindowEditor>().registry.Find(i => i.id == "Toggle:AttitudeController.useSAS").DrawItem(); if (!core.attitude.useSAS) { GUILayout.Label("Larger ship do better with a larger Tf"); GuiUtils.SimpleTextBox("Tf (s)", Tf); Tf = Math.Max(0.01, Tf); core.attitude.RCS_auto = GUILayout.Toggle(core.attitude.RCS_auto, " RCS auto mode"); GUILayout.BeginHorizontal(); GUILayout.Label("Kp, Ki, Kd", GUILayout.ExpandWidth(true)); GUILayout.Label(core.attitude.pid.Kp.ToString("F3") + ", " + core.attitude.pid.Ki.ToString("F3") + ", " + core.attitude.pid.Kd.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("prop. action.", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.propAct), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("deriv. action", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.derivativeAct), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("integral action.", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.intAccum), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("PID Action", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pidAction), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("AttitudeRollMatters ", GUILayout.ExpandWidth(true)); GUILayout.Label(core.attitude.attitudeRollMatters ? "true" : "false", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d torque = new Vector3d( vesselState.torqueAvailable.x + vesselState.torqueThrustPYAvailable * vessel.ctrlState.mainThrottle, vesselState.torqueAvailable.y, vesselState.torqueAvailable.z + vesselState.torqueThrustPYAvailable * vessel.ctrlState.mainThrottle ); GUILayout.BeginHorizontal(); GUILayout.Label("torque", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(torque), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|torque|", GUILayout.ExpandWidth(true)); GUILayout.Label(torque.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d inertia = Vector3d.Scale( vesselState.angularMomentum.Sign(), Vector3d.Scale( Vector3d.Scale(vesselState.angularMomentum, vesselState.angularMomentum), Vector3d.Scale(torque, vesselState.MoI).Invert() ) ); GUILayout.BeginHorizontal(); GUILayout.Label("inertia", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(inertia), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|inertia|", GUILayout.ExpandWidth(true)); GUILayout.Label(inertia.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); if ((core.attitude.Tf != Tf)) { core.attitude.Tf = Tf; double Kd = 0.53 / Tf; double Kp = Kd / (3 * Math.Sqrt(2) * Tf); double Ki = Kp / (12 * Math.Sqrt(2) * Tf); core.attitude.pid = new PIDControllerV2(Kp, Ki, Kd, 1, -1); } base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); //core.GetComputerModule<MechJebModuleCustomWindowEditor>().registry.Find(i => i.id == "Toggle:AttitudeController.useSAS").DrawItem(); core.attitude.RCS_auto = GUILayout.Toggle(core.attitude.RCS_auto, " RCS auto mode"); int currentController = core.attitude.activeController; if (GUILayout.Toggle(currentController == 0, "MJAttitudeController")) { currentController = 0; } if (GUILayout.Toggle(currentController == 1, "KosAttitudeController")) { currentController = 1; } if (GUILayout.Toggle(currentController == 2, "HybridController")) { currentController = 2; } GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); core.attitude.Controller.GUI(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (currentController != core.attitude.activeController) { core.attitude.SetActiveController(currentController); } showInfos = GUILayout.Toggle(showInfos, "Show Numbers"); if (showInfos) { GUILayout.BeginHorizontal(); GUILayout.Label("Axis Control ", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.AxisState, "F0"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Torque", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + core.attitude.torque.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(core.attitude.torque), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("torqueReactionSpeed", GUILayout.ExpandWidth(true)); GUILayout.Label( "|" + vesselState.torqueReactionSpeed.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vesselState.torqueReactionSpeed), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d ratio = Vector3d.Scale(vesselState.MoI, core.attitude.torque.InvertNoNaN()); GUILayout.BeginHorizontal(); GUILayout.Label("MOI / torque", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + ratio.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(ratio), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("MOI", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + vesselState.MoI.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vesselState.MoI), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Angular Velocity", GUILayout.ExpandWidth(true)); GUILayout.Label("|" + vessel.angularVelocity.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vessel.angularVelocity), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Angular M", GUILayout.ExpandWidth(true)); GUILayout.Label( "|" + vesselState.angularMomentum.magnitude.ToString("F3") + "| " + MuUtils.PrettyPrint(vesselState.angularMomentum), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("fixedDeltaTime", GUILayout.ExpandWidth(true)); GUILayout.Label(TimeWarp.fixedDeltaTime.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } MechJebModuleDebugArrows arrows = core.GetComputerModule <MechJebModuleDebugArrows>(); GuiUtils.SimpleTextBox("Arrows length", arrows.arrowsLength, "", 50); arrows.seeThrough = GUILayout.Toggle(arrows.seeThrough, "Visible through object"); arrows.comSphereActive = GUILayout.Toggle(arrows.comSphereActive, "Display the CoM", GUILayout.ExpandWidth(false)); arrows.colSphereActive = GUILayout.Toggle(arrows.colSphereActive, "Display the CoL", GUILayout.ExpandWidth(false)); arrows.cotSphereActive = GUILayout.Toggle(arrows.cotSphereActive, "Display the CoT", GUILayout.ExpandWidth(false)); GUILayout.BeginHorizontal(); GUILayout.Label("Radius of Sphere", GUILayout.ExpandWidth(true)); arrows.comSphereRadius.text = GUILayout.TextField(arrows.comSphereRadius.text, GUILayout.Width(40)); GUILayout.EndHorizontal(); arrows.displayAtCoM = GUILayout.Toggle(arrows.displayAtCoM, "Arrows origins at the CoM"); arrows.srfVelocityArrowActive = GUILayout.Toggle(arrows.srfVelocityArrowActive, "Pod Surface Velocity (green)"); arrows.obtVelocityArrowActive = GUILayout.Toggle(arrows.obtVelocityArrowActive, "Pod Orbital Velocity (red)"); arrows.dotArrowActive = GUILayout.Toggle(arrows.dotArrowActive, "Direction of Thrust (purple pink)"); arrows.forwardArrowActive = GUILayout.Toggle(arrows.forwardArrowActive, "Command Pod Forward (electric blue)"); //arrows.avgForwardArrowActive = GUILayout.Toggle(arrows.avgForwardArrowActive, "Forward Avg (blue)"); arrows.requestedAttitudeArrowActive = GUILayout.Toggle(arrows.requestedAttitudeArrowActive, "Requested Attitude (gray)"); arrows.debugArrowActive = GUILayout.Toggle(arrows.debugArrowActive, "Debug (magenta)"); arrows.debugArrow2Active = GUILayout.Toggle(arrows.debugArrow2Active, "Debug2 (light blue)"); GUILayout.EndVertical(); base.WindowGUI(windowID); }
public virtual Vector3d Drag(Vector3d vesselVelocity, double dragFactor, float mach) { if (shieldedFromAirstream || noDrag) { return(Vector3d.zero); } Vector3d dragVectorDirLocal = -(vesselToPart * vesselVelocity).normalized; cubes.SetDrag(dragVectorDirLocal, mach); Vector3d drag = -vesselVelocity.normalized * cubes.AreaDrag * dragFactor; #if DEBUG && false bool delta = false; string msg = oPart.name; if (vesselVelocity.sqrMagnitude > 1 && dynamicPressurekPa - oPart.dynamicPressurekPa > oPart.dynamicPressurekPa * 0.1) { msg += " dynamicPressurekPa " + dynamicPressurekPa.ToString("f4") + " vs " + oPart.dynamicPressurekPa.ToString("f4"); delta = true; } //if (vesselVelocity.sqrMagnitude > 1 && cubes.AreaDrag - oPart.DragCubes.AreaDrag > oPart.DragCubes.AreaDrag * 0.1) if (vesselVelocity.sqrMagnitude > 1) { msg += "\n AreaDrag " + cubes.AreaDrag.ToString("f4") + " vs " + oPart.DragCubes.AreaDrag.ToString("f4"); //msg += "\n mach " + mach.ToString("f4") + " vs " + oPart.machNumber.ToString("f4"); msg += "\n dragDir " + MuUtils.PrettyPrint(dragDir) + " vs " + MuUtils.PrettyPrint(oPart.dragVectorDirLocal) + " " + Vector3.Angle(dragDir, oPart.dragVectorDirLocal).ToString("F3") + "°"; //msg += "\n dragVel " + MuUtils.PrettyPrint(vesselVelocity.normalized) + " vs " + MuUtils.PrettyPrint(oPart.dragVector.normalized) + " " + Vector3.Angle(vesselVelocity.normalized, oPart.dragVector).ToString("F3") + "°"; msg += "\n Real° " + MuUtils.PrettyPrint(oPart.dragVectorDirLocal) + " " + Vector3.Angle(oPart.dragVectorDirLocal, Vector3.down).ToString("F3") + "°"; msg += "\n Sim° " + MuUtils.PrettyPrint(dragDir) + " " + Vector3.Angle(dragDir, Vector3.down).ToString("F3") + "°"; msg += "\n toUp " + MuUtils.PrettyPrint(vesselToPart * Vector3.up) + Vector3.Angle(vesselToPart * Vector3.up, Vector3.up).ToString("F3") + "°"; Vector3 quatUp = vesselToPart * Vector3.up; Vector3 shipUp = oPart.vessel.transform.InverseTransformDirection(oPart.transform.up); msg += "\n Ups " + MuUtils.PrettyPrint(quatUp) + " vs " + MuUtils.PrettyPrint(shipUp) + " " + Vector3.Angle(quatUp, shipUp).ToString("F3") + "°"; //msg += "\n AreaOccluded "; //for (int i = 0; i < 6; i++) //{ // msg += cubes.AreaOccluded[i].ToString("F3") + "/" + oPart.DragCubes.AreaOccluded[i].ToString("F3") + " "; //} //msg += "\n WeightedDrag "; //for (int i = 0; i < 6; i++) //{ // msg += cubes.WeightedDrag[i].ToString("F3") + "/" + oPart.DragCubes.WeightedDrag[i].ToString("F3") + " "; //} msg += "\n vesselToPart " + MuUtils.PrettyPrint(vesselToPart.eulerAngles); delta = true; } if (delta) { Log.dbg(msg); } #endif return(drag); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GuiUtils.SimpleTextBox("Kp", Kp); GuiUtils.SimpleTextBox("Ki", Ki); GuiUtils.SimpleTextBox("Kd", Kd); GuiUtils.SimpleTextBox("Tf", Tf); GuiUtils.SimpleTextBox("Ki_limit", Ki_limit); GuiUtils.SimpleTextBox("Factor", factor); GUILayout.BeginHorizontal(); GUILayout.Label("prevError", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.prevError), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|prevError|", GUILayout.ExpandWidth(true)); GUILayout.Label(core.attitude.pid.prevError.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("intAccum", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(core.attitude.pid.intAccum), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|intAccum|", GUILayout.ExpandWidth(true)); GUILayout.Label(core.attitude.pid.intAccum.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); double precision = Math.Max(0.5, Math.Min(10.0, (vesselState.torquePYAvailable + vesselState.torqueThrustPYAvailable * vessel.ctrlState.mainThrottle) * 20.0 / vesselState.MoI.magnitude)); GUILayout.BeginHorizontal(); GUILayout.Label("precision", GUILayout.ExpandWidth(true)); GUILayout.Label(precision.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d torque = new Vector3d( vesselState.torquePYAvailable + vesselState.torqueThrustPYAvailable * vessel.ctrlState.mainThrottle, vesselState.torqueRAvailable, vesselState.torquePYAvailable + vesselState.torqueThrustPYAvailable * vessel.ctrlState.mainThrottle ); GUILayout.BeginHorizontal(); GUILayout.Label("torque", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(torque), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|torque|", GUILayout.ExpandWidth(true)); GUILayout.Label(torque.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); Vector3d inertia = Vector3d.Scale( vesselState.angularMomentum.Sign(), Vector3d.Scale( Vector3d.Scale(vesselState.angularMomentum, vesselState.angularMomentum), Vector3d.Scale(torque, vesselState.MoI).Invert() ) ); GUILayout.BeginHorizontal(); GUILayout.Label("inertia", GUILayout.ExpandWidth(true)); GUILayout.Label(MuUtils.PrettyPrint(inertia), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("|inertia|", GUILayout.ExpandWidth(true)); GUILayout.Label(inertia.magnitude.ToString("F3"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); if ((Kp != core.attitude.Kp) || (Ki != core.attitude.Ki) || (Kd != core.attitude.Kd)) { core.attitude.Kp = Kp; core.attitude.Ki = Ki; core.attitude.Kd = Kd; core.attitude.Ki_limit = Ki_limit; core.attitude.pid = new PIDControllerV(Kp, Ki, Kd, Ki_limit, -Ki_limit); } core.attitude.drive_factor = factor; core.attitude.Tf = Tf; base.WindowGUI(windowID); }