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/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/Impl/PowertrainBuilder.cs b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs index 0fae92d6312ad372e901b6a82813e084be0dcfcf..c4f3fb4794db4ebad7c7be4950739e1d881a7947 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs @@ -1636,7 +1636,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } } - public class SimpleCharger : IElectricChargerPort + public class SimpleCharger : IElectricChargerPort, IUpdateable { #region Implementation of IElectricChargerPort @@ -1659,6 +1659,24 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } #endregion + + #region Implementation of IUpdateable + public bool UpdateFrom(object other) + { + if (other is IElectricSystemInfo es) { + _chargingPower = es.ChargePower; + return true; + } + + if (other is Watt w) { + _chargingPower = w; + return true; + } + + return false; + } + + #endregion } internal class DummyEngineInfo : VectoSimulationComponent, IEngineInfo, IEngineControl diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index 182243953ca8db344caa0fa760ecda4cf0134093..e951a3e2dd1c3baeeb1bfc002445c044ab6fc859 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -198,8 +198,45 @@ 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) { + var found = false; + if (c is IUpdateable target) { + foreach (var (_, source) in (realContainer as VehicleContainer)._components) { + if (target.UpdateFrom(source)) { + ComponentUpdateList.Add((target, source)); + found = true; + } + } + } + + #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) { 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/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..794bcf3a579c43dd353e349d2f907ef72f6be91f 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATGearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATGearbox.cs @@ -45,7 +45,7 @@ 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; @@ -581,8 +581,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public bool Disengaged = true; public WattSecond PowershiftLossEnergy; public NewtonMeter PowershiftLoss; + + public 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; + EngineInertia = g.EngineInertia; + Disengaged = g.Disengaged; + SwitchToNeutral = g.SwitchToNeutral; + RequestAfterGearshift = g.RequestAfterGearshift; + LastShift = g.LastShift; + return true; + } + + if (other is GearshiftPosition p) { + Gear = p; + DisengageGearbox = !p.Engaged; + Disengaged = !p.Engaged; + 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..14028b6418dd6db6302adab9007b98e611c9b941 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AbstractGearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AbstractGearbox.cs @@ -170,5 +170,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 3465fa90b62566887383800703b6b2e56988954a..f8f1527f75c7f70671782e6d530c4e7fe6bd628a 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs @@ -396,6 +396,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 @@ -433,5 +435,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..83b97ab25e555fd6966636b7606ce6a50baa83d7 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 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/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/ElectricMotor.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs index 69ad5fe4a116341f53ad34188a71f8c501187625..be9862dd999564a31a3da49a847e832d9b6a3ef9 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs @@ -14,7 +14,8 @@ 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 +577,22 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { return emSpeed / ModelData.RatioADC; } + + #region Implementation of IUpdateable + + public bool UpdateFrom(object other) { + if (other is ElectricMotor e) { + PreviousState = e.PreviousState.Clone(); + ElectricPower = e.ElectricPower; + ThermalBuffer = e.ThermalBuffer; + DeRatingActive = e.DeRatingActive; + return true; + } + + return false; + } + + #endregion } public class ElectricMotorState // : SimpleComponentState @@ -603,5 +620,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..3b0ce5332ac3869c977c64c1b6e7370b4d33e285 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,38 @@ 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(); + Disengaged = g.Disengaged; + DisengageGearbox = g.DisengageGearbox; + _nextGear = g.NextGear; + Gear = g.Gear; + + if (DataBus.VehicleInfo.VehicleStopped) { + Gear = _nextGear; + } + + return true; + } + + if (other is GearshiftPosition p) { + _nextGear = p; + DisengageGearbox = !p.Engaged; + Disengaged = !p.Engaged; + return true; + } + + if (other is GearboxState s) { + PreviousState = s.Clone(); + } + + 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/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/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/TestPowertrain.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/TestPowertrain.cs index 42c94ada790908d2e4738c008ef42098078168a5..9f93aba3f9c0fdd032594ea316578b2c2005664d 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,6 +114,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } //Brakes = new MockBrakes(container); } + + public void UpdateComponents() => Container.UpdateComponents(RealContainer); } public class MockBrakes : VectoSimulationComponent, IBrakes diff --git a/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs b/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs index 9b8d9bbe851ce95fcb5c2485e95e731f112560f8..dd5b241a7971d79b5af9feb77010802ba9e53014 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs @@ -9,7 +9,7 @@ using TUGraz.VectoCore.Models.SimulationComponent.Impl; namespace TUGraz.VectoCore.Models.SimulationComponent { - public class SwitchableClutch : Clutch + public class SwitchableClutch : Clutch, IUpdateable { public SwitchableClutch(IVehicleContainer container, CombustionEngineData engineData) : base(container, engineData) { } @@ -142,5 +142,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent #endregion #endregion + + #region Implementation of IUpdateable + + public 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