diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONHybridStrategyParameters.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONHybridStrategyParameters.cs index 716587fbaf8478a0bc3af92cd311ffc91807a111..2309583af933986c7985a94a16fdf31e9ad5d700 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONHybridStrategyParameters.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONHybridStrategyParameters.cs @@ -45,9 +45,10 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON public double EquivalenceFactorDischarge => double.NaN; public double EquivalenceFactorCharge => double.NaN; - public double MinSoC { get; } + public double MinSoC => Body.GetEx<double>("MinSoC") / 100.0; + public double MaxSoC => double.NaN; - public double TargetSoC { get; } + public double TargetSoC => Body.GetEx<double>("TargetSoC") / 100.0; public Second MinimumICEOnTime => null; public Second AuxBufferTime => null; public Second AuxBufferChargeTime => null; diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs index 4429f4c63da3a522cf746eb1e983a405bd6fb93e..1566c2b581fa1223d73db72618b4053532279aaf 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs @@ -744,8 +744,12 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl container.ModData?.AddElectricMotor(pos); ctl.AddElectricMotor(pos, motorData.Item2); var motor = new ElectricMotor(container, motorData.Item2, ctl.ElectricMotorControl(pos), pos); - motor.Connect(es); - return motor; + if (pos == PowertrainPosition.GEN) { + es.Connect(new GensetChargerAdapter(motor)); + } else { + motor.Connect(es); + } + return motor; } private static IElectricMotor GetElectricMachine(PowertrainPosition pos, diff --git a/VectoCore/VectoCore/Models/SimulationComponent/IElectricEnergyStorage.cs b/VectoCore/VectoCore/Models/SimulationComponent/IElectricEnergyStorage.cs index d3b35cbfb0bc8137aa61ada58366f22162d4b7bb..8a860cbf9a337185cf483d2eabd2c3dab7ebf78b 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/IElectricEnergyStorage.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/IElectricEnergyStorage.cs @@ -2,6 +2,7 @@ using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation.DataBus; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; namespace TUGraz.VectoCore.Models.SimulationComponent { @@ -21,6 +22,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent public interface IElectricSystem : IElectricSystemInfo { IElectricSystemResponse Request(Second absTime, Second dt, Watt powerDemand, bool dryRun = false); + void Connect(IElectricChargerPort charger); } public interface IElectricEnergyStorage : IBatteryProvider, IRESSInfo diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/GensetChargerAdapter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/GensetChargerAdapter.cs index a3d464490b92d65f22a17a9b1ba257001e3ae5dd..0a38a67fde8b6c1647d3bb04f5f4c5081a9982ea 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/GensetChargerAdapter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/GensetChargerAdapter.cs @@ -68,6 +68,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl }; } + public void Connect(IElectricChargerPort charger) + { + throw new System.NotImplementedException(); + } + #endregion } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/SerialHybridController.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/SerialHybridController.cs index 2318a8ca84e9ece210ad7e05a718a9ad2cf01351..deef15113bcf8e5e2c42b93f00359d9af02242d5 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/SerialHybridController.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/SerialHybridController.cs @@ -67,65 +67,89 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, bool dryRun) { - var strategyResponse = Strategy.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); - - if (strategyResponse is HybridStrategyLimitedResponse ovl) { - if (dryRun) { - return new ResponseDryRun(this) { - DeltaDragLoad = ovl.Delta, - DeltaFullLoad = ovl.Delta, - // TODO! delta full/drag torque - DeltaEngineSpeed = ovl.DeltaEngineSpeed, - Gearbox = { - InputTorque = ovl.GearboxResponse?.InputTorque, - InputSpeed = ovl.GearboxResponse?.InputSpeed, - OutputTorque = ovl.GearboxResponse?.OutputTorque, - OutputSpeed = ovl.GearboxResponse?.OutputSpeed, - PowerRequest = ovl.GearboxResponse?.PowerRequest, - Gear = ovl.GearboxResponse?.Gear - } + var retry = false; + var retryCount = 0; + IResponse retVal; + do { + if (retryCount > 10) { + throw new VectoException("SerialHybridStrategy: retry count exceeded! {0}", DebugData); + } + retry = false; + + var strategyResponse = Strategy.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); + + if (strategyResponse is HybridStrategyLimitedResponse ovl) { + if (dryRun) { + return new ResponseDryRun(this) { + DeltaDragLoad = ovl.Delta, + DeltaFullLoad = ovl.Delta, + // TODO! delta full/drag torque + DeltaEngineSpeed = ovl.DeltaEngineSpeed, + Gearbox = { + InputTorque = ovl.GearboxResponse?.InputTorque, + InputSpeed = ovl.GearboxResponse?.InputSpeed, + OutputTorque = ovl.GearboxResponse?.OutputTorque, + OutputSpeed = ovl.GearboxResponse?.OutputSpeed, + PowerRequest = ovl.GearboxResponse?.PowerRequest, + Gear = ovl.GearboxResponse?.Gear + } + + }; + } + + return new ResponseOverload(this) { + Delta = ovl.Delta }; } - return new ResponseOverload(this) { - Delta = ovl.Delta - }; - } - - var strategySettings = strategyResponse as HybridStrategyResponse; - ApplyStrategySettings(strategySettings); - CurrentStrategySettings = strategySettings; - if (!dryRun) { - CurrentState.SetState(outTorque, outAngularVelocity, outTorque, outAngularVelocity); - CurrentState.StrategyResponse = strategySettings; - } - - // Todo: re-think for S2 configuration.... - //if (!dryRun && /*!DataBus.EngineInfo.EngineOn &&*/ strategySettings.ShiftRequired) { - // DataBus.GearboxCtl.TriggerGearshift(absTime, dt); - // _shiftStrategy.SetNextGear(strategySettings.NextGear); - // SelectedGear = strategySettings.NextGear; - // if (!DataBus.GearboxInfo.GearboxType.AutomaticTransmission()) { - // return new ResponseGearShift(this); - // } - //} + var strategySettings = strategyResponse as HybridStrategyResponse; + ApplyStrategySettings(strategySettings); + CurrentStrategySettings = strategySettings; + if (!dryRun) { + CurrentState.SetState(outTorque, outAngularVelocity, outTorque, outAngularVelocity); + CurrentState.StrategyResponse = strategySettings; + } - var gensetResponse = GenSetPort.Request(absTime, dt, 0.SI<NewtonMeter>(), _electricMotorTorque[PowertrainPosition.GEN].Item1, dryRun); + // Todo: re-think for S2 configuration.... + //if (!dryRun && /*!DataBus.EngineInfo.EngineOn &&*/ strategySettings.ShiftRequired) { + // DataBus.GearboxCtl.TriggerGearshift(absTime, dt); + // _shiftStrategy.SetNextGear(strategySettings.NextGear); + // SelectedGear = strategySettings.NextGear; + // if (!DataBus.GearboxInfo.GearboxType.AutomaticTransmission()) { + // return new ResponseGearShift(this); + // } + //} + + var gensetResponse = GenSetPort.Request(absTime, dt, 0.SI<NewtonMeter>(), + _electricMotorTorque[PowertrainPosition.GEN].Item1, dryRun); + + if (!(gensetResponse is ResponseSuccess || gensetResponse is ResponseDryRun)) { + throw new VectoException("Invalid operating point for Genset provided by strategy! {0}", + gensetResponse); + } - if (!(gensetResponse is ResponseSuccess || gensetResponse is ResponseDryRun)) { - throw new VectoException("Invalid operating point for Genset provided by strategy! {0}", gensetResponse); - } + retVal = NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); + DebugData.Add(new { + DrivingAction = DataBus.DriverInfo.DrivingAction, + StrategySettings = strategySettings, + Response = retVal, + DryRun = dryRun + }); + + if (retVal is ResponseDifferentGearEngaged) { + retryCount++; + retry = true; + Strategy.OperatingpointChangedDuringRequest(absTime, dt, outTorque, outAngularVelocity, dryRun, + retVal); + continue; + } + retVal.HybridController.StrategySettings = strategySettings; + + } while (retry); - var retVal = NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); - DebugData.Add(new { - DrivingAction = DataBus.DriverInfo.DrivingAction, - StrategySettings = strategySettings, - Response = retVal, - DryRun = dryRun - }); - retVal.HybridController.StrategySettings = strategySettings; - var modifiedResponse = Strategy.AmendResponse(retVal, absTime, dt, outTorque, outAngularVelocity, dryRun); + var modifiedResponse = + Strategy.AmendResponse(retVal, absTime, dt, outTorque, outAngularVelocity, dryRun); return modifiedResponse; } @@ -156,6 +180,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var strategyResponse = Strategy.Initialize(outTorque, outAngularVelocity); PreviousState.StrategyResponse = strategyResponse as HybridStrategyResponse; _electricMotorTorque = PreviousState.StrategyResponse.MechanicalAssistPower; + + DuringInitialize = true; + var retVal = NextComponent.Initialize(outTorque, outAngularVelocity); if (DataBus.GearboxInfo != null) { SelectedGear = DataBus.GearboxInfo.Gear; @@ -164,9 +191,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl GenSetPort.Initialize(0.SI<NewtonMeter>(), DataBus.EngineInfo.EngineIdleSpeed); + DuringInitialize = false; + return retVal; } + protected bool DuringInitialize { get; set; } + #endregion #region Implementation of IHybridControllerInfo @@ -216,8 +247,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #endregion private NewtonMeter MechanicalAssistPower(PowertrainPosition pos, Second absTime, Second dt, - NewtonMeter outTorque, PerSecond prevOutAngularVelocity, PerSecond currOutAngularVelocity, bool dryRun) + NewtonMeter outTorque, PerSecond prevOutAngularVelocity, PerSecond currOutAngularVelocity, NewtonMeter maxDriveTorque, NewtonMeter maxRecuperationTorque, bool dryRun) { + if (DuringInitialize && pos == PowertrainPosition.BatteryElectricE2) { + return (-outTorque).LimitTo(maxDriveTorque, maxRecuperationTorque ?? VectoMath.Max(maxDriveTorque, 0.SI<NewtonMeter>())); + } + return _electricMotorTorque[pos]?.Item2; //return CurrentState.StrategyResponse.MechanicalAssistPower[pos]; @@ -277,7 +312,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl NewtonMeter maxDriveTorque, NewtonMeter maxRecuperationTorque, PowertrainPosition position, bool dryRun) { return _controller.MechanicalAssistPower(position, absTime, dt, outTorque, prevOutAngularVelocity, - currOutAngularVelocity, dryRun); + currOutAngularVelocity, maxDriveTorque, maxRecuperationTorque, dryRun); } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs index 69fd7a0294c476ad6a40b651dd6de9368c946cdc..1aa762f888dad48c003db9531ac4799f8e6b37c3 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs @@ -416,6 +416,20 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies protected DrivetrainDemand GetDrivetrainPowerDemand(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, GenSetOperatingPoint maxPowerGenset) { + if (TestPowertrain.Gearbox != null) { + var currentGear = DataBus.VehicleInfo.VehicleStopped + ? (DataBus.GearboxInfo as Gearbox).NextGear + : PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear : (DataBus.GearboxInfo as Gearbox).NextGear; + + TestPowertrain.Gearbox.PreviousState.InAngularVelocity = + (DataBus.GearboxInfo as Gearbox).PreviousState.InAngularVelocity; + TestPowertrain.Gearbox.Disengaged = (DataBus.GearboxInfo as Gearbox).Disengaged; + TestPowertrain.Gearbox.DisengageGearbox = (DataBus.GearboxInfo as Gearbox).DisengageGearbox; + TestPowertrain.Gearbox.Gear = currentGear; + TestPowertrain.Gearbox._nextGear = (DataBus.GearboxInfo as Gearbox).NextGear; + } + TestPowertrain.Container.VehiclePort.Initialize(DataBus.VehicleInfo.VehicleSpeed, DataBus.DrivingCycleInfo.RoadGradient ?? 0.SI<Radian>()); + TestPowertrain.ElectricMotor.ThermalBuffer = (DataBus.ElectricMotorInfo(EmPosition) as ElectricMotor).ThermalBuffer; TestPowertrain.ElectricMotor.DeRatingActive = @@ -441,6 +455,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies TestPowertrain.BatterySystem.PreviousState.PowerDemand = (DataBus.BatteryInfo as BatterySystem).PreviousState.PowerDemand; } + //if (TestPowertrain.Gearbox != null) { + // TestPowertrain.Gearbox.PreviousState.InAngularVelocity = + // (DataBus.GearboxInfo as Gearbox).PreviousState.InAngularVelocity; + // TestPowertrain.Gearbox.Disengaged = (DataBus.GearboxInfo as Gearbox).Disengaged; + // TestPowertrain.Gearbox.DisengageGearbox = (DataBus.GearboxInfo as Gearbox).DisengageGearbox; + // TestPowertrain.Gearbox.Gear = (DataBus.GearboxInfo as Gearbox).Gear; + // TestPowertrain.Gearbox._nextGear = (DataBus.GearboxInfo as Gearbox).NextGear; + //} + TestPowertrain.Charger.ChargingPower = maxPowerGenset.ElectricPower; TestPowertrain.HybridController.Initialize(Controller.PreviousState.OutTorque, Controller.PreviousState.OutAngularVelocity); @@ -645,7 +668,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public void OperatingpointChangedDuringRequest(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, bool dryRun, IResponse retVal) { - throw new NotImplementedException(); + } public void RepeatDrivingAction(Second absTime) diff --git a/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_S2_Job/SerialHybrid_S2.vveh b/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_S2_Job/SerialHybrid_S2.vveh index b6760f07821975ba7f40c7669eacb9c1ed24cb82..4e6c2723b5301a73a6893d559a951305e0ab0466 100644 --- a/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_S2_Job/SerialHybrid_S2.vveh +++ b/VectoCore/VectoCoreTest/TestData/Hybrids/GenericVehicle_S2_Job/SerialHybrid_S2.vveh @@ -38,10 +38,13 @@ "MechanicalEfficiency": 1 } ], - "Battery": { - "NumPacks": 2, + "Batteries": [ + { + "NumPacks": 1, + "StreamId": 0, "BatteryFile": "GenericBattery.vreess" - }, + } + ], "InitialSoC": 80, "TorqueLimits": {}, "IdlingSpeed": 0.0,