public void Start() { instance = this; if (!init) { Initialise(); } // register vessel if (FlightData.thisVessel == null) { FlightData.thisVessel = FlightGlobals.ActiveVessel; } PresetManager.loadCraftAsstPreset(); Utils.GetAsst(PIDList.Aileron).InMax = 180; Utils.GetAsst(PIDList.Aileron).InMin = -180; Utils.GetAsst(PIDList.Altitude).InMin = 0; Utils.GetAsst(PIDList.Throttle).InMin = 0; FlightData.thisVessel.OnPostAutopilotUpdate += new FlightInputCallback(vesselController); GameEvents.onVesselChange.Add(vesselSwitch); RenderingManager.AddToPostDrawQueue(5, drawGUI); }
public static void loadAsstPreset(AsstPreset p, PilotAssistant instance) { AsstController[] c = instance.controllers; for (int i = 0; i < 8; i++) { c[i].PGain = p.PIDGains[i][0]; c[i].IGain = p.PIDGains[i][1]; c[i].DGain = p.PIDGains[i][2]; c[i].OutMin = p.PIDGains[i][3]; c[i].OutMax = p.PIDGains[i][4]; c[i].ClampLower = p.PIDGains[i][5]; c[i].ClampUpper = p.PIDGains[i][6]; c[i].Scalar = p.PIDGains[i][7]; c[i].Easing = p.PIDGains[i][8]; } Instance.activeAsstPreset = p; GeneralUI.postMessage("Loaded preset " + p.name); if (Instance.activeAsstPreset != Instance.craftPresetDict[craftDefaultName].AsstPreset) { updateCraftPreset(Instance.activeAsstPreset, instance.vesModule.vesselRef); } saveToFile(); }
/// <summary> /// loads a preset into the controllers of a PA instance /// </summary> /// <param name="p">the preset to load</param> /// <param name="asstInstance">the PA instance to load to</param> public static void LoadAsstPreset(AsstPreset p, PilotAssistant asstInstance) { if (ReferenceEquals(p, null)) { return; } Asst_PID_Controller[] c = asstInstance.controllers; for (int i = 0; i < 8; i++) { c[i].K_proportional = p.PIDGains[i][0]; c[i].K_integral = p.PIDGains[i][1]; c[i].K_derivative = p.PIDGains[i][2]; c[i].OutMin = p.PIDGains[i][3]; c[i].OutMax = p.PIDGains[i][4]; c[i].IntegralClampLower = p.PIDGains[i][5]; c[i].IntegralClampUpper = p.PIDGains[i][6]; c[i].Scalar = p.PIDGains[i][7]; c[i].Easing = p.PIDGains[i][8]; } asstInstance.activePreset = p; GeneralUI.PostMessage("Loaded preset " + p.name); if (asstInstance.activePreset.name != Instance.craftPresetDict[craftDefaultName]) { Instance.UpdateCraftPreset(asstInstance.activePreset, asstInstance.vesModule.Vessel); } SaveToFile(); }
// called on vessel load public static void loadCraftAsstPreset(PilotAssistant instance) { if (Instance.craftPresetDict.ContainsKey(FlightGlobals.ActiveVessel.vesselName) && !ReferenceEquals(Instance.craftPresetDict[FlightGlobals.ActiveVessel.vesselName].AsstPreset, null)) { loadAsstPreset(Instance.craftPresetDict[FlightGlobals.ActiveVessel.vesselName].AsstPreset, instance); } else { loadAsstPreset(Instance.craftPresetDict[craftDefaultName].AsstPreset, instance); } }
/// <summary> /// called on vessel load to load the correct preset for the vessel being flown /// </summary> /// <param name="instance">The instance to load for</param> public void LoadCraftAsstPreset(PilotAssistant instance) { Logger.Log("loading preset for craft " + instance.Vessel.name); Logger.Log(craftPresetDict.TryGetValue(instance.Vessel.vesselName, out string presetName) + " " + presetName); if (craftPresetDict.TryGetValue(instance.Vessel.vesselName, out presetName)) { LoadAsstPreset(presetName, instance); } else { LoadAsstPreset(Instance.craftPresetDict[craftDefaultName], instance); } }
public static void updateAsstPreset(PilotAssistant instance) { Instance.activeAsstPreset.Update(instance.controllers); saveToFile(); }