diff --git a/Directory.Build.targets b/Directory.Build.targets index adb0bbe5ce19a05275019ed062324e91848e840d..c9c06bc38267f03fab4173b475beef36eb1e5c83 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -20,13 +20,14 @@ <ItemGroup> <!-- All files for net45 --> - <Net45VECTO Include="$(SolutionDir)VECTO\bin\Release\net45\*.exe*"/> + <Net45VECTO Include="$(SolutionDir)VECTO\bin\Release\net45\*.exe"/> <Net45VECTO Include="$(SolutionDir)VECTO\bin\Release\net45\*.dll*"/> - <Net45HashingTool Include="$(SolutionDir)HashingTool\bin\Release\net45\*.exe*"/> + <Net45Vecto Include="$(SolutionDir)VECTO\bin\Release\net45\nlog.config"/> + <Net45HashingTool Include="$(SolutionDir)HashingTool\bin\Release\net45\*.exe"/> <Net45HashingTool Include="$(SolutionDir)HashingTool\bin\Release\net45\*.dll*"/> - <Net45HashingTool Include="$(SolutionDir)HashingCmd\bin\Release\net45\*.exe*"/> + <Net45HashingTool Include="$(SolutionDir)HashingCmd\bin\Release\net45\*.exe"/> <Net45HashingTool Include="$(SolutionDir)HashingCmd\bin\Release\net45\*.dll*"/> - <Net45VectoCommandLine Include="$(SolutionDir)VectoConsole\bin\Release\net45\*.exe*"/> + <Net45VectoCommandLine Include="$(SolutionDir)VectoConsole\bin\Release\net45\*.exe"/> <Net45VectoCommandLine Include="$(SolutionDir)VectoConsole\bin\Release\net45\*.dll*"/> </ItemGroup> <Copy SourceFiles="@(Net45VectoCommandLine)" DestinationFolder="$(DeployPath)net45"/> @@ -35,13 +36,14 @@ <ItemGroup> <!-- All files for net48 --> - <Net48VECTO Include="$(SolutionDir)VECTO\bin\Release\net48\*.exe*"/> + <Net48VECTO Include="$(SolutionDir)VECTO\bin\Release\net48\*.exe"/> <Net48VECTO Include="$(SolutionDir)VECTO\bin\Release\net48\*.dll*"/> - <Net48HashingTool Include="$(SolutionDir)HashingCmd\bin\Release\net48\*.exe*"/> + <Net48Vecto Include="$(SolutionDir)VECTO\bin\Release\net48\nlog.config"/> + <Net48HashingTool Include="$(SolutionDir)HashingCmd\bin\Release\net48\*.exe"/> <Net48HashingTool Include="$(SolutionDir)HashingCmd\bin\Release\net48\*.dll*"/> - <Net48VectoCommandLine Include="$(SolutionDir)VectoConsole\bin\Release\net48\*.exe*"/> + <Net48VectoCommandLine Include="$(SolutionDir)VectoConsole\bin\Release\net48\*.exe"/> <Net48VectoCommandLine Include="$(SolutionDir)VectoConsole\bin\Release\net48\*.dll*"/> - <Net48VectoMultistage Include="$(SolutionDir)VECTO3GUI2020\bin\Release\net48\*.exe*"/> + <Net48VectoMultistage Include="$(SolutionDir)VECTO3GUI2020\bin\Release\net48\*.exe"/> <Net48VectoMultistage Include="$(SolutionDir)VECTO3GUI2020\bin\Release\net48\*.dll*"/> </ItemGroup> <Copy SourceFiles="@(Net48VectoCommandLine)" DestinationFolder="$(DeployPath)net48"/> @@ -53,6 +55,7 @@ <!-- All files for net6.0 --> <Vecto Include="$(SolutionDir)VECTO\bin\Release\net6.0-windows\VECTO.*" Exclude="*.dev.json"/> <Vecto Include="$(SolutionDir)VECTO\bin\Release\net6.0-windows\*.dll"/> + <Vecto Include="$(SolutionDir)VECTO\bin\Release\net6.0-windows\nlog.config"/> <VectoRuntimes Include="$(SolutionDir)VECTO\bin\Release\net6.0-windows\runtimes\**\*.*"/> <VectoCommandLine Include="$(SolutionDir)VectoConsole\bin\Release\net6.0\vectocmd.*" Exclude="*.dev.json"/> <VectoCommandLine Include="$(SolutionDir)VectoConsole\bin\Release\net6.0\*.dll"/> diff --git a/VECTO/GUI/MainForm.vb b/VECTO/GUI/MainForm.vb index dcd784a7afba838e843472e0e2d064175780447e..252bd4402bc425526ab7c668d781d133eec6330f 100644 --- a/VECTO/GUI/MainForm.vb +++ b/VECTO/GUI/MainForm.vb @@ -29,16 +29,14 @@ ' Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology ' -Imports System.Collections.Generic +Imports System.Collections.Concurrent Imports System.ComponentModel Imports System.IO -Imports System.Linq Imports TUGraz.VectoCore.Models.Simulation.Impl Imports TUGraz.VectoCore.InputData.FileIO.JSON Imports System.Text Imports System.Threading Imports System.Xml -Imports System.Xml.Linq Imports Microsoft.VisualBasic.FileIO Imports Ninject Imports TUGraz.VectoCommon.Exceptions @@ -50,7 +48,6 @@ Imports TUGraz.VectoCore Imports TUGraz.VectoCore.InputData.FileIO.XML Imports TUGraz.VectoCore.Models.Simulation Imports TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory -Imports TUGraz.VectoCore.Models.SimulationComponent.Data Imports TUGraz.VectoCore.OutputData Imports TUGraz.VectoCore.OutputData.FileIO Imports TUGraz.VectoCore.Utils @@ -274,6 +271,10 @@ Public Class MainForm _genCheckAllLock = False _genChecked = 0 + Dim logMessageTimer As New Windows.Forms.Timer(components) + logMessageTimer.Interval = 100 + AddHandler logMessageTimer.Tick, AddressOf TimerLogMessages_Tick + logMessageTimer.Start() 'Load Tabs properly (otherwise problem with ListViews) For x = 0 To TabControl1.TabCount - 1 @@ -1530,9 +1531,7 @@ lbFound: lv0.SubItems.Add(Now.ToString("HH:mm:ss.ff")) lv0.SubItems.Add(source) - If LvMsg.Items.Count > 9999 Then LvMsg.Items.RemoveAt(0) - - LogFile.WriteToLog(id, msg & vbTab & source) + Task.Run(Sub() LogFile.WriteToLog(id, msg & vbTab & source)) Select Case id @@ -1561,10 +1560,26 @@ lbFound: lv0.Tag = link End If + _logItemQueue.Enqueue(lv0) + End Sub + + Private ReadOnly _logItemQueue As New ConcurrentQueue(Of ListViewItem) - LvMsg.Items.Add(lv0) + Private Sub TimerLogMessages_Tick(sender As Object, e As EventArgs) + If Not _logItemQueue.IsEmpty Then - lv0.EnsureVisible() + LvMsg.BeginUpdate() + Dim item As ListViewItem = Nothing + While _logItemQueue.TryDequeue(item) + LvMsg.Items.Add(item) + If LvMsg.Items.Count > 9999 Then + LvMsg.Items.RemoveAt(0) + End If + End While + + LvMsg.Items(LvMsg.Items.Count - 1).EnsureVisible() + LvMsg.EndUpdate() + End If End Sub diff --git a/VECTO/VECTO.vbproj b/VECTO/VECTO.vbproj index 85de0a6f581d1151d321495058b2d965b8a34932..f1b4d12e4aafc9fef59bdcd372acac11145797b3 100644 --- a/VECTO/VECTO.vbproj +++ b/VECTO/VECTO.vbproj @@ -14,6 +14,14 @@ <DefineTrace>false</DefineTrace> <DefineConstants /> </PropertyGroup> + <ItemGroup> + <None Remove="nlog.config" /> + </ItemGroup> + <ItemGroup> + <Content Include="nlog.config"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + </ItemGroup> <ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> diff --git a/VECTO/app.config b/VECTO/app.config deleted file mode 100644 index 49b939ba25f80d51440ce081d6cee91c67bf198b..0000000000000000000000000000000000000000 --- a/VECTO/app.config +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<configuration> - <configSections> - <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" /> - </configSections> - <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="false" throwExceptions="false" internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> - <targets async="true"> - <target xsi:type="Console" name="ConsoleLogger" error="true" /> - <target name="GUILogger" xsi:type="MethodCall" className="TUGraz.VECTO.MainForm, VECTO" methodName="LogMethod"> - <parameter layout="${level}" /> - <parameter layout="${message}" /> - </target> - <target xsi:type="File" name="LogFile" fileName="${basedir}/logs/log.txt" layout="${longdate} [${processid}:${threadid}@${machinename}] ${callsite:skipFrames=1} ${level:uppercase=true}: ${message} ${exception:format=tostring}" keepFileOpen="false" archiveFileName="${basedir}/logs/archive{#}.txt" maxArchiveFiles="1" archiveAboveSize="10000000" /> - </targets> - <rules> - <logger name="TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory" minlevel="Info" writeTo="LogFile" /> - <logger name="*" minlevel="Warn" writeTo="LogFile" /> - <logger name="*" minlevel="Warn" writeTo="GUILogger" /> - </rules> - </nlog> - <system.diagnostics> - <sources> - <source name="DefaultSource" switchName="DefaultSwitch"> - <listeners> - <add name="FileLog" /> - </listeners> - </source> - </sources> - <switches> - <add name="DefaultSwitch" value="Information" /> - </switches> - <sharedListeners> - <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" /> - </sharedListeners> - </system.diagnostics> -</configuration> \ No newline at end of file diff --git a/VECTO/nlog.config b/VECTO/nlog.config new file mode 100644 index 0000000000000000000000000000000000000000..550e301d5814b8552ec48d779b4cb520ab24ad70 --- /dev/null +++ b/VECTO/nlog.config @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="false" throwExceptions="false" internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> + <targets async="true"> + <target xsi:type="Console" name="ConsoleLogger" error="true" /> + <target name="GUILogger" xsi:type="MethodCall" className="TUGraz.VECTO.MainForm, VECTO" methodName="LogMethod"> + <parameter layout="${level}" /> + <parameter layout="${message}" /> + </target> + <target xsi:type="File" name="LogFile" fileName="${basedir}/logs/log.txt" layout="${longdate} [${processid}:${threadid}@${machinename}] ${callsite:skipFrames=1} ${level:uppercase=true}: ${message} ${exception:format=tostring}" keepFileOpen="false" archiveFileName="${basedir}/logs/archive{#}.txt" maxArchiveFiles="1" archiveAboveSize="10000000" /> + </targets> + <rules> + <logger name="TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory" minlevel="Info" writeTo="LogFile" /> + <logger name="*" minlevel="Warn" writeTo="LogFile" /> + <logger name="*" minlevel="Warn" writeTo="GUILogger" /> + </rules> +</nlog> \ No newline at end of file diff --git a/VECTO3GUI2020/Helper/Converter/EnumConverter.cs b/VECTO3GUI2020/Helper/Converter/EnumConverter.cs index 12dffc1f3c7d409f7f595d909feacf1f81361475..55f045ea57d1a8b72a43bd5cd7c8ff39faa06545 100644 --- a/VECTO3GUI2020/Helper/Converter/EnumConverter.cs +++ b/VECTO3GUI2020/Helper/Converter/EnumConverter.cs @@ -22,7 +22,7 @@ namespace VECTO3GUI2020.Helper.Converter var attributes = valueType.GetField(value.ToString())?.GetCustomAttributes( typeof(GuiLabelAttribute),false); - if (!(attributes?.First() is GuiLabelAttribute attribute)) { + if (!(attributes?.FirstOrDefault() is GuiLabelAttribute attribute)) { return value; } else { return attribute.Label; diff --git a/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLBusAuxiliariesWriter.cs b/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLBusAuxiliariesWriter.cs index 57b1a4ba9b709c05cf039b5c4026294bdb168020..7c53ed93ce9b6fe067ef365b0eec308dbbf414b0 100644 --- a/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLBusAuxiliariesWriter.cs +++ b/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLBusAuxiliariesWriter.cs @@ -64,7 +64,7 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter public override void Initialize() { - _defaultNamespace = XMLNamespaces.v2_10_2; + _defaultNamespace = XMLNamespaces.V24; _xElement = new XElement(_defaultNamespace + XMLNames.Component_Auxiliaries); } @@ -127,7 +127,7 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter { var dataElement = new XElement(_defaultNamespace + XMLNames.ComponentDataWrapper, - new XAttribute("xmlns" , XMLNamespaces.v2_10_2), + new XAttribute("xmlns" , XMLNamespaces.V24), new XAttribute(XMLNamespaces.Xsi + XMLNames.Attr_Type, "AUX_Conventional_CompletedBusType")); if (_inputData.ElectricConsumers != null) { diff --git a/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLVehicleWriter.cs b/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLVehicleWriter.cs index 43fd5a161c5a9799b7a36a305ea0eb4b3db62720..d81f3a11e18dace97d64808396d94ff9e4287074 100644 --- a/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLVehicleWriter.cs +++ b/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLVehicleWriter.cs @@ -221,7 +221,7 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter protected override void Initialize() { - _defaultNamespace = XMLNamespaces.v2_10_2; + _defaultNamespace = XMLNamespaces.V24; _Xelement = new XElement(XMLNamespaces.V20 + XMLNames.Component_Vehicle, new XAttribute("xmlns", _defaultNamespace)); diff --git a/VECTO3GUI2020/Util/XML/XMLNamespaces.cs b/VECTO3GUI2020/Util/XML/XMLNamespaces.cs index c0053b0d80b7d34c33c4a9dbcc7b337cacb49431..dc88a706c7c62a3e6df7f1f3438a267aac8bf22e 100644 --- a/VECTO3GUI2020/Util/XML/XMLNamespaces.cs +++ b/VECTO3GUI2020/Util/XML/XMLNamespaces.cs @@ -9,14 +9,15 @@ namespace VECTO3GUI2020.Util.XML public static XNamespace Xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance"); public static XNamespace Tns = "urn:tugraz:ivt:VectoAPI:DeclarationInput"; public static XNamespace Tns_v20 = Tns.NamespaceName + ":v2.0"; - public static XNamespace V26 = DeclarationDefinition + ":DEV:v2.6"; + //public static XNamespace V26 = DeclarationDefinition + ":DEV:v2.6"; public static XNamespace V21 = DeclarationDefinition + ":v2.1"; - public static XNamespace V23 = DeclarationDefinition + ":DEV:v2.3"; + public static XNamespace V23 = DeclarationDefinition + ":v2.3"; + public static XNamespace V24 = DeclarationDefinition + ":v2.4"; public static XNamespace V20 = DeclarationDefinition + ":v2.0"; public static XNamespace V10 = DeclarationDefinition + ":v1.0"; - public static XNamespace V28 = DeclarationDefinition + ":DEV:v2.8"; - public static XNamespace v2_10_1 = DeclarationDefinition + ":DEV:v2.10.1"; - public static XNamespace v2_10_2 = DeclarationDefinition + ":DEV:v2.10.2"; + //public static XNamespace V28 = DeclarationDefinition + ":DEV:v2.8"; + //public static XNamespace v2_10_1 = DeclarationDefinition + ":DEV:v2.10.1"; + //public static XNamespace v2_10_2 = DeclarationDefinition + ":DEV:v2.10.2"; public static XNamespace Di = "http://www.w3.org/2000/09/xmldsig#"; @@ -33,11 +34,8 @@ namespace VECTO3GUI2020.Util.XML { V20, "v2.0"}, { V21, "v2.1"}, { V23, "v2.3"}, - { V26, "v2.6"}, + { V24, "v2.4"}, { Di, "di"}, - { V28, "v2.8"}, - {v2_10_2, "v2.10.2"}, - {v2_10_1, "v2.10.1"} }; public static string GetPrefix(XNamespace xNamespace) diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs index 137647f0f4dd5a22a42c6fe95f3b6a44ba9ab15d..250f3ae508d10562071621c0abd6366a4c023861 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs @@ -183,8 +183,8 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation var xElement = vehicleWriter.GetElement(); - var xDoc = xElement.CreateWrapperDocument(XMLNamespaces.v2_10_2); - Debug.WriteLine(xElement.CreateWrapperDocument(XMLNamespaces.v2_10_2).ToString()); + var xDoc = xElement.CreateWrapperDocument(XMLNamespaces.V24); + Debug.WriteLine(xElement.CreateWrapperDocument(XMLNamespaces.V24).ToString()); var valid = false; diff --git a/VectoCommon/VectoCommon/Utils/SI.cs b/VectoCommon/VectoCommon/Utils/SI.cs index 38faea4cd4c9fa93298d6e4a2515ecc1ee710fca..6776282cbbc86a44f4212c74d665da2f2549d32b 100644 --- a/VectoCommon/VectoCommon/Utils/SI.cs +++ b/VectoCommon/VectoCommon/Utils/SI.cs @@ -850,7 +850,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for one per second [1/s]. /// </summary> - [DebuggerDisplay("{Val.ToString(\"F1\"),nq} [rad/s] ({AsRPM.ToString(\"F1\"),nq} [rpm)")] + [DebuggerDisplay("{Val.ToString(\"F1\"),nq} [rad/s] ({AsRPM.ToString(\"F1\"),nq} [rpm])")] public class PerSecond : SIBase<PerSecond> { private static readonly int[] Units = { 0, 0, -1, 0, 0, 0, 0 }; @@ -864,14 +864,36 @@ namespace TUGraz.VectoCommon.Utils return SIBase<PerSquareSecond>.Create(perSecond.Val / second.Value()); } + public static PerMeter operator /(PerSecond perSecond, MeterPerSecond second) + { + return SIBase<PerMeter>.Create(perSecond.Val / second.Value()); + } + public static MeterPerSecond operator *(PerSecond perSecond, Meter meter) { return SIBase<MeterPerSecond>.Create(perSecond.Val * meter.Value()); } - + public double AsRPM => Val * 60 / (2 * Math.PI); } + /// <summary> + /// SI Class for one per meter [1/m]. + /// </summary> + [DebuggerDisplay("{Val.ToString(\"F1\"),nq} [1/m]")] + public class PerMeter : SIBase<PerMeter> + { + private static readonly int[] Units = { 0, -1, 0, 0, 0, 0, 0 }; + + [DebuggerHidden] + private PerMeter(double val) : base(val, Units) { } + + public static PerSecond operator *(PerMeter perMeter, MeterPerSecond meterPerSecond) => + SIBase<PerSecond>.Create(perMeter.Val * meterPerSecond.Value()); + + public static PerSecond operator *(MeterPerSecond meterPerSecond, PerMeter perMeter) => perMeter * meterPerSecond; + } + /// <summary> /// SI Class for Meter per second [m/s]. /// </summary> diff --git a/VectoCore/VectoCore/Configuration/Constants.cs b/VectoCore/VectoCore/Configuration/Constants.cs index cd55cf98a9c245406ea3d1187e4616f1984d6164..f4df273aa7cda478f3b1c98790a79b1406fb74c0 100644 --- a/VectoCore/VectoCore/Configuration/Constants.cs +++ b/VectoCore/VectoCore/Configuration/Constants.cs @@ -282,6 +282,11 @@ namespace TUGraz.VectoCore.Configuration public static readonly Meter BrakeNextTargetDistance = 2.5.SI<Meter>(); + /// <summary> + /// used in DriverModeBrake to detect if a vehicle is already below the speed of the brake trigger. + /// </summary> + public static readonly MeterPerSecond BrakeTriggerSpeedTolerance = 0.1.KMPHtoMeterPerSecond(); + public static readonly MeterPerSecond MinVelocityForCoast = 5.KMPHtoMeterPerSecond(); /// <summary> diff --git a/VectoCore/VectoCore/Models/BusAuxiliaries/DownstreamModules/Impl/Electrics/SimpleBattery.cs b/VectoCore/VectoCore/Models/BusAuxiliaries/DownstreamModules/Impl/Electrics/SimpleBattery.cs index 6fff2a8be4a8dcf535cdb86ffb59d39ff3118cea..2a7375c231c5ea8c72d3930b084c2a6556cad9c6 100644 --- a/VectoCore/VectoCore/Models/BusAuxiliaries/DownstreamModules/Impl/Electrics/SimpleBattery.cs +++ b/VectoCore/VectoCore/Models/BusAuxiliaries/DownstreamModules/Impl/Electrics/SimpleBattery.cs @@ -56,6 +56,12 @@ namespace TUGraz.VectoCore.Models.BusAuxiliaries.DownstreamModules.Impl.Electric } #endregion + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) => false; + + #endregion } // ######################################## @@ -114,6 +120,8 @@ namespace TUGraz.VectoCore.Models.BusAuxiliaries.DownstreamModules.Impl.Electric ConsumedEnergy = 0.SI<WattSecond>(); } public WattSecond ConsumedEnergy { get; set; } + + public State Clone() => (State)MemberwiseClone(); } #region Overrides of VectoSimulationComponent @@ -136,7 +144,17 @@ namespace TUGraz.VectoCore.Models.BusAuxiliaries.DownstreamModules.Impl.Electric } AdvanceState(); } + #endregion + #region Implementation of IUpdateable + public bool UpdateFrom(object other) { + if (other is SimpleBattery b) { + PreviousState = b.PreviousState.Clone(); + SOC = b.SOC; + return true; + } + return false; + } #endregion } } diff --git a/VectoCore/VectoCore/Models/BusAuxiliaries/Interfaces/DownstreamModules/Electrics/ISimpleBattery.cs b/VectoCore/VectoCore/Models/BusAuxiliaries/Interfaces/DownstreamModules/Electrics/ISimpleBattery.cs index 2afae59c4be801d0be66884e164fffc859df2095..1c615da59feeee6c47f6faf5c003e56862a30e91 100644 --- a/VectoCore/VectoCore/Models/BusAuxiliaries/Interfaces/DownstreamModules/Electrics/ISimpleBattery.cs +++ b/VectoCore/VectoCore/Models/BusAuxiliaries/Interfaces/DownstreamModules/Electrics/ISimpleBattery.cs @@ -1,4 +1,5 @@ using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.SimulationComponent; namespace TUGraz.VectoCore.Models.BusAuxiliaries.Interfaces.DownstreamModules.Electrics { @@ -9,7 +10,7 @@ namespace TUGraz.VectoCore.Models.BusAuxiliaries.Interfaces.DownstreamModules.El } - public interface ISimpleBattery : ISimpleBatteryInfo + public interface ISimpleBattery : ISimpleBatteryInfo, IUpdateable { WattSecond ConsumedEnergy { get; } diff --git a/VectoCore/VectoCore/Models/Simulation/DataBus/IGearboxInfo.cs b/VectoCore/VectoCore/Models/Simulation/DataBus/IGearboxInfo.cs index 481476c7796efa52764dca63c72bf5f8cda19aa1..ea6f671b0a563001a3caa80f31aedf6efff758de 100644 --- a/VectoCore/VectoCore/Models/Simulation/DataBus/IGearboxInfo.cs +++ b/VectoCore/VectoCore/Models/Simulation/DataBus/IGearboxInfo.cs @@ -78,6 +78,8 @@ namespace TUGraz.VectoCore.Models.Simulation.DataBus bool DisengageGearbox { get; } bool GearEngaged(Second absTime); + + bool RequestAfterGearshift { get; set; } } public interface IGearboxControl diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs index 0fae92d6312ad372e901b6a82813e084be0dcfcf..9a40b6810639974ccaa54a4db2b3f2405e37ff0f 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs @@ -1636,28 +1636,30 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } } - public class SimpleCharger : IElectricChargerPort + public class SimpleCharger : IElectricChargerPort, IUpdateable { #region Implementation of IElectricChargerPort + private Watt _chargingPower; + public SimpleCharger() => _chargingPower = 0.SI<Watt>(); + public Watt Initialize() => _chargingPower = 0.SI<Watt>(); + public Watt PowerDemand(Second absTime, Second dt, Watt powerDemandEletricMotor, Watt auxPower, bool dryRun) => _chargingPower; + #endregion - public Watt ChargingPower { get; set; } - - public SimpleCharger() + #region Implementation of IUpdateable + public bool UpdateFrom(object other) { - ChargingPower = 0.SI<Watt>(); - } + if (other is IElectricSystemInfo es) { + _chargingPower = es.ChargePower; + return true; + } - public Watt Initialize() - { - ChargingPower = 0.SI<Watt>(); - return ChargingPower; - } + if (other is Watt w) { + _chargingPower = w; + return true; + } - public Watt PowerDemand(Second absTime, Second dt, Watt powerDemandEletricMotor, Watt auxPower, bool dryRun) - { - return ChargingPower; + return false; } - #endregion } @@ -1864,6 +1866,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl return true; } + public bool RequestAfterGearshift { get; set; } + #endregion } diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index 182243953ca8db344caa0fa760ecda4cf0134093..ba4dc24e765f76485295b8dd39e45f9f5dcf8a29 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -198,8 +198,49 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl //todo mk20210617 use sorted list with inverse commitPriority (-commitPriority) _components = _components.OrderBy(x => x.Item1).Reverse().ToList(); } + private List<(IUpdateable, object)> ComponentUpdateList = new List<(IUpdateable, object)>(); + protected void UpdateComponentsInternal(IDataBus realContainer) + { + if (ComponentUpdateList.Any()) { + foreach (var (target, source) in ComponentUpdateList) { + target.UpdateFrom(source); + } + } else { + foreach (var (_, c) in _components) { +#if DEBUG + var found = false; +#endif + if (c is IUpdateable target) { + foreach (var (_, source) in (realContainer as VehicleContainer)._components) { + if (target.UpdateFrom(source)) { + ComponentUpdateList.Add((target, source)); +#if DEBUG + found = true; +#endif + } + } + } + +#if DEBUG + if (!found) { + Console.WriteLine("Test Component is not updateable: " + c.GetType()); + } +#endif + } + +#if DEBUG + var sourceList = ComponentUpdateList.Select(st => st.Item2).ToArray(); + foreach (var (_, source) in (realContainer as VehicleContainer)._components) { + if (!sourceList.Contains(source)){ + Console.WriteLine("Real Component is not used for update: " + source.GetType()); + } + } +#endif + ComponentUpdateList = ComponentUpdateList.Distinct().ToList(); + } + } public virtual void CommitSimulationStep(Second time, Second simulationInterval) { @@ -244,7 +285,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public virtual VectoRun.Status RunStatus { get; set; } - #endregion +#endregion public IReadOnlyCollection<VectoSimulationComponent> SimulationComponents() { @@ -285,22 +326,22 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl _gearboxInfo = new EngineOnlyGearboxInfo(this); } - #region Overrides of VehicleContainer +#region Overrides of VehicleContainer public override IMileageCounter MileageCounter => _mileageCounter; - #endregion +#endregion - #region Overrides of VehicleContainer +#region Overrides of VehicleContainer public override IVehicleInfo VehicleInfo => _vehicleInfo; - #endregion +#endregion - #region Overrides of VehicleContainer +#region Overrides of VehicleContainer public override IGearboxInfo GearboxInfo => _gearboxInfo; - #endregion +#endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/WHRCharger.cs b/VectoCore/VectoCore/Models/Simulation/Impl/WHRCharger.cs index 979140c4bf42541505cbf90fe33e3f423fca91ef..6ee398a33c537809c5005956f2c794792ff2400b 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/WHRCharger.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/WHRCharger.cs @@ -5,7 +5,7 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.Simulation.Impl { - public class WHRCharger : StatefulVectoSimulationComponent<WHRCharger.State>, IElectricChargerPort + public class WHRCharger : StatefulVectoSimulationComponent<WHRCharger.State>, IElectricChargerPort, IUpdateable { public double Efficiency { get; } @@ -71,7 +71,20 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public WattSecond GeneratedEnergy { get; set; } public WattSecond ExcessiveEnergy { get; set; } + + public State Clone() => (State)MemberwiseClone(); + } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is WHRCharger c) { + PreviousState = c.PreviousState.Clone(); + return true; + } + return false; } + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/DCDCConverter.cs b/VectoCore/VectoCore/Models/SimulationComponent/DCDCConverter.cs index c42d792ece20407478f89db7f2525e25cbf6649b..34559dde4aab10a71114be5c4f32364a79b6f22f 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/DCDCConverter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/DCDCConverter.cs @@ -8,7 +8,7 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.SimulationComponent { - public class DCDCConverter : StatefulVectoSimulationComponent<DCDCConverter.State>, IDCDCConverter + public class DCDCConverter : StatefulVectoSimulationComponent<DCDCConverter.State>, IDCDCConverter, IUpdateable { public double Efficiency { get; protected set; } @@ -90,6 +90,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent public WattSecond ConsumedEnergy { get; set; } public WattSecond MissingEnergy { get; set; } + + public State Clone() => (State)MemberwiseClone(); } + + #region Implementation of IUpdateable + public bool UpdateFrom(object other) { + if (other is DCDCConverter d) { + PreviousState = d.PreviousState.Clone(); + return true; + } + return false; + } + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/ElectricSystem.cs b/VectoCore/VectoCore/Models/SimulationComponent/ElectricSystem.cs index d4903f8f0bce7d77d53c52f467cb77f3a33ee50c..66338c293e6d96e6e450f26d251e0fee97bdb006 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/ElectricSystem.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/ElectricSystem.cs @@ -6,11 +6,13 @@ using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.SimulationComponent { - public class ElectricSystem : StatefulVectoSimulationComponent<ElectricSystem.State>, IElectricSystem, IElectricAuxConnecor, IElectricChargerConnector, IBatteryConnector + public class ElectricSystem : StatefulVectoSimulationComponent<ElectricSystem.State>, IElectricSystem, IElectricAuxConnecor, + IElectricChargerConnector, IBatteryConnector, IUpdateable { protected readonly List<IElectricAuxPort> Consumers = new List<IElectricAuxPort>(); @@ -141,7 +143,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent ConsumerPower = powerDemand; BatteryPower = batteryPower; } + + public State Clone() => (State)MemberwiseClone(); } + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is ElectricSystem s) { + PreviousState = s.PreviousState.Clone(); + return true; + } + + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/IAuxPort.cs b/VectoCore/VectoCore/Models/SimulationComponent/IAuxPort.cs index 8ffddbf456c1cf2f3f9c42112a21cddca1f8df29..04a22c88b3c5ddbf69df4769bab30d8a6c5d54df 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/IAuxPort.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/IAuxPort.cs @@ -43,7 +43,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent void Connect(IAuxPort aux); } - public interface IAuxPort + public interface IAuxPort: IUpdateable { NewtonMeter Initialize(NewtonMeter torque, PerSecond angularSpeed); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/IBrakes.cs b/VectoCore/VectoCore/Models/SimulationComponent/IBrakes.cs index 06e5019264e03483b670752220c06f5236bbe6d9..24c9b210d2348657fae37f93465e5da52abfbc37 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/IBrakes.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/IBrakes.cs @@ -33,7 +33,7 @@ using TUGraz.VectoCommon.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent { - public interface IBrakes + public interface IBrakes: IUpdateable { Watt BrakePower { get; set; } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/IUpdateable.cs b/VectoCore/VectoCore/Models/SimulationComponent/IUpdateable.cs new file mode 100644 index 0000000000000000000000000000000000000000..f60db9bb59ec3c8e23098c94fd182502cc3f25db --- /dev/null +++ b/VectoCore/VectoCore/Models/SimulationComponent/IUpdateable.cs @@ -0,0 +1,42 @@ +/* +* This file is part of VECTO. +* +* Copyright © 2012-2019 European Union +* +* Developed by Graz University of Technology, +* Institute of Internal Combustion Engines and Thermodynamics, +* Institute of Technical Informatics +* +* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved +* by the European Commission - subsequent versions of the EUPL (the "Licence"); +* You may not use VECTO except in compliance with the Licence. +* You may obtain a copy of the Licence at: +* +* https://joinup.ec.europa.eu/community/eupl/og_page/eupl +* +* Unless required by applicable law or agreed to in writing, VECTO +* distributed under the Licence is distributed on an "AS IS" basis, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the Licence for the specific language governing permissions and +* limitations under the Licence. +* +* Authors: +* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology +* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology +* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology +* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology +* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology +* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology +*/ + +namespace TUGraz.VectoCore.Models.SimulationComponent +{ + public interface IUpdateable + { + /// <summary> + /// Tries to update the internal state of this object from the other object. + /// </summary> + /// <returns>True if the update was possible. False if the update is not possible.</returns> + bool UpdateFrom(object other); + } +} \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AMTShiftStrategyOptimized.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AMTShiftStrategyOptimized.cs index 55b9974e750fb2884874cdaf446cfb27a14ee319..d63082eec148f69c0e9137a1cbfc32ed6a05a388 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AMTShiftStrategyOptimized.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AMTShiftStrategyOptimized.cs @@ -130,9 +130,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl continue; } - var estimatedEngineSpeed = (vehicleSpeedPostShift * (totalTransmissionRatio / - GearboxModelData.Gears[currentGear.Gear].Ratio * GearboxModelData.Gears[tryNextGear.Gear].Ratio)) - .Cast<PerSecond>(); + var estimatedEngineSpeed = vehicleSpeedPostShift * (totalTransmissionRatio / + GearboxModelData.Gears[currentGear.Gear].Ratio * GearboxModelData.Gears[tryNextGear.Gear].Ratio); if (estimatedEngineSpeed.IsSmaller(shiftStrategyParameters.MinEngineSpeedPostUpshift)) { continue; } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATGearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATGearbox.cs index 1de8dd3d0c4c7018288aa78a7c38708858541f93..087876ce24f6f1f24b288f591f5599b543301928 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATGearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATGearbox.cs @@ -40,17 +40,17 @@ using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.DataBus; using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; +using TUGraz.VectoCore.Models.SimulationComponent.Strategies; using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class ATGearbox : AbstractGearbox<ATGearbox.ATGearboxState>, IHybridControlledGearbox + public class ATGearbox : AbstractGearbox<ATGearbox.ATGearboxState>, IHybridControlledGearbox, IUpdateable { protected internal readonly IShiftStrategy _strategy; protected internal readonly TorqueConverter TorqueConverter; private IIdleController _idleController; - protected internal bool RequestAfterGearshift; internal WattSecond _powershiftLossEnergy; protected internal KilogramSquareMeter EngineInertia; @@ -581,8 +581,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public bool Disengaged = true; public WattSecond PowershiftLossEnergy; public NewtonMeter PowershiftLoss; + + public new ATGearboxState Clone() => (ATGearboxState)MemberwiseClone(); + } public bool SwitchToNeutral { get; set; } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) + { + if (other is ATGearbox g) { + PreviousState = g.PreviousState.Clone(); + _powershiftLossEnergy = g._powershiftLossEnergy; + LastShift = g.LastShift; + return true; + } + + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategyOptimized.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategyOptimized.cs index 472d7b0eccf667a0170d8ea79954c608538ee593..dbda13c068acc15ad117c4da3d36f8d50610c388 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategyOptimized.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategyOptimized.cs @@ -250,7 +250,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var inAngularVelocity = GearboxModelData.Gears[next.Gear].Ratio * outAngularVelocity; var totalTransmissionRatio = inAngularVelocity / (DataBus.VehicleInfo.VehicleSpeed + DataBus.DriverInfo.DriverAcceleration * dt); - var estimatedEngineSpeed = (vehicleSpeedPostShift * totalTransmissionRatio).Cast<PerSecond>(); + var estimatedEngineSpeed = vehicleSpeedPostShift * totalTransmissionRatio; if (estimatedEngineSpeed.IsSmaller(shiftStrategyParameters.MinEngineSpeedPostUpshift)) { continue; } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AbstractGearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AbstractGearbox.cs index e7b845bf7362c79d6caa4cef783f79cd4805e519..6c150c41888a239767076191a5bfa8ce02d1b2b1 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AbstractGearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AbstractGearbox.cs @@ -124,6 +124,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #endregion public abstract bool GearEngaged(Second absTime); + public bool RequestAfterGearshift { get; set; } protected bool ConsiderShiftLosses(GearshiftPosition nextGear, NewtonMeter torqueOut) { @@ -170,5 +171,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public GearshiftPosition Gear; public TransmissionLossMap.LossMapResult TorqueLossResult; public DrivingBehavior DrivingBehavior; + + public new GearboxState Clone() => (GearboxState)base.Clone(); } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs index b8c9d95da09aa07e50b7c9e7e5ba4389c4e8ebdf..dc0116d06b836915fbdf1c5007d601b744de5bb1 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs @@ -39,7 +39,7 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class AxleGear : TransmissionComponent, IAxlegear + public class AxleGear : TransmissionComponent, IAxlegear, IUpdateable { public AxleGear(IVehicleContainer container, AxleGearData modelData) : base(container, modelData.AxleGear) { } @@ -81,5 +81,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0, CurrentState.InTorque); public double Ratio => ModelData.Ratio; + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is AxleGear g) { + PreviousState = g.PreviousState.Clone(); + return true; + } + + return false; + } + + #endregion } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Battery.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Battery.cs index 2d131e2d6177c1e0abcbe683102e4037f6f22c30..c18f5f57e096b896125c9496c7fe65cf87e73a4b 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Battery.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Battery.cs @@ -14,7 +14,7 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Battery : StatefulVectoSimulationComponent<Battery.State>, IElectricEnergyStorage, IElectricEnergyStoragePort + public class Battery : StatefulVectoSimulationComponent<Battery.State>, IElectricEnergyStorage, IElectricEnergyStoragePort, IUpdateable { protected readonly BatteryData ModelData; @@ -274,8 +274,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public Watt MaxDischargePower; public Watt BatteryLoss; public Second PulseDuration; + public State Clone() => (State)MemberwiseClone(); } + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is Battery b) { + PreviousState = b.PreviousState.Clone(); + return true; + } + + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatterySystem.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatterySystem.cs index 556b71c828e5aef112c4aad7c323d2292505f708..0e3475ba42091f1d1917672aa2bec7b5a840c93d 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatterySystem.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatterySystem.cs @@ -14,9 +14,9 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class BatterySystem : StatefulVectoSimulationComponent<BatterySystem.State>, IElectricEnergyStorage, IElectricEnergyStoragePort + public class BatterySystem : StatefulVectoSimulationComponent<BatterySystem.State>, IElectricEnergyStorage, IElectricEnergyStoragePort, IUpdateable { - public class BatteryString + public class BatteryString: IUpdateable { protected readonly List<Battery> _batteries; @@ -111,6 +111,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl : MaxChargeCurrent(dt); return solutions.Where(x => Math.Sign(sign) == Math.Sign(x) && Math.Abs(x).IsSmallerOrEqual(Math.Abs(maxCurrent.Value()), 1e-3)).Min().SI<Ampere>(); } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is BatteryString bs) { + return _batteries.ZipAll(bs._batteries).All(ts => ts.Item1.UpdateFrom(ts.Item2)); + } + return false; + } + + #endregion } protected internal readonly Dictionary<int, BatteryString> Batteries = new Dictionary<int, BatteryString>(); @@ -377,6 +388,20 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public Watt MaxDischargePower; public Watt BatteryLoss; public Second PulseDuration; + public State Clone() => (State)MemberwiseClone(); + } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is BatterySystem b) { + PreviousState = b.PreviousState.Clone(); + return Batteries.All(kv => kv.Value.UpdateFrom(b.Batteries[kv.Key])); + } + + return false; } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs index bf6ef7e401733830f8742026bdc155343526774e..738460f4cfca7fe491d39f8b86b90a5e81b61b09 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs @@ -41,8 +41,7 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class Brakes : StatefulProviderComponent<SimpleComponentState, ITnOutPort, ITnInPort, ITnOutPort>, - IPowerTrainComponent, ITnOutPort, - ITnInPort, IBrakes + IPowerTrainComponent, ITnOutPort, ITnInPort, IBrakes, IUpdateable { public Watt BrakePower { get; set; } @@ -93,5 +92,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl BrakePower = 0.SI<Watt>(); base.DoCommitSimulationStep(time, simulationInterval); } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is Brakes b) { + PreviousState = b.PreviousState.Clone(); + BrakePower = b.BrakePower; + return true; + } + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs index c617ef869e79f937afe2e7001cdd4006eca09d62..a2f3f19d393ab4114d21d2e5db07ddde404363a6 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs @@ -401,6 +401,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public WattSecond MissingElectricEnergy { get; set; } public Watt ExcessiveDragPower = 0.SI<Watt>(); + + public BusAuxState Clone() => (BusAuxState)MemberwiseClone(); } public class ElectricStorageWrapper : ISimpleBatteryInfo @@ -438,5 +440,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #endregion } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is BusAuxiliariesAdapter b) { + PreviousState = b.PreviousState.Clone(); + return ElectricStorage.UpdateFrom(b.ElectricStorage); + } + + return false; + } + + #endregion } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs index 668e1523b35a4d0b139ea244d580668ffcbfaabb..d7d03ce19f404ce777e9906e1355ff79f49043d9 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs @@ -43,9 +43,8 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class - Clutch : StatefulProviderComponent<Clutch.ClutchState, ITnOutPort, ITnInPort, ITnOutPort>, IClutch, - ITnOutPort, ITnInPort + public class Clutch : StatefulProviderComponent<Clutch.ClutchState, ITnOutPort, ITnInPort, ITnOutPort>, IClutch, + ITnOutPort, ITnInPort, IUpdateable { protected readonly PerSecond _idleSpeed; protected readonly PerSecond _ratedSpeed; @@ -252,6 +251,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public Watt ClutchLoss { get; set; } public bool ICEOn { get; set; } public PerSecond ICEOnSpeed { get; set; } + public new ClutchState Clone() => (ClutchState)base.Clone(); } + + #region Implementation of IUpdateable + + public virtual bool UpdateFrom(object other) { + if (other is Clutch c) { + PreviousState = c.PreviousState.Clone(); + return true; + } + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs index 5a40c85b1062b0aa24370d894b7d5ee75130f692..a45144c5ca126b8a02fa0e5e2eacba9db14483bc 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs @@ -1178,7 +1178,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient, bool prohibitOverspeed = false) { - if (DataBus.VehicleInfo.VehicleSpeed.IsSmallerOrEqual(DriverStrategy.BrakeTrigger.NextTargetSpeed) && !DataBus.VehicleInfo.VehicleStopped) { + if (DataBus.VehicleInfo.VehicleSpeed.IsSmaller(DriverStrategy.BrakeTrigger.NextTargetSpeed, Constants.SimulationSettings.BrakeTriggerSpeedTolerance) + && !DataBus.VehicleInfo.VehicleStopped) { var retVal = HandleTargetspeedReached(absTime, ds, targetVelocity, gradient); for (var i = 0; i < 3 && retVal == null; i++) { retVal = HandleTargetspeedReached(absTime, ds, targetVelocity, gradient); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index 4f623cfa4501b73ca7c0de29522b51dafda09bff..a61d012880d55c66a6c438ce8cfda14fa67fa651 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -52,11 +52,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// </summary> public sealed class DistanceBasedDrivingCycle : StatefulProviderComponent <DistanceBasedDrivingCycle.DrivingCycleState, ISimulationOutPort, IDrivingCycleInPort, IDrivingCycleOutPort>, - IDrivingCycle, ISimulationOutPort, IDrivingCycleInPort, IDisposable + IDrivingCycle, ISimulationOutPort, IDrivingCycleInPort, IDisposable, IUpdateable { private const double LookaheadTimeSafetyMargin = 1.5; internal readonly IDrivingCycleData Data; - internal readonly DrivingCycleEnumerator CycleIntervalIterator; + internal DrivingCycleEnumerator CycleIntervalIterator; private bool _intervalProlonged; internal IdleControllerSwitcher IdleController; private Meter CycleEndDistance; @@ -579,5 +579,20 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { CycleIntervalIterator.Dispose(); } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is DistanceBasedDrivingCycle c) { + PreviousState = c.PreviousState.Clone(); + CycleIntervalIterator = c.CycleIntervalIterator; + //TODO MK-20220523 also allow updating from measuredspeeddrivingcycle? + return true; + } + + return false; + } + + #endregion } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DummyGearboxInfo.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DummyGearboxInfo.cs index 74ee79b2c1000f1b4084ef1899fc9d936ffccc2a..66cbd71d1c98257a598e418ece40099d758d9a03 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DummyGearboxInfo.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DummyGearboxInfo.cs @@ -67,6 +67,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return true; } + public bool RequestAfterGearshift { get; set; } + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs index 8e6eb79c42a418d9a4d633a9e1885531d03844f2..88247fe0a3e206243661de54853d63edebe05da7 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs @@ -9,12 +9,14 @@ using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Strategies; using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class ElectricMotor : StatefulProviderComponent<ElectricMotorState, ITnOutPort, ITnInPort, ITnOutPort>, IPowerTrainComponent, IElectricMotor, ITnOutPort, ITnInPort + public class ElectricMotor : StatefulProviderComponent<ElectricMotorState, ITnOutPort, ITnInPort, ITnOutPort>, + IPowerTrainComponent, IElectricMotor, ITnOutPort, ITnInPort, IUpdateable { protected internal IElectricSystem ElectricPower; @@ -576,6 +578,20 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { return emSpeed / ModelData.RatioADC; } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is ElectricMotor e && Position == e.Position) { + ThermalBuffer = e.ThermalBuffer; + DeRatingActive = e.DeRatingActive; + return true; + } + + return false; + } + + #endregion } public class ElectricMotorState // : SimpleComponentState @@ -603,5 +619,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public Watt ElectricPowerToBattery; + + public ElectricMotorState Clone() => (ElectricMotorState)MemberwiseClone(); } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineAuxiliary.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineAuxiliary.cs index e7f82a552ccc70b5474a6cd02d3b8de041e16a0b..18ee0611a90ad3d22da5b7c553c47f8b8dc51d49 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineAuxiliary.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/EngineAuxiliary.cs @@ -244,6 +244,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public PerSecond AngularSpeed; public Dictionary<string, Watt> PowerDemands; + + public State Clone() => (State)MemberwiseClone(); } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is EngineAuxiliary a) { + PreviousState = a.PreviousState.Clone(); + return true; + } + + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index aa931e68de0714d1a848ce8f7d7e4e6f8e07ca9a..86c5c945cb8242a1236396b93a8b5e373081235e 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -43,7 +43,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Gearbox : AbstractGearbox<GearboxState>, IHybridControlledGearbox + public class Gearbox : AbstractGearbox<GearboxState>, IHybridControlledGearbox, IUpdateable { /// <summary> /// The shift strategy. @@ -565,5 +565,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } public override Second LastShift => EngageTime; + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is Gearbox g) { + PreviousState = g.PreviousState.Clone(); + return true; + } + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/GensetChargerAdapter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/GensetChargerAdapter.cs index 0a38a67fde8b6c1647d3bb04f5f4c5081a9982ea..1a43cf623976f9edf5c99975a358bf39e53fb1ea 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/GensetChargerAdapter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/GensetChargerAdapter.cs @@ -1,10 +1,11 @@ using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.Connector.Ports.Impl; +using TUGraz.VectoCore.Models.SimulationComponent.Strategies; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class GensetChargerAdapter : IElectricChargerPort + public class GensetChargerAdapter : IElectricChargerPort, IUpdateable { protected IElectricSystem es; protected Watt PowerGenerated; @@ -75,5 +76,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #endregion } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is GenSetOperatingPoint p) { + ChargingPower = p.ElectricPower; + return true; + } + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/HybridController.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/HybridController.cs index 81a91730778d258669e80b1c3ab230f635acd7a3..0e2910e5e1eaf4937ee0ef2367616ae02e11c3a2 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/HybridController.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/HybridController.cs @@ -410,7 +410,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return _nextGear; } - protected GearshiftPosition InitStartGear(Second absTime, NewtonMeter outTorque, PerSecond outAngularVelocity) + protected virtual GearshiftPosition InitStartGear(Second absTime, NewtonMeter outTorque, PerSecond outAngularVelocity) { if (!DataBus.EngineCtl.CombustionEngineOn) { return _nextGear; @@ -617,7 +617,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public override void Disengage(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity) { } - protected GearshiftPosition InitStartGear(Second absTime, NewtonMeter outTorque, PerSecond outAngularVelocity) + protected override GearshiftPosition InitStartGear(Second absTime, NewtonMeter outTorque, PerSecond outAngularVelocity) { if (!DataBus.EngineCtl.CombustionEngineOn) { return _nextGear; diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs index 26501658c316471ababf468afa74db57fa85a8fe..c441b6e66c7928b1ab0d838551784293e8e1a6e6 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs @@ -352,10 +352,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl continue; } - var estimatedEngineSpeed = (vehicleSpeedPostShift * (totalTransmissionRatio / - GearboxModelData.Gears[currentGear.Gear].Ratio * - GearboxModelData.Gears[tryNextGear.Gear].Ratio)) - .Cast<PerSecond>(); + var estimatedEngineSpeed = vehicleSpeedPostShift * (totalTransmissionRatio / + GearboxModelData.Gears[currentGear.Gear].Ratio * GearboxModelData.Gears[tryNextGear.Gear].Ratio); if (estimatedEngineSpeed.IsSmaller(shiftStrategyParameters.MinEngineSpeedPostUpshift)) { continue; } @@ -597,9 +595,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } TestContainerSuperCap?.Initialize(DataBus.BatteryInfo.StateOfCharge); - if (TestContainerElectricSystemCharger != null) { - TestContainerElectricSystemCharger.ChargingPower = (DataBus.ElectricSystemInfo.ChargePower); - } + TestContainerElectricSystemCharger?.UpdateFrom(DataBus.ElectricSystemInfo.ChargePower); + //var pos = ModelData.ElectricMachinesData.FirstOrDefault().Item1; TestContainerElectricMotor.ThermalBuffer = diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/SimplePowertrainContainer.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/SimplePowertrainContainer.cs index b50f7d7e463308645f0d49080b280db24bd2c79d..2696b4904738e581962df417053be2ebe788e12e 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/SimplePowertrainContainer.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/SimplePowertrainContainer.cs @@ -36,5 +36,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public MeterPerSecond NextBrakeTriggerSpeed => 0.SI<MeterPerSecond>(); #endregion + + public void UpdateComponents(IDataBus realContainer) => UpdateComponentsInternal(realContainer); } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/SingleSpeedGearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/SingleSpeedGearbox.cs index 1ea17679607f375649a6d10d610bd4c98fd8b239..f52817d0e253d6a7063b64dd4c23058fc1e160e3 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/SingleSpeedGearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/SingleSpeedGearbox.cs @@ -83,6 +83,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return true; } + public bool RequestAfterGearshift { get; set; } + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/StopStartCombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/StopStartCombustionEngine.cs index 96aba3d63c58f420e2ce372c5339f89f38aef03b..767422c91aa53f0880cf6065c23500d7ca7827a2 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/StopStartCombustionEngine.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/StopStartCombustionEngine.cs @@ -12,7 +12,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class StopStartCombustionEngine : CombustionEngine + public class StopStartCombustionEngine : CombustionEngine, IUpdateable { private WattSecond EngineStartEnergy; @@ -230,6 +230,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl container[ModalResultField.P_WHR_mech_map] = 0.SI<Watt>(); container[ModalResultField.P_WHR_mech_corr] = 0.SI<Watt>(); } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) + { + if (other is CombustionEngine e) { + PreviousState = e.PreviousState; + return EngineAux.UpdateFrom(e.EngineAux); + } + return false; + } + + #endregion } public class SimplePowerrtrainCombustionEngine : StopStartCombustionEngine diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/SuperCap.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/SuperCap.cs index 041129065c6396b2a5e366e47eb03ed60b4fb1ea..bd0aa3e00d4bf82bdd00556b0eab86401e3b57a1 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/SuperCap.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/SuperCap.cs @@ -13,7 +13,7 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class SuperCap : StatefulVectoSimulationComponent<SuperCap.State>, IElectricEnergyStorage, IElectricEnergyStoragePort + public class SuperCap : StatefulVectoSimulationComponent<SuperCap.State>, IElectricEnergyStorage, IElectricEnergyStoragePort, IUpdateable { private SuperCapData ModelData; @@ -199,6 +199,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public Watt MaxChargePower; public Watt MaxDischargePower; public Watt InternalLoss; + + public State Clone() => (State)MemberwiseClone(); } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is SuperCap o) { + PreviousState = o.PreviousState.Clone(); + return true; + } + + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs index 54955db39f6ae5d4f853fbce13c490398f3040a3..a623f26eedf2044e766d7e7c05c453880c21ea40 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs @@ -49,7 +49,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class TorqueConverter : StatefulVectoSimulationComponent<TorqueConverter.TorqueConverterComponentState>, - ITnInPort, ITnOutPort, ITorqueConverter + ITnInPort, ITnOutPort, ITorqueConverter, IUpdateable { protected readonly IGearboxInfo Gearbox; protected readonly IShiftStrategy ShiftStrategy; @@ -506,6 +506,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public TorqueConverterOperatingPoint OperatingPoint; public bool IgnitionOn; + + public new TorqueConverterComponentState Clone() => (TorqueConverterComponentState)base.Clone(); } #region Implementation of ITorqueConverterControl @@ -520,6 +522,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public TorqueConverterOperatingPoint SetOperatingPoint { get; set; } + #endregion + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is TorqueConverter tc) { + PreviousState = tc.PreviousState.Clone(); + return true; + } + return false; + } + #endregion } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/TransmissionComponent.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/TransmissionComponent.cs index adf81d3165fcf0300cfa043f492587fe38e414da..8c7603946fdbaaa6331829a66a17f4e65ead80e2 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/TransmissionComponent.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/TransmissionComponent.cs @@ -49,6 +49,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public TransmissionLossMap.LossMapResult TorqueLossResult; //public NewtonMeter TorqueLoss = 0.SI<NewtonMeter>(); + public new TransmissionState Clone() => (TransmissionState)MemberwiseClone(); } protected TransmissionComponent(IVehicleContainer container, TransmissionData modelData) : base(container) diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index 1ea0ef778e71df79a4fe3a7b8ea3b06f455a56f0..3d5576124f99d3047c1eb40808b9881fcb7e42ca 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -47,8 +47,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class Vehicle : StatefulProviderComponent<Vehicle.VehicleState, IDriverDemandOutPort, IFvInPort, IFvOutPort>, - IVehicle, IMileageCounter, IFvInPort, - IDriverDemandOutPort + IVehicle, IMileageCounter, IFvInPort, IDriverDemandOutPort, IUpdateable { internal readonly VehicleData ModelData; @@ -280,6 +279,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl $"slope_res: {SlopeResistance}, " + $"air_drag: {AirDragResistance}, " + $"traction force: {VehicleTractionForce}"; + + public VehicleState Clone() => (VehicleState)MemberwiseClone(); + } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is Vehicle v) { + PreviousState = v.PreviousState.Clone(); + MaxVehicleSpeed = v.MaxVehicleSpeed; + return true; + } + return false; } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs index 6afaf44cc2d0eb9b8d351fdc9c4eeb73e37b070c..fa96f336de519ac769a24c0706f64a8097b3f752 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs @@ -40,7 +40,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class Wheels : StatefulProviderComponent<Wheels.WheelsState, IFvOutPort, ITnInPort, ITnOutPort>, IWheels, - IFvOutPort, ITnInPort + IFvOutPort, ITnInPort, IUpdateable { private readonly KilogramSquareMeter _totalWheelsInertia; @@ -49,6 +49,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public PerSecond AngularVelocity; public NewtonMeter TorqueIn; public NewtonMeter InertiaTorqueLoss; + + public WheelsState Clone() => (WheelsState)MemberwiseClone(); } public Wheels(IVehicleContainer cockpit, Meter rdyn, KilogramSquareMeter totalWheelsInertia) @@ -96,5 +98,17 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public Kilogram ReducedMassWheels => (_totalWheelsInertia / DynamicTyreRadius / DynamicTyreRadius).Cast<Kilogram>(); public Meter DynamicTyreRadius { get; } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is Wheels w) { + PreviousState = w.PreviousState.Clone(); + return true; + } + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs index 33b5db495e30054cf3643e1018c8a9489dbf1517..3c07697b96fc9afd7037d9523372584661d31266 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs @@ -6,7 +6,6 @@ using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; -using TUGraz.VectoCore.Models.BusAuxiliaries.DownstreamModules.Impl.Electrics; using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation; @@ -45,44 +44,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies protected override IResponse RequestDryRun(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, GearshiftPosition nextGear, HybridStrategyResponse cfg) { - if (DataBus.VehicleInfo.VehicleStopped) { - TestPowertrain.Gearbox.Gear = Controller.ShiftStrategy.NextGear; - } - else if (PreviousState.GearboxEngaged) { - TestPowertrain.Gearbox.Gear = DataBus.GearboxInfo.Gear; - } else { - TestPowertrain.Gearbox.Gear = Controller.ShiftStrategy.NextGear; - } + TestPowertrain.UpdateComponents(); + TestPowertrain.Gearbox.Gear = DataBus.VehicleInfo.VehicleStopped ? Controller.ShiftStrategy.NextGear : PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear : Controller.ShiftStrategy.NextGear; TestPowertrain.Gearbox.Disengaged = !nextGear.Engaged; TestPowertrain.Gearbox.DisengageGearbox = !nextGear.Engaged; TestPowertrain.Container.VehiclePort.Initialize(DataBus.VehicleInfo.VehicleSpeed, DataBus.DrivingCycleInfo.RoadGradient ?? 0.SI<Radian>()); TestPowertrain.HybridController.ApplyStrategySettings(cfg); TestPowertrain.HybridController.Initialize(Controller.PreviousState.OutTorque, Controller.PreviousState.OutAngularVelocity); - TestPowertrain.Clutch.Initialize(DataBus.ClutchInfo.ClutchLosses); - TestPowertrain.Battery?.Initialize(DataBus.BatteryInfo.StateOfCharge); - if (TestPowertrain.Battery != null) { - TestPowertrain.Battery.PreviousState.PulseDuration = - (DataBus.BatteryInfo as Battery).PreviousState.PulseDuration; - } - if (TestPowertrain.BatterySystem != null) { - var batSystem = DataBus.BatteryInfo as BatterySystem; - foreach (var bsKey in batSystem.Batteries.Keys) { - for (var i = 0; i < batSystem.Batteries[bsKey].Batteries.Count; i++) { - TestPowertrain.BatterySystem.Batteries[bsKey].Batteries[i] - .Initialize(batSystem.Batteries[bsKey].Batteries[i].StateOfCharge); - } - } - TestPowertrain.BatterySystem.PreviousState.PulseDuration = - (DataBus.BatteryInfo as BatterySystem).PreviousState.PulseDuration; - } - TestPowertrain.SuperCap?.Initialize(DataBus.BatteryInfo.StateOfCharge); TestPowertrain.Brakes.BrakePower = DataBus.Brakes.BrakePower; - - var currentGear = DataBus.VehicleInfo.VehicleStopped ? Controller.ShiftStrategy.NextGear : PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear : Controller.ShiftStrategy.NextGear; - - if (nextGear.Engaged && !nextGear.Equals(currentGear)) { + + if (nextGear.Engaged && !nextGear.Equals(TestPowertrain.Gearbox.Gear)) { if (!AllowEmergencyShift && ModelData.GearboxData.Gears[nextGear.Gear].Ratio > ModelData.GearshiftParameters.RatioEarlyUpshiftFC) { return null; } @@ -95,11 +68,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return null; } - var vDrop = DataBus.VehicleInfo.VehicleSpeed - estimatedVelocityPostShift; - var vehicleSpeedPostShift = estimatedVelocityPostShift; // DataBus.VehicleInfo.VehicleSpeed - vDrop * ModelData.GearshiftParameters.VelocityDropFactor; TestPowertrain.Gearbox.Gear = nextGear; - var init = TestPowertrain.Container.VehiclePort.Initialize( - vehicleSpeedPostShift, DataBus.DrivingCycleInfo.RoadGradient ?? 0.SI<Radian>()); + var init = TestPowertrain.Container.VehiclePort.Initialize(estimatedVelocityPostShift, DataBus.DrivingCycleInfo.RoadGradient ?? 0.SI<Radian>()); if (!AllowEmergencyShift && init.Engine.EngineSpeed.IsSmaller(ModelData.EngineData.IdleSpeed)) { return null; } @@ -107,68 +77,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies TestPowertrain.Gearbox._nextGear = Controller.ShiftStrategy.NextGear; TestPowertrain.Gearbox.Disengaged = !nextGear.Engaged; - - var combustionEngineInfo = DataBus.EngineInfo as CombustionEngine; - var enginePrevious = combustionEngineInfo.PreviousState; - TestPowertrain.CombustionEngine.Initialize(enginePrevious.EngineTorque, enginePrevious.EngineSpeed); - var testPreviousState = TestPowertrain.CombustionEngine.PreviousState; - testPreviousState.EngineOn = enginePrevious.EngineOn; - testPreviousState.EnginePower = enginePrevious.EnginePower; - testPreviousState.dt = enginePrevious.dt; - testPreviousState.EngineSpeed = enginePrevious.EngineSpeed; - testPreviousState.EngineTorque = enginePrevious.EngineTorque; - testPreviousState.EngineTorqueOut = enginePrevious.EngineTorqueOut; - testPreviousState.DynamicFullLoadTorque = enginePrevious.DynamicFullLoadTorque; - - switch (TestPowertrain.CombustionEngine.EngineAux) { - case EngineAuxiliary engineAux: - engineAux.PreviousState.AngularSpeed = - (combustionEngineInfo.EngineAux as EngineAuxiliary).PreviousState - .AngularSpeed; - break; - case BusAuxiliariesAdapter busAux: - busAux.PreviousState.AngularSpeed = - (combustionEngineInfo.EngineAux as BusAuxiliariesAdapter).PreviousState - .AngularSpeed; - if (busAux.ElectricStorage is SimpleBattery bat) { - bat.SOC = (combustionEngineInfo.EngineAux as BusAuxiliariesAdapter) - .ElectricStorage - .SOC; - } - break; - } - - if (TestPowertrain.DCDCConverter != null) { - TestPowertrain.DCDCConverter.PreviousState.ConsumedEnergy = - (DataBus.DCDCConverter as DCDCConverter).PreviousState.ConsumedEnergy; - } - - if (TestPowertrain.WHRCharger != null) { - TestPowertrain.WHRCharger.PreviousState.GeneratedEnergy = - DataBus.WHRCharger.PreviousState.GeneratedEnergy; - TestPowertrain.WHRCharger.PreviousState.ExcessiveEnergy = - DataBus.WHRCharger.PreviousState.ExcessiveEnergy; - } - - TestPowertrain.Gearbox.PreviousState.InAngularVelocity = - (DataBus.GearboxInfo as Gearbox).PreviousState.InAngularVelocity; - - TestPowertrain.Clutch.PreviousState.InAngularVelocity = - (DataBus.ClutchInfo as SwitchableClutch).PreviousState.InAngularVelocity; - TestPowertrain.Clutch.PreviousState.OutAngularVelocity = - (DataBus.ClutchInfo as SwitchableClutch).PreviousState.OutAngularVelocity; - - //} - + TestPowertrain.CombustionEngine.UpdateFrom(DataBus.EngineInfo); + TestPowertrain.Gearbox.UpdateFrom(DataBus.GearboxInfo); + TestPowertrain.Clutch.UpdateFrom(DataBus.ClutchInfo); var pos = ModelData.ElectricMachinesData.FirstOrDefault().Item1; - TestPowertrain.ElectricMotor.ThermalBuffer = - (DataBus.ElectricMotorInfo(pos) as ElectricMotor).ThermalBuffer; - TestPowertrain.ElectricMotor.DeRatingActive = - (DataBus.ElectricMotorInfo(pos) as ElectricMotor).DeRatingActive; - + TestPowertrain.ElectricMotor.UpdateFrom(DataBus.ElectricMotorInfo(pos)); foreach (var emPos in TestPowertrain.ElectricMotorsUpstreamTransmission.Keys) { - TestPowertrain.ElectricMotorsUpstreamTransmission[pos].PreviousState.EMSpeed = - DataBus.ElectricMotorInfo(emPos).ElectricMotorSpeed; + TestPowertrain.ElectricMotorsUpstreamTransmission[pos].PreviousState.EMSpeed = DataBus.ElectricMotorInfo(emPos).ElectricMotorSpeed; } var retVal = TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, true); @@ -193,58 +108,28 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies //tmp.FuelCosts = double.NaN; // = Tuple.Create(true, response.Gearbox.Gear - 1); tmp.IgnoreReason |= HybridConfigurationIgnoreReason.EngineSpeedBelowDownshift; } - - } - } - // ===================================================== - - public class HybridStrategyAT : AbstractHybridStrategy<ATGearbox> { + public HybridStrategyAT(VectoRunData runData, IVehicleContainer vehicleContainer) : base(runData, vehicleContainer) + { } - public HybridStrategyAT(VectoRunData runData, IVehicleContainer vehicleContainer) : base(runData, - vehicleContainer) - { - - } - - protected override IResponse RequestDryRun(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, - GearshiftPosition nextGear, HybridStrategyResponse cfg) + protected override IResponse RequestDryRun(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, GearshiftPosition nextGear, HybridStrategyResponse cfg) { + TestPowertrain.UpdateComponents(); + TestPowertrain.Gearbox.Gear = PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear : Controller.ShiftStrategy.NextGear; TestPowertrain.Gearbox.Disengaged = !nextGear.Engaged; TestPowertrain.Gearbox.DisengageGearbox = !nextGear.Engaged; TestPowertrain.Container.VehiclePort.Initialize(DataBus.VehicleInfo.VehicleSpeed, DataBus.DrivingCycleInfo.RoadGradient ?? 0.SI<Radian>()); TestPowertrain.HybridController.ApplyStrategySettings(cfg); TestPowertrain.HybridController.Initialize(Controller.PreviousState.OutTorque, Controller.PreviousState.OutAngularVelocity); - // TestPowertrain.Clutch.Initialize(DataBus.ClutchInfo.ClutchLosses); - TestPowertrain.Battery?.Initialize(DataBus.BatteryInfo.StateOfCharge); - if (TestPowertrain.Battery != null) { - TestPowertrain.Battery.PreviousState.PulseDuration = - (DataBus.BatteryInfo as Battery).PreviousState.PulseDuration; - } - if (TestPowertrain.BatterySystem != null) { - var batSystem = DataBus.BatteryInfo as BatterySystem; - foreach (var bsKey in batSystem.Batteries.Keys) { - for (var i = 0; i < batSystem.Batteries[bsKey].Batteries.Count; i++) { - TestPowertrain.BatterySystem.Batteries[bsKey].Batteries[i] - .Initialize(batSystem.Batteries[bsKey].Batteries[i].StateOfCharge); - } - } - TestPowertrain.BatterySystem.PreviousState.PulseDuration = - (DataBus.BatteryInfo as BatterySystem).PreviousState.PulseDuration; - } - TestPowertrain.SuperCap?.Initialize(DataBus.BatteryInfo.StateOfCharge); - + TestPowertrain.Brakes.BrakePower = DataBus.Brakes.BrakePower; - - var currentGear = PreviousState.GearboxEngaged ? DataBus.GearboxInfo.Gear : Controller.ShiftStrategy.NextGear; - - var gearboxInfo = DataBus.GearboxInfo as ATGearbox; - if (nextGear.Engaged && !nextGear.Equals(currentGear)) { + + if (nextGear.Engaged && !nextGear.Equals(TestPowertrain.Gearbox.Gear)) { if (!AllowEmergencyShift && ModelData.GearboxData.Gears[nextGear.Gear].Ratio > ModelData.GearshiftParameters.RatioEarlyUpshiftFC) { return null; } @@ -254,130 +139,44 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } var vDrop = DataBus.DriverInfo.DriverAcceleration * ModelData.GearshiftParameters.ATLookAheadTime; - var vehicleSpeedPostShift = (DataBus.VehicleInfo.VehicleSpeed + vDrop * ModelData.GearshiftParameters.VelocityDropFactor).LimitTo( - 0.KMPHtoMeterPerSecond(), DataBus.DrivingCycleInfo.CycleData.LeftSample.VehicleTargetSpeed); - - //var estimatedVelocityPostShift = VelocityDropData.Interpolate(DataBus.VehicleInfo.VehicleSpeed, DataBus.DrivingCycleInfo.RoadGradient ?? 0.SI<Radian>()); - //if (!AllowEmergencyShift && !estimatedVelocityPostShift.IsGreater(DeclarationData.GearboxTCU.MIN_SPEED_AFTER_TRACTION_INTERRUPTION)) { - // return null; - //} - + var vehicleSpeedPostShift = (DataBus.VehicleInfo.VehicleSpeed + vDrop * ModelData.GearshiftParameters.VelocityDropFactor).LimitTo(0.KMPHtoMeterPerSecond(), DataBus.DrivingCycleInfo.CycleData.LeftSample.VehicleTargetSpeed); if (nextGear.TorqueConverterLocked.HasValue && nextGear.TorqueConverterLocked.Value) { var inAngularVelocity = ModelData.GearboxData.Gears[nextGear.Gear].Ratio * outAngularVelocity; - if (inAngularVelocity.IsEqual(0)) { return null; } - var totalTransmissionRatio = inAngularVelocity / - (DataBus.VehicleInfo.VehicleSpeed + - DataBus.DriverInfo.DriverAcceleration * dt); - + var totalTransmissionRatio = inAngularVelocity / (DataBus.VehicleInfo.VehicleSpeed + DataBus.DriverInfo.DriverAcceleration * dt); var estimatedEngineSpeed = (vehicleSpeedPostShift * totalTransmissionRatio).Cast<PerSecond>(); if (estimatedEngineSpeed.IsSmaller(ModelData.GearshiftParameters.MinEngineSpeedPostUpshift)) { return null; } } - //var vDrop = DataBus.VehicleInfo.VehicleSpeed - estimatedVelocityPostShift; - //var vehicleSpeedPostShift = estimatedVelocityPostShift; // DataBus.VehicleInfo.VehicleSpeed - vDrop * ModelData.GearshiftParameters.VelocityDropFactor; TestPowertrain.Gearbox.Gear = nextGear; TestPowertrain.Gearbox.RequestAfterGearshift = true; - //var init = TestPowertrain.Container.VehiclePort.Initialize( - // vehicleSpeedPostShift, DataBus.DrivingCycleInfo.RoadGradient ?? 0.SI<Radian>()); - //if (!AllowEmergencyShift && init.Engine.EngineSpeed.IsSmaller(ModelData.EngineData.IdleSpeed)) { - // return null; - //} } else { - TestPowertrain.Gearbox.RequestAfterGearshift = gearboxInfo.RequestAfterGearshift; + TestPowertrain.Gearbox.RequestAfterGearshift = DataBus.GearboxInfo.RequestAfterGearshift; } - //TestPowertrain.Gearbox.ShiftToLocked = (DataBus.GearboxInfo as ATGearbox).ShiftToLocked; - + if (!nextGear.Engaged) { - //TestPowertrain.Gearbox._nextGear = Controller.ShiftStrategy.NextGear; TestPowertrain.Gearbox.Disengaged = !nextGear.Engaged; } - //if (!PreviousState.GearboxEngaged) { - var engineInfo = DataBus.EngineInfo as CombustionEngine; - var enginePrevious = engineInfo.PreviousState; - TestPowertrain.CombustionEngine.Initialize(enginePrevious.EngineTorque, enginePrevious.EngineSpeed); - var testEnginePrevious = TestPowertrain.CombustionEngine.PreviousState; - testEnginePrevious.EngineOn = enginePrevious.EngineOn; - testEnginePrevious.EnginePower = enginePrevious.EnginePower; - testEnginePrevious.dt = enginePrevious.dt; - testEnginePrevious.EngineSpeed = enginePrevious.EngineSpeed; - testEnginePrevious.EngineTorque = enginePrevious.EngineTorque; - testEnginePrevious.EngineTorqueOut = enginePrevious.EngineTorqueOut; - testEnginePrevious.DynamicFullLoadTorque = enginePrevious.DynamicFullLoadTorque; - - switch (TestPowertrain.CombustionEngine.EngineAux) { - case EngineAuxiliary engineAux: - engineAux.PreviousState.AngularSpeed = (engineInfo.EngineAux as EngineAuxiliary).PreviousState.AngularSpeed; - break; - case BusAuxiliariesAdapter busAux: - busAux.PreviousState.AngularSpeed = (engineInfo.EngineAux as BusAuxiliariesAdapter).PreviousState.AngularSpeed; - if (busAux.ElectricStorage is SimpleBattery bat) { - bat.SOC = (engineInfo.EngineAux as BusAuxiliariesAdapter) - .ElectricStorage - .SOC; - } - break; - } - - if (TestPowertrain.DCDCConverter != null) { - TestPowertrain.DCDCConverter.PreviousState.ConsumedEnergy = - (DataBus.DCDCConverter as DCDCConverter).PreviousState.ConsumedEnergy; - } - - if (TestPowertrain.WHRCharger != null) { - TestPowertrain.WHRCharger.PreviousState.GeneratedEnergy = - DataBus.WHRCharger.PreviousState.GeneratedEnergy; - TestPowertrain.WHRCharger.PreviousState.ExcessiveEnergy = - DataBus.WHRCharger.PreviousState.ExcessiveEnergy; - } - - TestPowertrain.Gearbox.PreviousState.OutAngularVelocity = gearboxInfo.PreviousState.OutAngularVelocity; - TestPowertrain.Gearbox.PreviousState.InAngularVelocity = gearboxInfo.PreviousState.InAngularVelocity; - TestPowertrain.Gearbox._powershiftLossEnergy = gearboxInfo._powershiftLossEnergy; - TestPowertrain.Gearbox.PreviousState.PowershiftLossEnergy = gearboxInfo.PreviousState.PowershiftLossEnergy; - TestPowertrain.Gearbox.LastShift = gearboxInfo.LastShift; - TestPowertrain.Gearbox.PreviousState.Gear = gearboxInfo.PreviousState.Gear; - + TestPowertrain.CombustionEngine.UpdateFrom(DataBus.EngineInfo); + TestPowertrain.Gearbox.UpdateFrom(DataBus.GearboxInfo); if (nextGear.TorqueConverterLocked.HasValue && !nextGear.TorqueConverterLocked.Value) { - var dataBusTorqueConverterInfo = DataBus.TorqueConverterInfo as TorqueConverter; - var prev = dataBusTorqueConverterInfo.PreviousState; - var testTCPrevious = TestPowertrain.TorqueConverter.PreviousState; - testTCPrevious.InAngularVelocity = prev.InAngularVelocity; - testTCPrevious.InTorque = prev.InTorque; - testTCPrevious.OutAngularVelocity = prev.OutAngularVelocity; - testTCPrevious.IgnitionOn = prev.IgnitionOn; + TestPowertrain.TorqueConverter.UpdateFrom(DataBus.TorqueConverterInfo); } - //TestPowertrain.Clutch.PreviousState.InAngularVelocity = - // (DataBus.ClutchInfo as SwitchableClutch).PreviousState.InAngularVelocity; - - //} - var pos = ModelData.ElectricMachinesData.FirstOrDefault().Item1; - TestPowertrain.ElectricMotor.ThermalBuffer = - (DataBus.ElectricMotorInfo(pos) as ElectricMotor).ThermalBuffer; - TestPowertrain.ElectricMotor.DeRatingActive = - (DataBus.ElectricMotorInfo(pos) as ElectricMotor).DeRatingActive; - + TestPowertrain.ElectricMotor.UpdateFrom(DataBus.ElectricMotorInfo(pos)); foreach (var emPos in TestPowertrain.ElectricMotorsUpstreamTransmission.Keys) { - TestPowertrain.ElectricMotorsUpstreamTransmission[pos].PreviousState.EMSpeed = - DataBus.ElectricMotorInfo(emPos).ElectricMotorSpeed; + TestPowertrain.ElectricMotorsUpstreamTransmission[pos].PreviousState.EMSpeed = DataBus.ElectricMotorInfo(emPos).ElectricMotorSpeed; } try { - var retVal = TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, - outAngularVelocity, false); - - //if (retVal.Source is TorqueConverter) { - // return null; - //} - + var retVal = TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, false); retVal.HybridController.StrategySettings = cfg; return retVal; } catch (Exception e) { @@ -423,22 +222,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } - // ===================================================== - public abstract class AbstractHybridStrategy<T> : LoggingObject, IHybridControlStrategy where T : class, IHybridControlledGearbox, IGearbox { - public class StrategyState { public PerSecond AngularVelocity { get; set; } public HybridStrategyResponse Response { get; set; } public List<HybridResultEntry> Evaluations; public HybridResultEntry Solution { get; set; } - public bool GearboxEngaged { get; set; } - public Second ICEStartTStmp { get; set; } - public Second GearshiftTriggerTstmp { get; set; } public NewtonMeter MaxGbxTq { get; set; } public bool ICEOn { get; set; } @@ -569,18 +362,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies GearshiftPosition nextGear; if (DataBus.VehicleInfo.VehicleStopped) { nextGear = Controller.ShiftStrategy.NextGear; - } - else if (!DataBus.GearboxInfo.GearEngaged(absTime)) { + } else if (!DataBus.GearboxInfo.GearEngaged(absTime)) { nextGear = Controller.ShiftStrategy.NextGear; - } - else if (PreviousState.GearboxEngaged) { + } else if (PreviousState.GearboxEngaged) { nextGear = DataBus.GearboxInfo.Gear; } else { nextGear = Controller.ShiftStrategy.NextGear; } if (DataBus.DriverInfo.DrivingAction == DrivingAction.Accelerate && StrategyParameters.MaxPropulsionTorque?.GetVECTOValueOrDefault(nextGear) != null && DataBus.GearboxInfo.TCLocked) { - + var emOff = new HybridStrategyResponse { CombustionEngineOn = DataBus.EngineInfo.EngineOn, // AllowICEOff(absTime), GearboxInNeutral = false, @@ -653,7 +444,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies case DrivingAction.Halt: HandleHaltAction(absTime, dt, outTorque, outAngularVelocity, dryRun, eval); break; - default: throw new ArgumentOutOfRangeException(); + default: + throw new ArgumentOutOfRangeException(); } @@ -703,8 +495,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies CurrentState.GearshiftTriggerTstmp = absTime; } - DebugData.Add("AHS.R", new { DataBus.DriverInfo.DrivingAction, Evaluations = eval, - Best = best, RetVal = retVal, DryRun = dryRun }); + DebugData.Add("AHS.R", new { + DataBus.DriverInfo.DrivingAction, + Evaluations = eval, + Best = best, + RetVal = retVal, + DryRun = dryRun + }); return retVal; } @@ -863,7 +660,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } var testRequest = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, emOff); if (testRequest != null && testRequest.Engine.EngineSpeed < ModelData.EngineData.FullLoadCurves[0].NTq99hSpeed) { - var maxGbxTorque = StrategyParameters.MaxPropulsionTorque?.GetVECTOValueOrDefault(nextGear).FullLoadDriveTorque(testRequest.Gearbox.InputSpeed); + var maxGbxTorque = StrategyParameters.MaxPropulsionTorque?.GetVECTOValueOrDefault(nextGear)?.FullLoadDriveTorque(testRequest.Gearbox.InputSpeed); candidates[nextGear] = maxGbxTorque != null ? Tuple.Create(maxGbxTorque * testRequest.Gearbox.InputSpeed, testRequest) : Tuple.Create(testRequest.Gearbox.InputTorque * testRequest.Gearbox.InputSpeed, testRequest); @@ -987,7 +784,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var isP1 = DataBus.PowertrainInfo.ElectricMotorPositions.Contains(PowertrainPosition.HybridP1); if (isP1 && (!ModelData.VehicleData.ADAS.EngineStopStart || !isPCC)) return false; - + //normal case: only turn of ICE if ESS is activated and the minimal ICE on time is exceeded. var MinICEonTimeExceeded = PreviousState.ICEStartTStmp is null || absTime.IsGreaterOrEqual(PreviousState.ICEStartTStmp + StrategyParameters.MinICEOnTime); @@ -1008,8 +805,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var disengageSpeedThreshold = ModelData.GearboxData.DisengageWhenHaltingSpeed; // hint: only check for halting speed if vehicle is actually braking to halt. - var vehiclespeedBelowThreshold = DataBus.VehicleInfo.VehicleSpeed.IsSmaller(disengageSpeedThreshold) - && (DataBus.DriverInfo.NextBrakeTriggerSpeed?.IsEqual(0) ?? false); + var vehiclespeedBelowThreshold = DataBus.VehicleInfo.VehicleSpeed.IsSmaller(disengageSpeedThreshold) + && (DataBus.DriverInfo.NextBrakeTriggerSpeed?.IsEqual(0) ?? false); if (ElectricMotorCanPropellDuringTractionInterruption || DataBus.GearboxInfo.GearEngaged(absTime)) { @@ -1030,8 +827,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies GearshiftPosition nextGear; if (!DataBus.GearboxInfo.GearEngaged(absTime)) { nextGear = new GearshiftPosition(0); - } - else if (PreviousState.GearboxEngaged) { + } else if (PreviousState.GearboxEngaged) { nextGear = DataBus.GearboxInfo.Gear; } else { nextGear = Controller.ShiftStrategy.NextGear; @@ -1062,7 +858,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var endSpeed = DataBus.VehicleInfo.VehicleSpeed + DataBus.DriverInfo.DriverAcceleration * ModelData.GearboxData.TractionInterruption; if (EngineSpeedTooLow(response) - && (DataBus.GearboxInfo.GearboxType.ManualTransmission() || DataBus.GearboxInfo.GearboxType == GearboxType.IHPC) + && (DataBus.GearboxInfo.GearboxType.ManualTransmission() || DataBus.GearboxInfo.GearboxType == GearboxType.IHPC) && endSpeed.IsSmallerOrEqual(disengageSpeedThreshold, 0.1.KMPHtoMeterPerSecond())) { var responseEmOff = ResponseEmOff; responseEmOff.Gear = new GearshiftPosition(0); @@ -1072,7 +868,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return; } - if (GearList.HasPredecessor(nextGear) + if (GearList.HasPredecessor(nextGear) && EngineSpeedTooLow(response) && (!vehiclespeedBelowThreshold || AllowEmergencyShift)) { // engine speed would fall below idling speed - consider downshift @@ -1127,7 +923,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var downshift = ResponseEmOff; //downshift.Gear = GearList.Predecessor(nextGear); downshift.Gear = best; // GearList.Predecessor(nextGear); - downshift.Setting.GearboxInNeutral = best.Gear == 0; + downshift.Setting.GearboxInNeutral = best.Gear == 0; downshift.Setting.ShiftRequired = best.Gear == 0; eval.Add(downshift); return; @@ -1347,11 +1143,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies private GearshiftPosition FindBestGearForBraking(GearshiftPosition nextGear, IResponse firstResponse) { - var endSpeed = DataBus.VehicleInfo.VehicleSpeed + + var endSpeed = DataBus.VehicleInfo.VehicleSpeed + DataBus.DriverInfo.DriverAcceleration * ModelData.GearboxData.TractionInterruption; - + // only disengage if we are actually braking for halting (meaning: next brake trigger speed is 0). - if (DataBus.GearboxInfo.GearboxType.ManualTransmission() + if (DataBus.GearboxInfo.GearboxType.ManualTransmission() && (DataBus.DriverInfo.NextBrakeTriggerSpeed?.IsEqual(0) ?? false) && endSpeed.IsSmallerOrEqual(ModelData.GearboxData.DisengageWhenHaltingSpeed, 0.1.KMPHtoMeterPerSecond())) { return new GearshiftPosition(0); @@ -1738,7 +1534,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies // ICE is off, selected solution has a too low or too high engine speed - keep ICE off retVal.CombustionEngineOn = false; } - if (best.IgnoreReason.EngineSpeedTooLow() && !DataBus.EngineInfo.EngineOn + if (best.IgnoreReason.EngineSpeedTooLow() && !DataBus.EngineInfo.EngineOn && DataBus.VehicleInfo.VehicleSpeed.IsGreater(ModelData.GearshiftParameters.StartSpeed)) { // ICE is off, selected solution has a too low or too high engine speed - keep ICE off retVal.CombustionEngineOn = false; diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs index 995b7b21150e34339e81981217bb4a5c7526618b..78f5fa87f671a6be67ae557651f7615a54b8ba52 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/SerialHybridStrategy.cs @@ -19,104 +19,47 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies { - public class SerialHybridStrategyAT : AbstractSerialHybridStrategy<APTNGearbox> { public SerialHybridStrategyAT(VectoRunData runData, IVehicleContainer container) : base(runData, container) { } #region Overrides of AbstractSerialHybridStrategy<ATGearbox> - protected override DrivetrainDemand GetDrivetrainPowerDemand(Second absTime, Second dt, NewtonMeter outTorque, - PerSecond outAngularVelocity, GenSetOperatingPoint maxPowerGenset) + protected override DrivetrainDemand GetDrivetrainPowerDemand(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, GenSetOperatingPoint maxPowerGenset) { - if (TestPowertrain.Gearbox != null) { - var gearboxInfo = DataBus.GearboxInfo as APTNGearbox; - if (gearboxInfo == null) { - throw new VectoException("AT Gearbox Required!"); - } - var currentGear = DataBus.VehicleInfo.VehicleStopped - ? gearboxInfo.NextGear - : DataBus.GearboxInfo.Gear; + TestPowertrain.UpdateComponents(); - TestPowertrain.Gearbox.PreviousState.InAngularVelocity = - gearboxInfo.PreviousState.InAngularVelocity; + if (TestPowertrain.Gearbox != null) { + var gearboxInfo = DataBus.GearboxInfo as APTNGearbox ?? throw new VectoException("AT Gearbox Required!"); + var currentGear = DataBus.VehicleInfo.VehicleStopped ? gearboxInfo.NextGear : DataBus.GearboxInfo.Gear; TestPowertrain.Gearbox.Disengaged = gearboxInfo.Disengaged; TestPowertrain.Gearbox.DisengageGearbox = gearboxInfo.DisengageGearbox; TestPowertrain.Gearbox.Gear = currentGear; TestPowertrain.Gearbox._nextGear = gearboxInfo.NextGear; } TestPowertrain.Container.VehiclePort.Initialize(DataBus.VehicleInfo.VehicleSpeed, DataBus.DrivingCycleInfo.RoadGradient ?? 0.SI<Radian>()); - (TestPowertrain.Container.VehicleInfo as Vehicle).PreviousState.Velocity = - (DataBus.VehicleInfo as Vehicle).PreviousState.Velocity; - - TestPowertrain.ElectricMotor.ThermalBuffer = - (DataBus.ElectricMotorInfo(EmPosition) as ElectricMotor).ThermalBuffer; - TestPowertrain.ElectricMotor.DeRatingActive = - (DataBus.ElectricMotorInfo(EmPosition) as ElectricMotor).DeRatingActive; - - TestPowertrain.Battery?.Initialize(DataBus.BatteryInfo.StateOfCharge); - if (TestPowertrain.Battery != null) { - TestPowertrain.Battery.PreviousState.PulseDuration = - (DataBus.BatteryInfo as Battery).PreviousState.PulseDuration; - TestPowertrain.Battery.PreviousState.PowerDemand = - (DataBus.BatteryInfo as Battery).PreviousState.PowerDemand; - } - if (TestPowertrain.BatterySystem != null) { - var batSystem = DataBus.BatteryInfo as BatterySystem; - foreach (var bsKey in batSystem.Batteries.Keys) { - for (var i = 0; i < batSystem.Batteries[bsKey].Batteries.Count; i++) { - TestPowertrain.BatterySystem.Batteries[bsKey].Batteries[i] - .Initialize(batSystem.Batteries[bsKey].Batteries[i].StateOfCharge); - } - } - TestPowertrain.BatterySystem.PreviousState.PulseDuration = - (DataBus.BatteryInfo as BatterySystem).PreviousState.PulseDuration; - TestPowertrain.BatterySystem.PreviousState.PowerDemand = (DataBus.BatteryInfo as BatterySystem).PreviousState.PowerDemand; - } - - TestPowertrain.Charger.ChargingPower = maxPowerGenset.ElectricPower; - - if (TestPowertrain.WHRCharger != null) { - TestPowertrain.WHRCharger.PreviousState.GeneratedEnergy = - DataBus.WHRCharger.PreviousState.GeneratedEnergy; - TestPowertrain.WHRCharger.PreviousState.ExcessiveEnergy = - DataBus.WHRCharger.PreviousState.ExcessiveEnergy; - } - - TestPowertrain.HybridController.Initialize(Controller.PreviousState.OutTorque, - Controller.PreviousState.OutAngularVelocity); - - if (TestPowertrain.Gearbox != null) { - var gearboxInfo = DataBus.GearboxInfo as APTNGearbox; - TestPowertrain.Gearbox.PreviousState.OutAngularVelocity = gearboxInfo.PreviousState.OutAngularVelocity; - TestPowertrain.Gearbox.PreviousState.InAngularVelocity = gearboxInfo.PreviousState.InAngularVelocity; - } - + TestPowertrain.Charger.UpdateFrom(maxPowerGenset); + TestPowertrain.HybridController.Initialize(Controller.PreviousState.OutTorque, Controller.PreviousState.OutAngularVelocity); + TestPowertrain.Gearbox?.UpdateFrom(DataBus.GearboxInfo); + TestPowertrain.Brakes.BrakePower = DataBus.Brakes.BrakePower; - var testResponse = - TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, false); - TestPowertrain.HybridController.ApplyStrategySettings(new HybridStrategyResponse() { - CombustionEngineOn = false, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { - { - EmPosition, - Tuple.Create(testResponse.ElectricMotor.AvgDrivetrainSpeed, -testResponse.ElectricMotor.TorqueRequest) - } + var testResponse = TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, false); + TestPowertrain.HybridController.ApplyStrategySettings(new HybridStrategyResponse { + CombustionEngineOn = false, + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { + { EmPosition, Tuple.Create(testResponse.ElectricMotor.AvgDrivetrainSpeed, -testResponse.ElectricMotor.TorqueRequest) } } }); - var testResponse2 = - TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, - false); - return new DrivetrainDemand() { + var testResponse2 = TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, false); + return new DrivetrainDemand { AvgEmDrivetrainSpeed = testResponse2.ElectricMotor.AvgDrivetrainSpeed, EmTorqueDemand = testResponse2.ElectricMotor.TorqueRequest, ElectricPowerDemand = testResponse2.ElectricSystem.ConsumerPower, Response = testResponse2 }; } - - + #endregion } @@ -131,77 +74,32 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies protected override 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 - : DataBus.GearboxInfo.Gear; - - 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 = - (DataBus.ElectricMotorInfo(EmPosition) as ElectricMotor).DeRatingActive; - - TestPowertrain.Battery?.Initialize(DataBus.BatteryInfo.StateOfCharge); - if (TestPowertrain.Battery != null) { - TestPowertrain.Battery.PreviousState.PulseDuration = - (DataBus.BatteryInfo as Battery).PreviousState.PulseDuration; - TestPowertrain.Battery.PreviousState.PowerDemand = - (DataBus.BatteryInfo as Battery).PreviousState.PowerDemand; - } - if (TestPowertrain.BatterySystem != null) { - var batSystem = DataBus.BatteryInfo as BatterySystem; - foreach (var bsKey in batSystem.Batteries.Keys) { - for (var i = 0; i < batSystem.Batteries[bsKey].Batteries.Count; i++) { - TestPowertrain.BatterySystem.Batteries[bsKey].Batteries[i] - .Initialize(batSystem.Batteries[bsKey].Batteries[i].StateOfCharge); - } - } - TestPowertrain.BatterySystem.PreviousState.PulseDuration = - (DataBus.BatteryInfo as BatterySystem).PreviousState.PulseDuration; - TestPowertrain.BatterySystem.PreviousState.PowerDemand = (DataBus.BatteryInfo as BatterySystem).PreviousState.PowerDemand; - } - - TestPowertrain.Charger.ChargingPower = maxPowerGenset.ElectricPower; - - if (TestPowertrain.WHRCharger != null) { - TestPowertrain.WHRCharger.PreviousState.GeneratedEnergy = - DataBus.WHRCharger.PreviousState.GeneratedEnergy; - TestPowertrain.WHRCharger.PreviousState.ExcessiveEnergy = - DataBus.WHRCharger.PreviousState.ExcessiveEnergy; - } + TestPowertrain.UpdateComponents(); - TestPowertrain.HybridController.Initialize(Controller.PreviousState.OutTorque, - Controller.PreviousState.OutAngularVelocity); - TestPowertrain.Brakes.BrakePower = DataBus.Brakes.BrakePower; if (TestPowertrain.Gearbox != null) { - TestPowertrain.Gearbox.PreviousState.InAngularVelocity = - (DataBus.GearboxInfo as Gearbox).PreviousState.InAngularVelocity; + var g = DataBus.GearboxInfo as Gearbox ?? throw new VectoException("AMT Gearbox Required!"); + TestPowertrain.Gearbox.Disengaged = g.Disengaged; + TestPowertrain.Gearbox.DisengageGearbox = g.DisengageGearbox; + TestPowertrain.Gearbox.Gear = DataBus.VehicleInfo.VehicleStopped ? g.NextGear : DataBus.GearboxInfo.Gear; + TestPowertrain.Gearbox._nextGear = g.NextGear; } - var testResponse = - TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, false); - TestPowertrain.HybridController.ApplyStrategySettings(new HybridStrategyResponse() { + TestPowertrain.Container.VehiclePort.Initialize(DataBus.VehicleInfo.VehicleSpeed, DataBus.DrivingCycleInfo.RoadGradient ?? 0.SI<Radian>()); + TestPowertrain.Charger.UpdateFrom(maxPowerGenset); + TestPowertrain.HybridController.Initialize(Controller.PreviousState.OutTorque, Controller.PreviousState.OutAngularVelocity); + TestPowertrain.Gearbox?.UpdateFrom(DataBus.GearboxInfo); + + TestPowertrain.Brakes.BrakePower = DataBus.Brakes.BrakePower; + + var testResponse = TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, false); + TestPowertrain.HybridController.ApplyStrategySettings(new HybridStrategyResponse { CombustionEngineOn = false, - MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>>() { - { - EmPosition, - Tuple.Create(testResponse.ElectricMotor.AvgDrivetrainSpeed, -testResponse.ElectricMotor.TorqueRequest) - } + MechanicalAssistPower = new Dictionary<PowertrainPosition, Tuple<PerSecond, NewtonMeter>> { + { EmPosition, Tuple.Create(testResponse.ElectricMotor.AvgDrivetrainSpeed, -testResponse.ElectricMotor.TorqueRequest) } } }); - var testResponse2 = - TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, - false); - return new DrivetrainDemand() { + var testResponse2 = TestPowertrain.HybridController.NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, false); + return new DrivetrainDemand { AvgEmDrivetrainSpeed = testResponse2.ElectricMotor.AvgDrivetrainSpeed, EmTorqueDemand = testResponse2.ElectricMotor.TorqueRequest, ElectricPowerDemand = testResponse2.ElectricSystem.ConsumerPower, @@ -213,7 +111,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies // ======================================================================= - public abstract class AbstractSerialHybridStrategy<T> : LoggingObject, IHybridControlStrategy where T : class, IHybridControlledGearbox, IGearbox + public abstract class AbstractSerialHybridStrategy<T> : LoggingObject, IHybridControlStrategy where T : class, IHybridControlledGearbox, IGearbox { public enum StateMachineState @@ -251,13 +149,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies protected TestPowertrain<T> TestPowertrain; protected TestGenset TestGenSet; protected GenSetCharacteristics GenSetCharacteristics; - + protected PowertrainPosition EmPosition; protected DryRunSolutionState DryRunSolution { get; set; } - public AbstractSerialHybridStrategy (VectoRunData runData, IVehicleContainer container) + public AbstractSerialHybridStrategy(VectoRunData runData, IVehicleContainer container) { DataBus = container; ModelData = runData; @@ -293,8 +191,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies PowertrainBuilder.BuildSimpleGenSet(runData, gensetContainer); TestGenSet = new TestGenset(gensetContainer, DataBus); - - container.AddPreprocessor(new GensetPreprocessor(GenSetCharacteristics ,TestGenSet, runData.EngineData, + + container.AddPreprocessor(new GensetPreprocessor(GenSetCharacteristics, TestGenSet, runData.EngineData, runData.ElectricMachinesData.FirstOrDefault(x => x.Item1 == PowertrainPosition.GEN)?.Item2)); } @@ -311,7 +209,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } GenSetCharacteristics.ContinuousTorque = ModelData.ElectricMachinesData - .FirstOrDefault(x => x.Item1 == EmPosition)?.Item2.Overload.ContinuousTorque ?? 0.SI<NewtonMeter>(); + .FirstOrDefault(x => x.Item1 == EmPosition)?.Item2.Overload.ContinuousTorque ?? 0.SI<NewtonMeter>(); PreviousState.AngularVelocity = outAngularVelocity; PreviousState.SMState = DataBus.BatteryInfo.StateOfCharge > StrategyParameters.TargetSoC @@ -539,22 +437,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } return ApproachGensetOperatingPoint(absTime, dt, gensetLimit, gensetState); - + } public GenSetOperatingPoint GensetOff => new - GenSetOperatingPoint - { - ICEOn = false, - ICESpeed = ModelData.EngineData.IdleSpeed, - ICETorque = null, - EMTorque = null - }; + GenSetOperatingPoint { + ICEOn = false, + ICESpeed = ModelData.EngineData.IdleSpeed, + ICETorque = null, + EMTorque = null + }; public GenSetOperatingPoint GensetIdle => new GenSetOperatingPoint() { - ICEOn = true, + ICEOn = true, ICESpeed = ModelData.EngineData.IdleSpeed, - ICETorque = 0.SI<NewtonMeter>(), + ICETorque = 0.SI<NewtonMeter>(), EMTorque = null, }; @@ -710,7 +607,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies var iceSpeed = op.ICESpeed; var emTqDt = op.ICETorque; - + TestGenSet.ElectricMotorCtl.EMTorque = emTqDt; var r1 = TestGenSet.ElectricMotor.Request(absTime, dt, 0.SI<NewtonMeter>(), iceSpeed); @@ -850,8 +747,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies return (tqDt, iceSpeed, r1); } - - + + public IResponse AmendResponse(IResponse response, Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, bool dryRun) { @@ -863,7 +760,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies CurrentState.ICEOn = DataBus.EngineCtl.CombustionEngineOn; PreviousState = CurrentState; CurrentState = new StrategyState(); - + AllowEmergencyShift = false; } @@ -878,12 +775,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public void OperatingpointChangedDuringRequest(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, bool dryRun, IResponse retVal) { - + } public void RepeatDrivingAction(Second absTime) { - + } #endregion @@ -944,8 +841,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public GenSetOperatingPoint OptimalPoint { - get - { + get { if (_optimalPoint == null) { var tmp = OptimalPoints.Values.SelectMany(x => x).Where(x => x.ElectricPower > MinGensetPower).ToArray(); if (!tmp.Any()) { @@ -960,8 +856,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public GenSetOperatingPoint OptimalPointDeRated { - get - { + get { if (_optimalPointDerated == null) { var tmp = OptimalPoints.Values.SelectMany(x => x).Where(x => x.EMTorque.IsSmaller(ContinuousTorque)).Where(x => x.ElectricPower > MinGensetPower).ToArray(); if (!tmp.Any()) { @@ -970,7 +865,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies .Where(x => x.EMTorque.IsSmaller(ContinuousTorque)).ToArray(); } - + _optimalPointDerated = tmp.MinBy(x => x.FuelConsumption / x.ElectricPower); } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/TestPowertrain.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/TestPowertrain.cs index 42c94ada790908d2e4738c008ef42098078168a5..e198f3a774097cf830318e2bfc940f4a71a842da 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/TestPowertrain.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/TestPowertrain.cs @@ -43,6 +43,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public class TestPowertrain<T> where T: class, IHybridControlledGearbox, IGearbox { public SimplePowertrainContainer Container; + public IDataBus RealContainer; + public T Gearbox; public SimpleHybridController HybridController; @@ -63,6 +65,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public TestPowertrain(SimplePowertrainContainer container, IDataBus realContainer) { Container = container; + RealContainer = realContainer; + Gearbox = Container.GearboxCtl as T; HybridController = Container.HybridController as SimpleHybridController; @@ -110,9 +114,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } //Brakes = new MockBrakes(container); } + + public void UpdateComponents() => Container.UpdateComponents(RealContainer); } - public class MockBrakes : VectoSimulationComponent, IBrakes + public class MockBrakes : VectoSimulationComponent, IBrakes, IUpdateable { public MockBrakes(IVehicleContainer container) : base(container) { @@ -138,6 +144,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies public Watt BrakePower { get; set; } #endregion + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is IBrakes b) { + BrakePower = b.BrakePower; + return true; + } + + return false; + } + + #endregion } public class MockDrivingCycle : VectoSimulationComponent, IDrivingCycleInfo diff --git a/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs b/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs index 9b8d9bbe851ce95fcb5c2485e95e731f112560f8..3cd054bcf8f9e1c86fea271a987f5f89928b9d9b 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs @@ -142,5 +142,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent #endregion #endregion + + #region Implementation of IUpdateable + + public override bool UpdateFrom(object other) { + if (other is SwitchableClutch c) { + PreviousState = c.PreviousState.Clone(); + ClutchOpen = c.ClutchOpen; + return true; + } + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs b/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs index 6034fcc178a0acbfad280038e40008ae0210f9ea..584ab68d22ca69ffa46a0092261c4c7de4e6bfda 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs @@ -145,5 +145,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent OutTorque = outTorque; OutAngularVelocity = outAngularVelocity; } + + public SimpleComponentState Clone() => (SimpleComponentState)MemberwiseClone(); } } \ No newline at end of file diff --git a/VectoCore/VectoCore/OutputData/XML/ComponentWriter/ComponentWriterNinjectModule.cs b/VectoCore/VectoCore/OutputData/XML/ComponentWriter/ComponentWriterNinjectModule.cs index 3f3db79d76b2e71da25560524c8385f86ad378ec..015197523b60bc480e6c83c7d20e26d9aa617ece 100644 --- a/VectoCore/VectoCore/OutputData/XML/ComponentWriter/ComponentWriterNinjectModule.cs +++ b/VectoCore/VectoCore/OutputData/XML/ComponentWriter/ComponentWriterNinjectModule.cs @@ -20,7 +20,7 @@ namespace TUGraz.VectoCore.OutputData.XML.ComponentWriter //ADASTypes - var v2102 = XMLDeclarationNamespaces.v2_10_2; + var v2102 = XMLDeclarationNamespaces.V24; Bind<IDeclarationAdasWriter>().To<AdasConventionalWriter>(). Named(GetName(GroupNames.ADAS_Conventional_Type, v2102)); diff --git a/VectoCore/VectoCore/OutputData/XML/GroupWriter/XMLGroupWriterNinjectModule.cs b/VectoCore/VectoCore/OutputData/XML/GroupWriter/XMLGroupWriterNinjectModule.cs index 8b46e43aa233bfcba2c95f6a080357daa2e20ff7..084c13b344a0414f3707190a63d4f11e788af428 100644 --- a/VectoCore/VectoCore/OutputData/XML/GroupWriter/XMLGroupWriterNinjectModule.cs +++ b/VectoCore/VectoCore/OutputData/XML/GroupWriter/XMLGroupWriterNinjectModule.cs @@ -22,7 +22,7 @@ namespace TUGraz.VectoCore.OutputData.XML.GroupWriter Bind<IGroupWriterFactory>().ToFactory(() => new UseFirstTwoArgumentsAsInstanceProvider(1, false)).InSingletonScope(); ///Vehicle V2_10_2 - var v2102 = XMLDeclarationNamespaces.v2_10_2; + var v2102 = XMLDeclarationNamespaces.V24; Bind<IVehicleDeclarationGroupWriter>().To<CompletedBusGeneralParametersWriterV2_10_2>().InSingletonScope(). Named(GetName(GroupNames.Vehicle_CompletedBus_GeneralParametersSequenceGroup, v2102)); Bind<IVehicleDeclarationGroupWriter>().To<CompletedBusParametersWriterV2_10_2>().InSingletonScope(). diff --git a/VectoCore/VectoCore/OutputData/XML/XMLDeclarationNamespaces.cs b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationNamespaces.cs index fb74d2980b0303cad5bb2489ef9e8534637d76f8..47ab2e5bb42d3161bce0e91fdbf78bc522d8b1c7 100644 --- a/VectoCore/VectoCore/OutputData/XML/XMLDeclarationNamespaces.cs +++ b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationNamespaces.cs @@ -16,6 +16,7 @@ namespace TUGraz.VectoCore.OutputData.XML public static readonly XNamespace V26 = DeclarationDefinition + ":DEV:v2.6"; public static readonly XNamespace V21 = DeclarationDefinition + ":v2.1"; public static readonly XNamespace V23 = DeclarationDefinition + ":DEV:v2.3"; + public static readonly XNamespace V24 = DeclarationDefinition + ":v2.4"; public static readonly XNamespace V20 = DeclarationDefinition + ":v2.0"; public static readonly XNamespace V10 = DeclarationDefinition + ":v1.0"; public static readonly XNamespace V28 = DeclarationDefinition + ":DEV:v2.8"; diff --git a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs index d821eaf669d44e01054d220d36b619588a79c13d..4fe1b3ca9cd1ed8a31de51b052ff2632001cc252 100644 --- a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs +++ b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs @@ -178,7 +178,6 @@ namespace TUGraz.VectoCore.Utils //iterationCount += 100; log.Debug("LineSearch could not find an operating point."); log.Error("Exceeded max iterations when searching for operating point!"); - log.Error("debug: {0}", debug); WriteSearch(debug, "LineSearch.csv"); throw new VectoSearchFailedException("Failed to find operating point! points: {0}", debug.LocalData.Select(d => d.b).Join()); @@ -295,7 +294,6 @@ namespace TUGraz.VectoCore.Utils log.Debug("InterpolateSearch could not find an operating point."); #if DEBUG log.Error("InterpolateSearch exceeded max iterations when searching for operating point!"); - log.Error("debug: {0}", debug); #endif WriteSearch(debug, "InterpolateSearch.csv"); throw new VectoSearchFailedException("Failed to find operating point! points: {0}", debug.LocalData.Select(d => d.b).Join()); diff --git a/VectoCore/VectoCoreTest/Utils/MockBrakes.cs b/VectoCore/VectoCoreTest/Utils/MockBrakes.cs index 755580cfdaac54c5bb8776c400073a7a9cba8365..eba2ca40b3d624acc1d5e0c3fc28dde1ae9fcdde 100644 --- a/VectoCore/VectoCoreTest/Utils/MockBrakes.cs +++ b/VectoCore/VectoCoreTest/Utils/MockBrakes.cs @@ -36,7 +36,7 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Tests.Utils { - public class MockBrakes : VectoSimulationComponent, IBrakes + public class MockBrakes : VectoSimulationComponent, IBrakes, IUpdateable { public MockBrakes(IVehicleContainer vehicle) : base(vehicle) { @@ -48,5 +48,18 @@ namespace TUGraz.VectoCore.Tests.Utils protected override void DoWriteModalResults(Second time, Second simulationInterval, IModalDataContainer container) {} protected override void DoCommitSimulationStep(Second time, Second simulationInterval) {} + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is IBrakes b) { + BrakePower = b.BrakePower; + return true; + } + + return false; + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/Utils/MockGearbox.cs b/VectoCore/VectoCoreTest/Utils/MockGearbox.cs index 8f656aa0f2f11b41ab940f0c0c43e3ea5b921a6d..1e83d9820061133dbf102f5aa7fb910f448d731b 100644 --- a/VectoCore/VectoCoreTest/Utils/MockGearbox.cs +++ b/VectoCore/VectoCoreTest/Utils/MockGearbox.cs @@ -131,6 +131,8 @@ namespace TUGraz.VectoCore.Tests.Utils return _clutchClosed; } + public bool RequestAfterGearshift { get; set; } + public bool ClutchClosed(Second absTime) { return _clutchClosed; diff --git a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs index 54b0580661a7a5ebf6b8e35c8b34976eebc24649..911ee8289e38a8bb17690705a5994278382a8449 100644 --- a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs +++ b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs @@ -48,7 +48,7 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Tests.Utils { - public class MockVehicleContainer : IVehicleContainer, IEngineInfo, IEngineControl, IVehicleInfo, IClutchInfo, IBrakes, IAxlegearInfo, IWheelsInfo, IDriverInfo, IDrivingCycleInfo, IMileageCounter, IGearboxInfo, IGearboxControl, IPowertainInfo + public class MockVehicleContainer : IVehicleContainer, IEngineInfo, IEngineControl, IVehicleInfo, IClutchInfo, IBrakes, IAxlegearInfo, IWheelsInfo, IDriverInfo, IDrivingCycleInfo, IMileageCounter, IGearboxInfo, IGearboxControl, IPowertainInfo, IUpdateable { // only CycleData Lookup is set / accessed... @@ -315,6 +315,8 @@ namespace TUGraz.VectoCore.Tests.Utils return ClutchClosed(absTime); } + public bool RequestAfterGearshift { get; set; } + #endregion public IEnumerable<ISimulationPreprocessor> GetPreprocessingRuns { get { return new ISimulationPreprocessor[] { }; } } @@ -337,5 +339,13 @@ namespace TUGraz.VectoCore.Tests.Utils public VectoSimulationJobType VehicleArchitecutre { get; } #endregion + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + return false; + } + + #endregion } } \ No newline at end of file