diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/HybridController.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/HybridController.cs index df2d93fe9ff9ffc0016c1fd2a7e12f0570f5cc7d..28412e0016438f0b78820c97a895a3621990990d 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/HybridController.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/HybridController.cs @@ -91,19 +91,31 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, bool dryRun = false) { - var strategySettings = Strategy.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); - ApplyStrategySettings(strategySettings); - if (!dryRun) { - CurrentState.SetState(outTorque, outAngularVelocity, outTorque, outAngularVelocity); - CurrentState.StrategyResponse = strategySettings; - } - if (!dryRun && /*!DataBus.EngineInfo.EngineOn &&*/ strategySettings.ShiftRequired) { - DataBus.GearboxCtl.TriggerGearshift(absTime, dt); - _shiftStrategy.SetNextGear(strategySettings.NextGear); - return new ResponseGearShift(this); - } - var retVal = NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); - retVal.HybridController.StrategySettings = strategySettings; + var retry = false; + var retryCount = 0; + IResponse retVal; + do { + retry = false; + var strategySettings = Strategy.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); + ApplyStrategySettings(strategySettings); + if (!dryRun) { + CurrentState.SetState(outTorque, outAngularVelocity, outTorque, outAngularVelocity); + CurrentState.StrategyResponse = strategySettings; + } + if (!dryRun && /*!DataBus.EngineInfo.EngineOn &&*/ strategySettings.ShiftRequired) { + DataBus.GearboxCtl.TriggerGearshift(absTime, dt); + _shiftStrategy.SetNextGear(strategySettings.NextGear); + return new ResponseGearShift(this); + } + + retVal = NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); + retVal.HybridController.StrategySettings = strategySettings; + if (!(retVal is ResponseSuccess) && retVal.Gearbox.Gear != strategySettings.EvaluatedSolution.Gear && retryCount < 3) { + retryCount++; + retry = true; + } + } while (retry); + return retVal; } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs index dcf66b7864cade73609c9097bd276fdb2ef29cac..a1d5900e984c66d4b7018b371deeb8104b37fd01 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs @@ -246,6 +246,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return; } + if (firstResponse.ElectricMotor.MaxRecuperationTorque == null) { + eval.Add(ResponseEmOff); + return; + } + var maxRecuperation = new HybridStrategyResponse() { CombustionEngineOn = DataBus.EngineInfo.EngineOn, // AllowICEOff(absTime), GearboxInNeutral = false, @@ -276,7 +281,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var emRecuperationTq = SearchAlgorithm.Search( maxRecuperationResponse.ElectricMotor.ElectricMotorPowerMech / maxRecuperationResponse.ElectricMotor.AngularVelocity, - maxRecuperationResponse.Engine.TorqueOutDemand, maxRecuperationResponse.ElectricMotor.MaxDriveTorque * 0.1, + maxRecuperationResponse.Engine.TorqueOutDemand, maxRecuperationResponse.ElectricMotor.MaxRecuperationTorque * 0.1, getYValue: r => { var response = r as ResponseDryRun; return response.DeltaDragLoad; @@ -376,7 +381,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies { var best = eval.Where(x => !double.IsNaN(x.Score)).OrderBy(x => x.Score).FirstOrDefault(); if (best == null) { - best = eval.OrderBy(x => Math.Abs((int)currentGear - x.Gear)).FirstOrDefault(x => !DataBus.EngineCtl.CombustionEngineOn || !x.IgnoreReason.InvalidEngineSpeed()); + best = eval.OrderBy(x => Math.Abs((int)currentGear - x.Gear)).FirstOrDefault( + x => !DataBus.EngineCtl.CombustionEngineOn || !x.IgnoreReason.InvalidEngineSpeed()); if (best == null /*&& dryRun*/) { var emEngaged = (!ElectricMotorCanPropellDuringTractionInterruption || (DataBus.GearboxInfo.GearEngaged(absTime) && eval.First().Response.Gearbox.Gear != 0)); @@ -401,9 +407,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } } if ((DataBus.DriverInfo.DrivingAction == DrivingAction.Accelerate // || - /*DataBus.DriverInfo.DrivingAction == DrivingAction.Brake*/) && allUnderload) { + /*DataBus.DriverInfo.DrivingAction == DrivingAction.Brake*/) && allUnderload) { if (ElectricMotorCanPropellDuringTractionInterruption || DataBus.GearboxInfo.GearEngaged(absTime)) { - var filtered = eval.Where(x => !x.IgnoreReason.InvalidEngineSpeed()).OrderBy(x => Math.Abs((int)currentGear - x.Gear)).ToArray(); + var filtered = eval.Where(x => !x.IgnoreReason.InvalidEngineSpeed()) + .OrderBy(x => Math.Abs((int)currentGear - x.Gear)).ToArray(); if (!filtered.Any()) { filtered = eval.OrderBy(x => Math.Abs((int)currentGear - x.Gear)).ToArray(); } @@ -411,6 +418,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies x => x.Setting.MechanicalAssistPower.Sum(e => e.Value ?? 0.SI<NewtonMeter>())); } } + } else { + } return best; } @@ -697,16 +706,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies TestPowertrain.Gearbox._nextGear = Controller.ShiftStrategy.NextGear; } - TestPowertrain.CombustionEngine.PreviousState.EngineOn = (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineOn; - TestPowertrain.CombustionEngine.PreviousState.EnginePower = (DataBus.EngineInfo as CombustionEngine).PreviousState.EnginePower; - TestPowertrain.CombustionEngine.PreviousState.dt = (DataBus.EngineInfo as CombustionEngine).PreviousState.dt; - TestPowertrain.CombustionEngine.PreviousState.EngineSpeed = (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineSpeed; - TestPowertrain.CombustionEngine.PreviousState.EngineTorque = (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineTorque; - TestPowertrain.CombustionEngine.PreviousState.EngineTorqueOut = (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineTorqueOut; - TestPowertrain.CombustionEngine.PreviousState.DynamicFullLoadTorque = (DataBus.EngineInfo as CombustionEngine).PreviousState.DynamicFullLoadTorque; - - TestPowertrain.Clutch.PreviousState.InAngularVelocity = - (DataBus.ClutchInfo as SwitchableClutch).PreviousState.InAngularVelocity; + //if (!PreviousState.GearboxEngaged) { + TestPowertrain.CombustionEngine.PreviousState.EngineOn = + (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineOn; + TestPowertrain.CombustionEngine.PreviousState.EnginePower = + (DataBus.EngineInfo as CombustionEngine).PreviousState.EnginePower; + TestPowertrain.CombustionEngine.PreviousState.dt = (DataBus.EngineInfo as CombustionEngine).PreviousState.dt; + TestPowertrain.CombustionEngine.PreviousState.EngineSpeed = + (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineSpeed; + TestPowertrain.CombustionEngine.PreviousState.EngineTorque = + (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineTorque; + TestPowertrain.CombustionEngine.PreviousState.EngineTorqueOut = + (DataBus.EngineInfo as CombustionEngine).PreviousState.EngineTorqueOut; + TestPowertrain.CombustionEngine.PreviousState.DynamicFullLoadTorque = + (DataBus.EngineInfo as CombustionEngine).PreviousState.DynamicFullLoadTorque; + + TestPowertrain.Gearbox.PreviousState.InAngularVelocity = + (DataBus.GearboxInfo as Gearbox).PreviousState.InAngularVelocity; + + TestPowertrain.Clutch.PreviousState.InAngularVelocity = + (DataBus.ClutchInfo as SwitchableClutch).PreviousState.InAngularVelocity; + //} if (/*nextGear != DataBus.GearboxInfo.Gear && */TestPowertrain.ElectricMotorP2 != null) { TestPowertrain.ElectricMotorP2.PreviousState.OutAngularVelocity = @@ -758,15 +778,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies tmp.IgnoreReason |= HybridConfigurationIgnoreReason.EngineSpeedBelowDownshift; } - if (!double.IsNaN(tmp.FuelCosts)) { - if (allowIceOff && resp.Engine.TorqueOutDemand.IsEqual(0)) { - // no torque from ICE requested, ICE could be turned off - tmp.FuelCosts = 0; - tmp.ICEOff = true; - } else { - tmp.FuelCosts = ModelData.EngineData.Fuels.Sum( - x => (x.ConsumptionMap.GetFuelConsumptionValue(resp.Engine.TotalTorqueDemand, resp.Engine.EngineSpeed) - * x.FuelData.LowerHeatingValueVecto * dt).Value()); + if (allowIceOff && resp.Engine.TorqueOutDemand.IsEqual(0)) { + // no torque from ICE requested, ICE could be turned off + tmp.FuelCosts = 0; + tmp.ICEOff = true; + } else { + if (!double.IsNaN(tmp.FuelCosts)) { + //if (!allowIceOff || !resp.Engine.TorqueOutDemand.IsEqual(0)) { + tmp.FuelCosts = ModelData.EngineData.Fuels.Sum( + x => (x.ConsumptionMap.GetFuelConsumptionValue(resp.Engine.TotalTorqueDemand, resp.Engine.EngineSpeed) + * x.FuelData.LowerHeatingValueVecto * dt).Value()); + //} } } tmp.BatCosts = -(resp.ElectricSystem.BatteryPowerDemand * dt).Value();