diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs index 551e52b2f5ae04b886ec6c16935cf7d01c41c382..b0477968cf035ce631accd57c3eac4269bd9c0ae 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs @@ -111,13 +111,13 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl // PWheelCycle --> AxleGear --> Clutch --> Engine <-- Aux var powertrain = new PWheelCycle(container, data.Cycle, data.AxleGearData.AxleGear.Ratio, data.VehicleData, - gearbox.ModelData.Gears.ToDictionary(g => g.Key, g => g.Value.Ratio)) + gearbox.ModelData.Gears.ToDictionary(g => g.Key, g => g.Value.Ratio)) .AddComponent(new AxleGear(container, data.AxleGearData)) .AddComponent(data.AngledriveData != null ? new Angledrive(container, data.AngledriveData) : null) .AddComponent(gearbox, data.Retarder, container) .AddComponent(new Clutch(container, data.EngineData)); var engine = new CombustionEngine(container, data.EngineData, pt1Disabled: true); - var idleController = GetIdleController(data.PTO, engine); + var idleController = GetIdleController(data.PTO, engine, container); powertrain.AddComponent(engine, idleController) .AddAuxiliaries(container, data); @@ -148,7 +148,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } var engine = new CombustionEngine(container, data.EngineData); - var idleController = GetIdleController(data.PTO, engine); + var idleController = GetIdleController(data.PTO, engine, container); powertrain.AddComponent(engine, idleController) .AddAuxiliaries(container, data); @@ -208,7 +208,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } var engine = new CombustionEngine(container, data.EngineData); - var idleController = GetIdleController(data.PTO, engine); + var idleController = GetIdleController(data.PTO, engine, container); cycle.IdleController = idleController as IdleControllerSwitcher; powertrain.AddComponent(engine, idleController) @@ -219,12 +219,12 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl return container; } - private static IIdleController GetIdleController(PTOData pto, ICombustionEngine engine) + private static IIdleController GetIdleController(PTOData pto, ICombustionEngine engine, IVehicleContainer container) { var controller = engine.IdleController; if (pto != null && pto.PTOCycle != null) { - var ptoController = new PTOCycleController(pto.PTOCycle); + var ptoController = new PTOCycleController(container, pto.PTOCycle); controller = new IdleControllerSwitcher(engine.IdleController, ptoController); } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PTOCycleController.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PTOCycleController.cs index ae0b89117951da85948703a794296b3c761ada39..91bcd94fbee7a29f0ae4317397056c430bc50ca0 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PTOCycleController.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PTOCycleController.cs @@ -29,7 +29,6 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System; using System.Linq; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; @@ -37,6 +36,7 @@ using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Connector.Ports; 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.OutputData; @@ -45,7 +45,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public class PTOCycleController : PowertrainDrivingCycle, IIdleController { - public ITnOutPort RequestPort { + public ITnOutPort RequestPort + { set { NextComponent = value; } } @@ -53,8 +54,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected Second IdleStart; - public PTOCycleController(DrivingCycleData cycle) : base(null, cycle) + public PTOCycleController(IVehicleContainer container, IDrivingCycleData cycle) + : base(null, cycle) { + DataBus = container; Duration = Data.Entries.Last().Time - Data.Entries.First().Time; } @@ -62,13 +65,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl bool dryRun = false) { if (outAngularVelocity != null) { - throw new VectoException("{0} can only handle idle requests: AngularVelocity has to be null!", GetType().ToString()); + throw new VectoException("{0} can only handle idle requests: AngularVelocity has to be null!", + GetType().ToString()); } if (!outTorque.IsEqual(0)) { throw new VectoException("{0} can only handle idle requests: Torque has to be 0!", GetType().ToString()); } if (IdleStart == null) { IdleStart = absTime; + PreviousState.InAngularVelocity = DataBus.EngineSpeed; } return base.Request(absTime - IdleStart, dt); } @@ -81,7 +86,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public void Reset() { CycleIterator.Reset(); - PreviousState.InAngularVelocity = CycleIterator.LeftSample.AngularVelocity; IdleStart = null; } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs b/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs index 2ccd9340152c2014dc40af21c12fc8e0218ee621..a6f038af1abda1881925d29ae3dd06e4c4eee561 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs @@ -1,147 +1,147 @@ -/* -* This file is part of VECTO. -* -* Copyright © 2012-2016 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 -*/ - -using System; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Models.Simulation; -using TUGraz.VectoCore.Models.Simulation.DataBus; -using TUGraz.VectoCore.OutputData; - -namespace TUGraz.VectoCore.Models.SimulationComponent -{ - /// <summary> - /// Base class for all vecto simulation components. - /// </summary> - public abstract class VectoSimulationComponent : LoggingObject - { - [NonSerialized] protected readonly IDataBus DataBus; - - /// <summary> - /// Constructor. Registers the component in the cockpit. - /// </summary> - /// <param name="dataBus">The vehicle container</param> - protected VectoSimulationComponent(IVehicleContainer dataBus) - { - DataBus = dataBus; - - // if a component doesn't want to be registered in DataBus, it supplies null to the constructor - // (mk 2016-08-31: currently the only example is PTOCycleController, to not interfere with the real DrivingCycle) - if (dataBus != null) - dataBus.AddComponent(this); - } - - public virtual void CommitSimulationStep(IModalDataContainer container) - { - if (container != null) { - DoWriteModalResults(container); - } - DoCommitSimulationStep(); - } - - protected abstract void DoWriteModalResults(IModalDataContainer container); - - /// <summary> - /// Commits the simulation step. - /// Writes the moddata into the data writer. - /// Commits the internal state of the object if needed. - /// </summary> - protected abstract void DoCommitSimulationStep(); - } - - public abstract class StatefulVectoSimulationComponent<TStateType> : VectoSimulationComponent where TStateType : new() - { - protected internal TStateType CurrentState; - protected internal TStateType PreviousState; - - protected StatefulVectoSimulationComponent(IVehicleContainer container) - : base(container) - { - CurrentState = new TStateType(); - PreviousState = new TStateType(); - } - - protected void AdvanceState() - { - PreviousState = CurrentState; - CurrentState = new TStateType(); - } - } - - public abstract class StatefulProviderComponent<TStateType, TProviderOutPort, TProviderInPort, TOutPort> : - StatefulVectoSimulationComponent<TStateType> - where TStateType : new() - where TProviderOutPort : class - where TProviderInPort : class - { - protected TOutPort NextComponent; - - protected StatefulProviderComponent(IVehicleContainer container) : base(container) {} - - public TProviderOutPort OutPort() - { - return this as TProviderOutPort; - } - - public TProviderInPort InPort() - { - return this as TProviderInPort; - } - - public virtual void Connect(TOutPort other) - { - NextComponent = other; - } - - protected override void DoCommitSimulationStep() - { - AdvanceState(); - } - } - - public class SimpleComponentState - { - public NewtonMeter OutTorque = 0.SI<NewtonMeter>(); - public NewtonMeter InTorque = 0.SI<NewtonMeter>(); - - public PerSecond OutAngularVelocity = 0.SI<PerSecond>(); - public PerSecond InAngularVelocity = 0.SI<PerSecond>(); - - public void SetState(NewtonMeter inTorque, PerSecond inAngularVelocity, NewtonMeter outTorque, - PerSecond outAngularVelocity) - { - InTorque = inTorque; - InAngularVelocity = inAngularVelocity; - OutTorque = outTorque; - OutAngularVelocity = outAngularVelocity; - } - } +/* +* This file is part of VECTO. +* +* Copyright © 2012-2016 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 +*/ + +using System; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Simulation; +using TUGraz.VectoCore.Models.Simulation.DataBus; +using TUGraz.VectoCore.OutputData; + +namespace TUGraz.VectoCore.Models.SimulationComponent +{ + /// <summary> + /// Base class for all vecto simulation components. + /// </summary> + public abstract class VectoSimulationComponent : LoggingObject + { + [NonSerialized] protected IDataBus DataBus; + + /// <summary> + /// Constructor. Registers the component in the cockpit. + /// </summary> + /// <param name="dataBus">The vehicle container</param> + protected VectoSimulationComponent(IVehicleContainer dataBus) + { + DataBus = dataBus; + + // if a component doesn't want to be registered in DataBus, it supplies null to the constructor + // (mk 2016-08-31: currently the only example is PTOCycleController, in order to not interfere with the real DrivingCycle) + if (dataBus != null) + dataBus.AddComponent(this); + } + + public virtual void CommitSimulationStep(IModalDataContainer container) + { + if (container != null) { + DoWriteModalResults(container); + } + DoCommitSimulationStep(); + } + + protected abstract void DoWriteModalResults(IModalDataContainer container); + + /// <summary> + /// Commits the simulation step. + /// Writes the moddata into the data writer. + /// Commits the internal state of the object if needed. + /// </summary> + protected abstract void DoCommitSimulationStep(); + } + + public abstract class StatefulVectoSimulationComponent<TStateType> : VectoSimulationComponent where TStateType : new() + { + protected internal TStateType CurrentState; + protected internal TStateType PreviousState; + + protected StatefulVectoSimulationComponent(IVehicleContainer container) + : base(container) + { + CurrentState = new TStateType(); + PreviousState = new TStateType(); + } + + protected void AdvanceState() + { + PreviousState = CurrentState; + CurrentState = new TStateType(); + } + } + + public abstract class StatefulProviderComponent<TStateType, TProviderOutPort, TProviderInPort, TOutPort> : + StatefulVectoSimulationComponent<TStateType> + where TStateType : new() + where TProviderOutPort : class + where TProviderInPort : class + { + protected TOutPort NextComponent; + + protected StatefulProviderComponent(IVehicleContainer container) : base(container) { } + + public TProviderOutPort OutPort() + { + return this as TProviderOutPort; + } + + public TProviderInPort InPort() + { + return this as TProviderInPort; + } + + public virtual void Connect(TOutPort other) + { + NextComponent = other; + } + + protected override void DoCommitSimulationStep() + { + AdvanceState(); + } + } + + public class SimpleComponentState + { + public NewtonMeter OutTorque = 0.SI<NewtonMeter>(); + public NewtonMeter InTorque = 0.SI<NewtonMeter>(); + + public PerSecond OutAngularVelocity = 0.SI<PerSecond>(); + public PerSecond InAngularVelocity = 0.SI<PerSecond>(); + + public void SetState(NewtonMeter inTorque, PerSecond inAngularVelocity, NewtonMeter outTorque, + PerSecond outAngularVelocity) + { + InTorque = inTorque; + InAngularVelocity = inAngularVelocity; + OutTorque = outTorque; + OutAngularVelocity = outAngularVelocity; + } + } } \ No newline at end of file