diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationAuxiliaryDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationAuxiliaryDataProvider.cs index bb1e8cc69fa086ed4a5e7a21b418fcac1143c091..fa7a277c72f09ae52ab9542872e7591994dcde30 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationAuxiliaryDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationAuxiliaryDataProvider.cs @@ -29,50 +29,50 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Collections.Generic; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.InputData.Impl; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration -{ - public class XMLDeclarationAuxiliaryDataProvider : AbstractDeclarationXMLComponentDataProvider, - IAuxiliariesDeclarationInputData - { - public XMLDeclarationAuxiliaryDataProvider(XMLDeclarationInputDataProvider xmlInputDataProvider) : base(xmlInputDataProvider) - { - XBasePath = Helper.Query(VehiclePath, - XMLNames.Vehicle_Components, - XMLNames.Component_Auxiliaries, - XMLNames.ComponentDataWrapper); - } - - - public IList<IAuxiliaryDeclarationInputData> Auxiliaries - { - get - { - var retVal = new List<IAuxiliaryDeclarationInputData>(); - var auxiliaries = Navigator.Select(Helper.Query(XBasePath, - Helper.QueryConstraint("*", - Helper.NSPrefix(XMLNames.Auxiliaries_Auxiliary_Technology), null, "")), - Manager); - - while (auxiliaries.MoveNext()) { - var techlistNodes = auxiliaries.Current.Select(Helper.NSPrefix(XMLNames.Auxiliaries_Auxiliary_Technology), Manager); - var technologyList = new List<string>(); - while (techlistNodes.MoveNext()) { - technologyList.Add(techlistNodes.Current.Value); - } - retVal.Add(new AuxiliaryDataInputData { - Type = auxiliaries.Current.Name.ParseEnum<AuxiliaryType>(), - Technology = technologyList, - }); - } - return retVal; - } - } - } +using System.Collections.Generic; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.InputData.Impl; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration +{ + public class XMLDeclarationAuxiliaryDataProvider : AbstractDeclarationXMLComponentDataProvider, + IAuxiliariesDeclarationInputData + { + public XMLDeclarationAuxiliaryDataProvider(XMLDeclarationInputDataProvider xmlInputDataProvider) : base(xmlInputDataProvider) + { + XBasePath = Helper.Query(VehiclePath, + XMLNames.Vehicle_Components, + XMLNames.Component_Auxiliaries, + XMLNames.ComponentDataWrapper); + } + + + public IList<IAuxiliaryDeclarationInputData> Auxiliaries + { + get + { + var retVal = new List<IAuxiliaryDeclarationInputData>(); + var auxiliaries = Navigator.Select(Helper.Query(XBasePath, + Helper.QueryConstraint("*", + Helper.NSPrefix(XMLNames.Auxiliaries_Auxiliary_Technology), null, "")), + Manager); + + while (auxiliaries.MoveNext()) { + var techlistNodes = auxiliaries.Current.Select(Helper.NSPrefix(XMLNames.Auxiliaries_Auxiliary_Technology), Manager); + var technologyList = new List<string>(); + while (techlistNodes.MoveNext()) { + technologyList.Add(techlistNodes.Current.Value); + } + retVal.Add(new AuxiliaryDataInputData { + Type = auxiliaries.Current.Name.ParseEnum<AuxiliaryType>(), + Technology = technologyList, + }); + } + return retVal; + } + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Simulation/DataBus/IDataBus.cs b/VectoCore/VectoCore/Models/Simulation/DataBus/IDataBus.cs index 292497a44ed911d50203b64645f6e79fd0f3ddd9..c7414b8e7db5382064881094e7c1ebaa4b1f1c97 100644 --- a/VectoCore/VectoCore/Models/Simulation/DataBus/IDataBus.cs +++ b/VectoCore/VectoCore/Models/Simulation/DataBus/IDataBus.cs @@ -29,22 +29,22 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Models.SimulationComponent; - -namespace TUGraz.VectoCore.Models.Simulation.DataBus -{ - /// <summary> - /// Defines interfaces for all different cockpits to access shared data of the powertrain. - /// </summary> - public interface IDataBus : IGearboxInfo, IAxlegearInfo, IEngineInfo, IVehicleInfo, IMileageCounter, IClutchInfo, - IBrakes, IWheelsInfo, IDriverInfo, IDrivingCycleInfo - { - ExecutionMode ExecutionMode { get; } - - FuelType FuelType { get; } - - Second AbsTime { get; set; } - } +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.SimulationComponent; + +namespace TUGraz.VectoCore.Models.Simulation.DataBus +{ + /// <summary> + /// Defines interfaces for all different cockpits to access shared data of the powertrain. + /// </summary> + public interface IDataBus : IGearboxInfo, IAxlegearInfo, IEngineInfo, IVehicleInfo, IMileageCounter, IClutchInfo, + IBrakes, IWheelsInfo, IDriverInfo, IDrivingCycleInfo + { + ExecutionMode ExecutionMode { get; } + + FuelType FuelType { get; } + + Second AbsTime { get; set; } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs b/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs index cef9d77aa19e7158d8436e2e9903258597fb3532..3ae6ae60a32f6482437f4a887dc65afe2b76049e 100644 --- a/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs +++ b/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs @@ -30,6 +30,7 @@ */ using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; namespace TUGraz.VectoCore.Models.Simulation.DataBus { @@ -45,6 +46,9 @@ namespace TUGraz.VectoCore.Models.Simulation.DataBus public interface IDriverInfo { DrivingBehavior DriverBehavior { get; } + + DrivingAction DrivingAction { get; } + MeterPerSquareSecond DriverAcceleration { get; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index 84178bb81027ca293c02d90723e93ee402213a8f..57f4a2e5ea2204c41b9486cb832dc69dcf9941d9 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -299,7 +299,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl commitPriority = 6; }) .If<PTOCycleController>(c => { commitPriority = 99; }) - .If<VTPCycle>(_ => { commitPriority = 0; }); + .If<VTPCycle>(_ => { commitPriority = 0; }); _components.Add(Tuple.Create(commitPriority, component)); _components = _components.OrderBy(x => x.Item1).Reverse().ToList(); @@ -395,6 +395,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl get { return Driver != null ? Driver.DriverBehavior : DrivingBehavior.Driving; } } + public DrivingAction DrivingAction + { + get { return Driver.DrivingAction; } + } + public MeterPerSquareSecond DriverAcceleration { get { return Driver != null ? Driver.DriverAcceleration : 0.SI<MeterPerSquareSecond>(); } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs index 013be9c16d896cf441ab83cd960de5cb20b761d9..c4c0e09f98ee08516b6dae5d5741282f2ab17733 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs @@ -29,38 +29,38 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Models.Simulation; -using TUGraz.VectoCore.Models.Simulation.Data; -using TUGraz.VectoCore.Models.SimulationComponent.Data; -using TUGraz.VectoCore.OutputData; - -namespace TUGraz.VectoCore.Models.SimulationComponent.Impl -{ - public class AxleGear : TransmissionComponent, IAxlegear - { - public AxleGear(IVehicleContainer container, AxleGearData modelData) : base(container, modelData.AxleGear) {} - - public override IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, - bool dryRun = false) - { - var retVal = base.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); - retVal.AxlegearPowerRequest = outTorque * (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0; - return retVal; - } - - protected override void DoWriteModalResults(IModalDataContainer container) - { - var avgAngularVelocity = (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0; - container[ModalResultField.P_axle_loss] = (CurrentState.InTorque - CurrentState.OutTorque / ModelData.Ratio) * - avgAngularVelocity; - container[ModalResultField.P_axle_in] = CurrentState.InTorque * avgAngularVelocity; - } - - public Watt AxlegearLoss() - { - return PreviousState.TorqueLossResult.Value * PreviousState.InAngularVelocity; - } - } +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Simulation; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.OutputData; + +namespace TUGraz.VectoCore.Models.SimulationComponent.Impl +{ + public class AxleGear : TransmissionComponent, IAxlegear + { + public AxleGear(IVehicleContainer container, AxleGearData modelData) : base(container, modelData.AxleGear) {} + + public override IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, + bool dryRun = false) + { + var retVal = base.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); + retVal.AxlegearPowerRequest = outTorque * (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0; + return retVal; + } + + protected override void DoWriteModalResults(IModalDataContainer container) + { + var avgAngularVelocity = (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0; + container[ModalResultField.P_axle_loss] = (CurrentState.InTorque - CurrentState.OutTorque / ModelData.Ratio) * + avgAngularVelocity; + container[ModalResultField.P_axle_in] = CurrentState.InTorque * avgAngularVelocity; + } + + public Watt AxlegearLoss() + { + return PreviousState.TorqueLossResult.Value * PreviousState.InAngularVelocity; + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 894dd1b7096ba7193d40314f607a597d65863c86..892a126ddb379865e7fdcdd013b9b94b37e83229 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -45,6 +45,14 @@ using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { + public enum DrivingAction + { + Halt = 0, + Roll = 2, + Coast = 4, + Accelerate = 6, + Brake = -5, + } public class Driver : StatefulProviderComponent<Driver.DriverState, IDrivingCycleOutPort, IDriverDemandInPort, IDriverDemandOutPort>, IDriver, IDrivingCycleOutPort, IDriverDemandInPort, IDriverActions, IDriverInfo @@ -52,7 +60,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public DriverData DriverData { get; protected set; } protected readonly IDriverStrategy DriverStrategy; - public string CurrentAction = ""; + + public DrivingAction DrivingAction { get; private set; } public Driver(IVehicleContainer container, DriverData driverData, IDriverStrategy strategy) : base(container) { @@ -132,7 +141,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Radian gradient, IResponse previousResponse = null) { - CurrentAction = "ACCELERATE"; + DrivingAction = DrivingAction.Accelerate; IterationStatistics.Increment(this, "Accelerate"); Log.Debug("DrivingAction Accelerate"); var operatingPoint = ComputeAcceleration(ds, targetVelocity); @@ -181,6 +190,23 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl response); } + if (nextOperatingPoint == null && absTime > 0 && DataBus.VehicleStopped) { + Log.Info( + "No operating point found! Vehicle stopped! trying HALT action"); + DataBus.BrakePower = 1.SI<Watt>(); + retVal = DrivingActionHalt(absTime, operatingPoint.SimulationInterval, 0.SI<MeterPerSecond>(), gradient); + + retVal.SimulationDistance = 0.SI<Meter>(); + retVal.Acceleration = 0.SI<MeterPerSquareSecond>(); + retVal.SimulationInterval = operatingPoint.SimulationInterval; + retVal.OperatingPoint = new OperatingPoint() { + Acceleration = retVal.Acceleration, + SimulationDistance = retVal.SimulationDistance, + SimulationInterval = operatingPoint.SimulationInterval + }; + return retVal; + } + var limitedOperatingPoint = nextOperatingPoint; if (!(retVal is ResponseEngineSpeedTooHigh || DataBus.ClutchClosed(absTime))) { limitedOperatingPoint = LimitAccelerationByDriverModel(nextOperatingPoint, @@ -283,7 +309,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <returns></returns> public IResponse DrivingActionCoast(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient) { - CurrentAction = "COAST"; + DrivingAction = DrivingAction.Coast; IterationStatistics.Increment(this, "Coast"); Log.Debug("DrivingAction Coast"); @@ -300,7 +326,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <returns></returns> public IResponse DrivingActionRoll(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient) { - CurrentAction = "ROLL"; + DrivingAction = DrivingAction.Roll; IterationStatistics.Increment(this, "Roll"); Log.Debug("DrivingAction Roll"); @@ -419,7 +445,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse DrivingActionBrake(Second absTime, Meter ds, MeterPerSecond nextTargetSpeed, Radian gradient, IResponse previousResponse = null, Meter targetDistance = null) { - CurrentAction = "BRAKE"; + DrivingAction = DrivingAction.Brake; IterationStatistics.Increment(this, "Brake"); Log.Debug("DrivingAction Brake"); @@ -746,12 +772,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl retVal.Acceleration = tmp.Acceleration; retVal.SimulationInterval = tmp.SimulationInterval; retVal.SimulationDistance = tmp.SimulationDistance; + + + } else { + retVal.Acceleration = acc; + retVal.SimulationDistance = 0.SI<Meter>(); } IterationStatistics.Increment(this, "SearchOperatingPoint"); DriverAcceleration = acc; var response = NextComponent.Request(absTime, retVal.SimulationInterval, acc, gradient, true); response.OperatingPoint = retVal; return response; + }, criterion: response => { var r = (ResponseDryRun)response; @@ -768,6 +800,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var r = (ResponseDryRun)response; return r != null && !actionRoll && !ds.IsEqual(r.OperatingPoint.SimulationDistance); }); + return ComputeTimeInterval(retVal.Acceleration, retVal.SimulationDistance); } catch (VectoSearchAbortedException) { // search aborted, try to go ahead with the last acceleration } catch (Exception) { @@ -779,7 +812,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl DriverData.AccelerationCurve.MaxAcceleration())) { Log.Info("Operating Point outside driver acceleration limits: a: {0}", retVal.Acceleration); } - return ComputeTimeInterval(retVal.Acceleration, retVal.SimulationDistance); + return null; } private static Watt GetOrigDelta(IResponse initialResponse, bool coastingOrRoll, bool actionRoll) @@ -892,7 +925,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <returns></returns> public IResponse DrivingActionHalt(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { - CurrentAction = "HALT"; + DrivingAction = DrivingAction.Halt; if (!targetVelocity.IsEqual(0) || !DataBus.VehicleStopped) { Log.Error("TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!", targetVelocity, @@ -919,27 +952,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected override void DoWriteModalResults(IModalDataContainer container) { container[ModalResultField.acc] = CurrentState.Acceleration; - container.SetDataValue("DriverAction", ActionToNumber(CurrentAction)); - } - - private int ActionToNumber(string currentAction) - { - switch (currentAction.ToUpper()) { - case "HALT": - return 0; - case "ROLL": - return 2; - case "COAST": - return 4; - case "ACCELERATE": - return 6; - case "BRAKE": - return -5; - default: - return -10; - } + container.SetDataValue("DriverAction", (int)DrivingAction); } + protected override void DoCommitSimulationStep() { if (!(CurrentState.Response is ResponseSuccess)) { diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 565fabc1c82ba402b22b4a101507dd30e46753e4..477ec7b5cd4435dd4b1c2ff7529fa63a0841928b 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -178,8 +178,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _engageTime = absTime + dt; } - if (DataBus.DriverBehavior == DrivingBehavior.Braking && (DataBus.BrakePower.IsGreater(0) || outTorque < 0) && - DataBus.VehicleSpeed.IsSmaller(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed)) { + var halted = DataBus.DrivingAction == DrivingAction.Halt; + var driverDeceleratingNegTorque = DataBus.DriverBehavior == DrivingBehavior.Braking && + (DataBus.BrakePower.IsGreater(0) || outTorque < 0); + var vehiclespeedBelowThreshold = + DataBus.VehicleSpeed.IsSmaller(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed); + if (halted || (driverDeceleratingNegTorque && vehiclespeedBelowThreshold)) { _engageTime = VectoMath.Max(_engageTime, absTime + dt); return RequestGearDisengaged(absTime, dt, outTorque, outAngularVelocity, dryRun); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs index 5e156498f1e7884bf7d07737a278a463ca129b65..488de7cd83ca88aacc05da9ab59ce649b8abcd62 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/MeasuredSpeedDrivingCycle.cs @@ -389,6 +389,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public DrivingBehavior DriverBehavior { get; internal set; } + public DrivingAction DrivingAction + { + get { return DrivingAction.Accelerate; } + } + public MeterPerSquareSecond DriverAcceleration { get; protected set; } public Meter Distance diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PWheelCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PWheelCycle.cs index 4711b22174493c35df52f7cebf406809658a62ce..1f7ed4d5455279cd08f132b27168edda4f22138e 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PWheelCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PWheelCycle.cs @@ -47,38 +47,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public class PWheelCycle : PowertrainDrivingCycle, IDriverInfo, IVehicleInfo { protected bool FirstRun = true; - protected readonly VectoRunData RunData; - - /// <summary> - /// Initializes a new instance of the <see cref="PWheelCycle"/> class. - /// </summary> - /// <param name="container">The container.</param> - /// <param name="cycle">The cycle.</param> - public PWheelCycle(IVehicleContainer container, IDrivingCycleData cycle) : base(container, cycle) - { - RunData = container.RunData; - } - - protected virtual void InitializeCycleData() - { - FirstRun = false; - var gearRatios = RunData.GearboxData.Gears.ToDictionary(g => g.Key, g => g.Value.Ratio); - // just to ensure that null-gear has ratio 1 - gearRatios[0] = 1; - var axleRatio = RunData.AxleGearData.AxleGear.Ratio; - - foreach (var entry in Data.Entries) { - entry.WheelAngularVelocity = entry.AngularVelocity / (axleRatio * gearRatios[entry.Gear]); - entry.Torque = entry.PWheel / entry.WheelAngularVelocity; - } - } - - public override IResponse Initialize() - { - if (FirstRun) { - InitializeCycleData(); - - } + protected readonly VectoRunData RunData; + + /// <summary> + /// Initializes a new instance of the <see cref="PWheelCycle"/> class. + /// </summary> + /// <param name="container">The container.</param> + /// <param name="cycle">The cycle.</param> + public PWheelCycle(IVehicleContainer container, IDrivingCycleData cycle) : base(container, cycle) + { + RunData = container.RunData; + } + + protected virtual void InitializeCycleData() + { + FirstRun = false; + var gearRatios = RunData.GearboxData.Gears.ToDictionary(g => g.Key, g => g.Value.Ratio); + // just to ensure that null-gear has ratio 1 + gearRatios[0] = 1; + var axleRatio = RunData.AxleGearData.AxleGear.Ratio; + + foreach (var entry in Data.Entries) { + entry.WheelAngularVelocity = entry.AngularVelocity / (axleRatio * gearRatios[entry.Gear]); + entry.Torque = entry.PWheel / entry.WheelAngularVelocity; + } + } + + public override IResponse Initialize() + { + if (FirstRun) { + InitializeCycleData(); + + } var first = Data.Entries[0]; AbsTime = first.Time; var response = NextComponent.Initialize(first.Torque, first.WheelAngularVelocity); @@ -165,6 +165,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl get { return DrivingBehavior.Driving; } } + public DrivingAction DrivingAction + { + get { return DrivingAction.Accelerate; } + } + public MeterPerSquareSecond DriverAcceleration { get { return 0.SI<MeterPerSquareSecond>(); } diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs index 0d6304bc71c25b2dbf2cf1897fbbc0a01966e679..6a8fff1be306927bb4f73ba1f767bb202391a8c7 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs @@ -82,13 +82,13 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent public const string AngledriveLossMap = @"TestData\Components\AngleGear.vtlm"; - [OneTimeSetUp] - public void RunBeforeAnyTests() - { - Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); - } + [OneTimeSetUp] + public void RunBeforeAnyTests() + { + Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + } - private static GearboxData CreateGearboxData() + private static GearboxData CreateGearboxData() { var ratios = new[] { 6.38, 4.63, 3.44, 2.59, 1.86, 1.35, 1, 0.76 }; @@ -548,6 +548,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var container = new MockVehicleContainer() { VehicleSpeed = 10.SI<MeterPerSecond>(), DriverBehavior = DrivingBehavior.Driving, + DrivingAction = DrivingAction.Accelerate, Altitude = 0.SI<Meter>(), VehicleMass = 10000.SI<Kilogram>(), ReducedMassWheels = 100.SI<Kilogram>(), diff --git a/VectoCore/VectoCoreTest/Utils/MockDriver.cs b/VectoCore/VectoCoreTest/Utils/MockDriver.cs index b561c9ea5333be82ee1e44cb4ab2167f8609ecb2..3999f369b2a51b51f4caf0687c21ed66afe037a3 100644 --- a/VectoCore/VectoCoreTest/Utils/MockDriver.cs +++ b/VectoCore/VectoCoreTest/Utils/MockDriver.cs @@ -36,6 +36,7 @@ using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.DataBus; using TUGraz.VectoCore.Models.SimulationComponent; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Tests.Utils @@ -49,6 +50,7 @@ namespace TUGraz.VectoCore.Tests.Utils public MockDriver(IVehicleContainer container) : base(container) { DriverBehavior = DrivingBehavior.Accelerating; + DrivingAction = DrivingAction.Accelerate; } protected override void DoWriteModalResults(IModalDataContainer container) {} @@ -117,6 +119,9 @@ namespace TUGraz.VectoCore.Tests.Utils public bool VehicleStopped { get; set; } public DrivingBehavior DriverBehavior { get; set; } + + public DrivingAction DrivingAction { get; set; } + public MeterPerSquareSecond DriverAcceleration { get; set; } } } \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs index 3cd6443191aa4c920190ce135534f361aaf73ca1..df365a62f56c98810aa04bd6a0fff5cdfa6acca1 100644 --- a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs +++ b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs @@ -29,203 +29,207 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System; -using System.Collections.Generic; -using TUGraz.VectoCommon.Exceptions; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Models.Connector.Ports; -using TUGraz.VectoCore.Models.Declaration; -using TUGraz.VectoCore.Models.Simulation; -using TUGraz.VectoCore.Models.Simulation.Data; -using TUGraz.VectoCore.Models.Simulation.DataBus; -using TUGraz.VectoCore.Models.Simulation.Impl; -using TUGraz.VectoCore.Models.SimulationComponent; -using TUGraz.VectoCore.Models.SimulationComponent.Data; -using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; -using TUGraz.VectoCore.OutputData; - -namespace TUGraz.VectoCore.Tests.Utils -{ - public class MockVehicleContainer : IVehicleContainer - { - // only CycleData Lookup is set / accessed... - - public List<VectoSimulationComponent> Components = new List<VectoSimulationComponent>(); - private Watt _axlegearLoss = 0.SI<Watt>(); - private bool _clutchClosed = true; - - public IEngineInfo Engine { get; set; } - - public GearboxType GearboxType { get; set; } - - public uint Gear { get; set; } - public GearInfo NextGear { get; private set; } - - public Second TractionInterruption - { - get { return 1.SI<Second>(); } - } - - public uint NumGears { get; set; } - - public MeterPerSecond StartSpeed { get; set; } - public MeterPerSquareSecond StartAcceleration { get; set; } - public NewtonMeter GearMaxTorque { get; set; } - - public FuelType FuelType - { - get { return FuelType.DieselCI; } - } - - public Second AbsTime { get; set; } - - public Watt GearboxLoss() - { - throw new System.NotImplementedException(); - } - - public Second LastShift { get; private set; } - - public GearData GetGearData(uint gear) - { - throw new System.NotImplementedException(); - } - - public PerSecond EngineSpeed { get; set; } - public NewtonMeter EngineTorque { get; set; } - - public Watt EngineStationaryFullPower(PerSecond angularSpeed) - { - return Engine.EngineStationaryFullPower(angularSpeed); - } - - public Watt EngineDragPower(PerSecond angularSpeed) - { - return Engine.EngineStationaryFullPower(angularSpeed); - } - - public PerSecond EngineIdleSpeed - { - get { return Engine.EngineIdleSpeed; } - } - - public PerSecond EngineRatedSpeed - { - get { return Engine.EngineRatedSpeed; } - } - - public PerSecond EngineN95hSpeed - { - get { return Engine.EngineN95hSpeed; } - } - - public PerSecond EngineN80hSpeed - { - get { return Engine.EngineN80hSpeed; } - } - - public MeterPerSecond VehicleSpeed { get; set; } - public Kilogram VehicleMass { get; set; } - public Kilogram VehicleLoading { get; set; } - public Kilogram TotalMass { get; set; } - public CubicMeter CargoVolume { get; set; } - - public Newton AirDragResistance(MeterPerSecond previousVelocity, MeterPerSecond nextVelocity) - { - return 0.SI<Newton>(); - } - - public Newton RollingResistance(Radian gradient) - { - return 0.SI<Newton>(); - } - - public Newton SlopeResistance(Radian gradient) - { - return 0.SI<Newton>(); - } - - public Meter Distance { get; set; } - - public bool SetClutchClosed - { - set { _clutchClosed = value; } - } - - public bool ClutchClosed(Second absTime) - { - return _clutchClosed; - } - - public Watt BrakePower { get; set; } - public Meter CycleStartDistance { get; set; } - - public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance) - { - throw new System.NotImplementedException(); - } - - public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Second time) - { - throw new System.NotImplementedException(); - } - - public bool VehicleStopped { get; set; } - - public DrivingBehavior DriverBehavior { get; set; } - public MeterPerSquareSecond DriverAcceleration { get; set; } - - public CycleData CycleData { get; set; } - - public DrivingCycleData.DrivingCycleEntry CycleLookAhead(Meter distance) - { - return new DrivingCycleData.DrivingCycleEntry() { - RoadGradient = 0.SI<Radian>(), - Altitude = 0.SI<Meter>() - }; - } - - public Meter Altitude { get; set; } - public ExecutionMode ExecutionMode { get; set; } - public IModalDataContainer ModalData { get; set; } - public VectoRunData RunData { get; set; } - - public ISimulationOutPort GetCycleOutPort() - { - throw new System.NotImplementedException(); - } - - public VectoRun.Status RunStatus { get; set; } - - public bool PTOActive { get; private set; } - - public void AddComponent(VectoSimulationComponent component) - { - Components.Add(component); - } - - public void CommitSimulationStep(Second time, Second simulationInterval) - { - foreach (var entry in Components) { - entry.CommitSimulationStep(ModalData); - } - } - - public void FinishSimulation() {} - - public void FinishSimulationRun(Exception e) {} - - public Watt SetAxlegearLoss - { - set { _axlegearLoss = value; } - } - - public Watt AxlegearLoss() - { - return _axlegearLoss; - } - - public Kilogram ReducedMassWheels { get; set; } - } +using System; +using System.Collections.Generic; +using TUGraz.VectoCommon.Exceptions; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Connector.Ports; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.Simulation; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.Simulation.DataBus; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.Models.SimulationComponent; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.OutputData; + +namespace TUGraz.VectoCore.Tests.Utils +{ + public class MockVehicleContainer : IVehicleContainer + { + // only CycleData Lookup is set / accessed... + + public List<VectoSimulationComponent> Components = new List<VectoSimulationComponent>(); + private Watt _axlegearLoss = 0.SI<Watt>(); + private bool _clutchClosed = true; + + public IEngineInfo Engine { get; set; } + + public GearboxType GearboxType { get; set; } + + public uint Gear { get; set; } + public GearInfo NextGear { get; private set; } + + public Second TractionInterruption + { + get { return 1.SI<Second>(); } + } + + public uint NumGears { get; set; } + + public MeterPerSecond StartSpeed { get; set; } + public MeterPerSquareSecond StartAcceleration { get; set; } + public NewtonMeter GearMaxTorque { get; set; } + + public FuelType FuelType + { + get { return FuelType.DieselCI; } + } + + public Second AbsTime { get; set; } + + public Watt GearboxLoss() + { + throw new System.NotImplementedException(); + } + + public Second LastShift { get; private set; } + + public GearData GetGearData(uint gear) + { + throw new System.NotImplementedException(); + } + + public PerSecond EngineSpeed { get; set; } + public NewtonMeter EngineTorque { get; set; } + + public Watt EngineStationaryFullPower(PerSecond angularSpeed) + { + return Engine.EngineStationaryFullPower(angularSpeed); + } + + public Watt EngineDragPower(PerSecond angularSpeed) + { + return Engine.EngineStationaryFullPower(angularSpeed); + } + + public PerSecond EngineIdleSpeed + { + get { return Engine.EngineIdleSpeed; } + } + + public PerSecond EngineRatedSpeed + { + get { return Engine.EngineRatedSpeed; } + } + + public PerSecond EngineN95hSpeed + { + get { return Engine.EngineN95hSpeed; } + } + + public PerSecond EngineN80hSpeed + { + get { return Engine.EngineN80hSpeed; } + } + + public MeterPerSecond VehicleSpeed { get; set; } + public Kilogram VehicleMass { get; set; } + public Kilogram VehicleLoading { get; set; } + public Kilogram TotalMass { get; set; } + public CubicMeter CargoVolume { get; set; } + + public Newton AirDragResistance(MeterPerSecond previousVelocity, MeterPerSecond nextVelocity) + { + return 0.SI<Newton>(); + } + + public Newton RollingResistance(Radian gradient) + { + return 0.SI<Newton>(); + } + + public Newton SlopeResistance(Radian gradient) + { + return 0.SI<Newton>(); + } + + public Meter Distance { get; set; } + + public bool SetClutchClosed + { + set { _clutchClosed = value; } + } + + public bool ClutchClosed(Second absTime) + { + return _clutchClosed; + } + + public Watt BrakePower { get; set; } + public Meter CycleStartDistance { get; set; } + + public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance) + { + throw new System.NotImplementedException(); + } + + public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Second time) + { + throw new System.NotImplementedException(); + } + + public bool VehicleStopped { get; set; } + + public DrivingBehavior DriverBehavior { get; set; } + + public DrivingAction DrivingAction { get; set; } + + public MeterPerSquareSecond DriverAcceleration { get; set; } + + public CycleData CycleData { get; set; } + + public DrivingCycleData.DrivingCycleEntry CycleLookAhead(Meter distance) + { + return new DrivingCycleData.DrivingCycleEntry() { + RoadGradient = 0.SI<Radian>(), + Altitude = 0.SI<Meter>() + }; + } + + public Meter Altitude { get; set; } + public ExecutionMode ExecutionMode { get; set; } + public IModalDataContainer ModalData { get; set; } + public VectoRunData RunData { get; set; } + + public ISimulationOutPort GetCycleOutPort() + { + throw new System.NotImplementedException(); + } + + public VectoRun.Status RunStatus { get; set; } + + public bool PTOActive { get; private set; } + + public void AddComponent(VectoSimulationComponent component) + { + Components.Add(component); + } + + public void CommitSimulationStep(Second time, Second simulationInterval) + { + foreach (var entry in Components) { + entry.CommitSimulationStep(ModalData); + } + } + + public void FinishSimulation() {} + + public void FinishSimulationRun(Exception e) {} + + public Watt SetAxlegearLoss + { + set { _axlegearLoss = value; } + } + + public Watt AxlegearLoss() + { + return _axlegearLoss; + } + + public Kilogram ReducedMassWheels { get; set; } + } } \ No newline at end of file