private void LoadConfig(ConfigNode node = null) { // handle config BatteryConfig batCfg = RealBatteryConfiguration.GetConfig((BatteryTypes)BatteryType); if (!batCfg.isPopulated) { batCfg = RealBatteryConfiguration.GetConfig(BatteryTypes.CFG_lead_acid); if (!batCfg.isPopulated) { throw new Exception("No default battery config for RealBattery!"); } } BatteryTech = RealBatteryConfiguration.getBatteryTypesFriendlyName((BatteryTypes)BatteryType); PowerDensity = batCfg.PowerDensity; EnergyDensity = batCfg.EnergyDensity; ChargeEfficiencyCurve = batCfg.ChargeEfficiencyCurve; //finish loading this batteries config double DischargeRate = part.mass * PowerDensity; //kW DischargeInfoEditor = String.Format("{0:F2}", DischargeRate); ChargeInfoEditor = String.Format("{0:F2}", DischargeRate * ChargeEfficiencyCurve.Evaluate(0f)); PartResource StoredCharge = part.Resources.Get("StoredCharge"); if (StoredCharge == null) { StoredCharge = part.Resources.Add("StoredCharge", 10, 10, true, true, true, true, PartResource.FlowMode.None); } StoredCharge.maxAmount = part.mass * EnergyDensity; StoredCharge.amount = SC_SOC * part.mass * EnergyDensity; // setup ECbufferRatio PartResource ElectricCharge = part.Resources.Get("ElectricCharge"); if (ElectricCharge == null) { ElectricCharge = part.Resources.Add("ElectricCharge", 10, 10, true, true, true, true, PartResource.FlowMode.Both); } ElectricCharge.maxAmount = DischargeRate; ElectricCharge.amount = DischargeRate; UIPartActionWindow[] partWins = FindObjectsOfType <UIPartActionWindow>(); foreach (UIPartActionWindow partWin in partWins) { partWin.displayDirty = true; } }
public static BatteryConfig GetConfig(BatteryTypes config) { PopulateConfig(); BatteryConfig retCfg = new BatteryConfig(); if (!Configurations.ContainsKey(config)) { retCfg.isPopulated = false; Debug.Log("RealBattery: Warning, config is not populated!"); } else { retCfg = Configurations[config]; retCfg.isPopulated = true; } return(retCfg); }
private static void PopulateConfig() { if (Configurations.Count != 0) { // Already populated return; } Debug.Log("RealBattery: Populating configuration"); BatteryConfig tempCfg; //-------Lead Acid Config START tempCfg = new BatteryConfig(); tempCfg.batteryType = BatteryTypes.CFG_lead_acid; tempCfg.PowerDensity = 400f; tempCfg.EnergyDensity = 20f; tempCfg.HighEClevel = 0.9f; tempCfg.LowEClevel = 0.1f; tempCfg.ThermalLosses = 0.1f; tempCfg.CoreTempGoal = 320f; //273 + 47°C tempCfg.ECbufferRatio = 1.0f; tempCfg.ChargeEfficiencyCurve = new FloatCurve(); tempCfg.ChargeEfficiencyCurve.Add(0.0f, 0.1f); tempCfg.ChargeEfficiencyCurve.Add(0.5f, 0.1f); tempCfg.ChargeEfficiencyCurve.Add(0.8f, 0.08f); tempCfg.ChargeEfficiencyCurve.Add(1.0f, 0.05f); Configurations.Add(tempCfg.batteryType, tempCfg); //-------Lead Acid Config END //-------Lead Acid Config START tempCfg = new BatteryConfig(); tempCfg.batteryType = BatteryTypes.CFG_lead_acid_singleUse; tempCfg.PowerDensity = 400f; tempCfg.EnergyDensity = 20f; tempCfg.HighEClevel = 0.9f; tempCfg.LowEClevel = 0.1f; tempCfg.ThermalLosses = 0.1f; tempCfg.CoreTempGoal = 320f; //273 + 47°C tempCfg.ECbufferRatio = 1.0f; tempCfg.ChargeEfficiencyCurve = new FloatCurve(); tempCfg.ChargeEfficiencyCurve.Add(0.0f, 0.1f); tempCfg.ChargeEfficiencyCurve.Add(0.5f, 0.1f); tempCfg.ChargeEfficiencyCurve.Add(0.8f, 0.08f); tempCfg.ChargeEfficiencyCurve.Add(1.0f, 0.05f); Configurations.Add(tempCfg.batteryType, tempCfg); //-------Lead Acid Config END //-------Li Ion Config START tempCfg = new BatteryConfig(); tempCfg.batteryType = BatteryTypes.CFG_li_ion; tempCfg.PowerDensity = 2000f; tempCfg.EnergyDensity = 200f; tempCfg.HighEClevel = 0.9f; tempCfg.LowEClevel = 0.1f; tempCfg.ThermalLosses = 0.1f; tempCfg.CoreTempGoal = 340f; //273 + 67°C; 80°C thermal fuse, 140°C Meltdown tempCfg.ECbufferRatio = 1.0f; tempCfg.ChargeEfficiencyCurve = new FloatCurve(); tempCfg.ChargeEfficiencyCurve.Add(0.0f, 1.0f); tempCfg.ChargeEfficiencyCurve.Add(0.5f, 1.0f); tempCfg.ChargeEfficiencyCurve.Add(0.9f, 0.8f); tempCfg.ChargeEfficiencyCurve.Add(1.0f, 0.7f); Configurations.Add(tempCfg.batteryType, tempCfg); //-------Li Ion Config END }