diff --git a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs index 5143a36743667381234311908191c4d4eb7d5ab4..ed6f39ed1639b8d72bbaaa7d224cdf3c5674671f 100644 --- a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs +++ b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs @@ -275,7 +275,16 @@ namespace TUGraz.VectoCommon.InputData /// P021 /// cf. VECTO Input Parameters.xlsx /// </summary> - MeterPerSecond MinSpeed { get; } + //MeterPerSecond MinSpeed { get; } + double CoastingDecisionFactorOffset { get; } + + double CoastingDecisionFactorScaling { get; } + + double LookaheadDistanceFactor { get; } + + DataTable CoastingDecisionFactorTargetSpeedLookup { get; } + + DataTable CoastingDecisionFactorVelocityDropLookup { get; } } public interface IAuxiliaryEngineeringInputData : IAuxiliaryDeclarationInputData diff --git a/VectoCommon/VectoCommon/Utils/VectoMath.cs b/VectoCommon/VectoCommon/Utils/VectoMath.cs index 1179151b9fede73f232e575a751d039316a04d4b..484a0aa94b6a821c8435cd278b9266cf8ebd09d5 100644 --- a/VectoCommon/VectoCommon/Utils/VectoMath.cs +++ b/VectoCommon/VectoCommon/Utils/VectoMath.cs @@ -109,6 +109,11 @@ namespace TUGraz.VectoCore.Utils return c1.CompareTo(c2) >= 0 ? c1 : c2; } + public static T Max<T>(T c1, T c2, T c3) where T : IComparable + { + return Max(Max(c1, c2), c3); + } + public static T Limit<T>(this T value, T lowerBound, T upperBound) where T : IComparable { if (lowerBound.CompareTo(upperBound) > 0) { diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index ffbf6bab3609efb177172eb292eee4d0d95d78c2..034dc18b321e39e4e6f186a1d0ca5dbe5de42ecf 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -265,7 +265,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON public virtual IVehicleEngineeringInputData VehicleInputData { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", + "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] get { if (VehicleData == null) { @@ -277,7 +278,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON public virtual IGearboxEngineeringInputData GearboxInputData { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", + "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] get { if (Gearbox == null) { @@ -289,7 +291,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON public virtual IAxleGearInputData AxleGearInputData { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", + "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] get { if (AxleGear == null) { @@ -306,7 +309,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON public virtual IEngineEngineeringInputData EngineInputData { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", + "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] get { if (Engine == null) { @@ -333,7 +337,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON public virtual IRetarderInputData RetarderInputData { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", + "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] get { if (Retarder == null) { @@ -359,7 +364,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON public virtual IList<ICycleData> Cycles { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", + "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] get { var retVal = new List<ICycleData>(); @@ -441,6 +447,14 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON Enabled = lac.GetEx<bool>(JsonKeys.DriverData_Lookahead_Enabled), Deceleration = lac.GetEx<double>(JsonKeys.DriverData_Lookahead_Deceleration).SI<MeterPerSquareSecond>(), MinSpeed = lac.GetEx<double>(JsonKeys.DriverData_Lookahead_MinSpeed).KMPHtoMeterPerSecond(), + LookaheadDistanceFactor = lac.GetEx<double>("PreviewDistanceFactor"), + CoastingDecisionFactorOffset = lac.GetEx<double>("DF_offset"), + CoastingDecisionFactorScaling = lac.GetEx<double>("DF_scaling"), + CoastingDecisionFactorTargetSpeedLookup = + ReadTableData(lac.GetEx<string>("DF_targetSpeedLookup"), "Lookahead Coasting Decisionfactor - Target speed", false), + CoastingDecisionFactorVelocityDropLookup = ReadTableData(lac.GetEx<string>("Df_velocityDropLookup"), + "Lookahead Coasting Decisionfactor - Velocity drop", + false) }; } } @@ -467,7 +481,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON public virtual DataTable AccelerationCurve { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", + "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] get { var acceleration = Body[JsonKeys.DriverData_AccelerationCurve]; diff --git a/VectoCore/VectoCore/InputData/Impl/InputData.cs b/VectoCore/VectoCore/InputData/Impl/InputData.cs index f412415e9c5d489f38ee074bbb90d671c7db3ab0..3e637a227b74da0a023e09e699ddb75bec983a38 100644 --- a/VectoCore/VectoCore/InputData/Impl/InputData.cs +++ b/VectoCore/VectoCore/InputData/Impl/InputData.cs @@ -62,6 +62,12 @@ namespace TUGraz.VectoCore.InputData.Impl public MeterPerSquareSecond Deceleration { get; internal set; } public MeterPerSecond MinSpeed { get; internal set; } + + public double CoastingDecisionFactorOffset { get; internal set; } + public double CoastingDecisionFactorScaling { get; internal set; } + public double LookaheadDistanceFactor { get; internal set; } + public DataTable CoastingDecisionFactorTargetSpeedLookup { get; internal set; } + public DataTable CoastingDecisionFactorVelocityDropLookup { get; internal set; } } public class OverSpeedEcoRollInputData : IOverSpeedEcoRollEngineeringInputData @@ -92,10 +98,11 @@ namespace TUGraz.VectoCore.InputData.Impl public class AxleInputData : IAxleEngineeringInputData { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", + "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")] public bool SavedInDeclarationMode { - get {throw new System.NotImplementedException(); } + get { throw new System.NotImplementedException(); } } public string Vendor { get; internal set; } diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs index 33966847e518f1c1c37e36c20efe0288e4e07bd3..bfe0af29c587e5287e7e72465fbab6dd89aed04d 100644 --- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs +++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs @@ -58,7 +58,9 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdaper var lookAheadData = new DriverData.LACData { Enabled = DeclarationData.Driver.LookAhead.Enabled, //Deceleration = DeclarationData.Driver.LookAhead.Deceleration, - MinSpeed = DeclarationData.Driver.LookAhead.MinimumSpeed + MinSpeed = DeclarationData.Driver.LookAhead.MinimumSpeed, + LookAheadDecisionFactor = new LACDecisionFactor(), + LookAheadDistanceFactor = 10, }; var overspeedData = new DriverData.OverSpeedEcoRollData { Mode = data.OverSpeedEcoRoll.Mode, diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs index 8a6a795af2216de1b723438031fa6711d3b2f8e4..2a83d9e698b1565d16430a0af3f87232487788c7 100644 --- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs +++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs @@ -196,7 +196,12 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdaper var lookAheadData = new DriverData.LACData { Enabled = driver.Lookahead.Enabled, //Deceleration = driver.Lookahead.Deceleration, - MinSpeed = driver.Lookahead.MinSpeed, + //MinSpeed = driver.Lookahead.MinSpeed, + LookAheadDecisionFactor = + new LACDecisionFactor(driver.Lookahead.CoastingDecisionFactorOffset, driver.Lookahead.CoastingDecisionFactorScaling, + driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup, + driver.Lookahead.CoastingDecisionFactorVelocityDropLookup), + LookAheadDistanceFactor = driver.Lookahead.LookaheadDistanceFactor }; var overspeedData = new DriverData.OverSpeedEcoRollData { Mode = driver.OverSpeedEcoRoll.Mode, diff --git a/VectoCore/VectoCore/Models/Declaration/LACDecisionFactor.cs b/VectoCore/VectoCore/Models/Declaration/LACDecisionFactor.cs index 5c9ca9f40f4a74f78b0cb229593fb2771c3b64a0..eed98aa327f3fa8407285d52cbb3478746dfa0c4 100644 --- a/VectoCore/VectoCore/Models/Declaration/LACDecisionFactor.cs +++ b/VectoCore/VectoCore/Models/Declaration/LACDecisionFactor.cs @@ -6,11 +6,21 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public static class LACDecisionFactor + public class LACDecisionFactor { - private static readonly DecisionFactor LAC = new DecisionFactor(); + private readonly DecisionFactor LAC; - public static double Lookup(MeterPerSecond targetVelocity, MeterPerSecond velocityDrop) + public LACDecisionFactor() + { + LAC = new DecisionFactor(); + } + + public LACDecisionFactor(double offset, double scaling, DataTable vTargetLookup, DataTable vDropLookup) + { + LAC = new DecisionFactor(offset, scaling, vTargetLookup, vDropLookup); + } + + public double Lookup(MeterPerSecond targetVelocity, MeterPerSecond velocityDrop) { return LAC.Lookup(targetVelocity, velocityDrop); } @@ -20,13 +30,32 @@ namespace TUGraz.VectoCore.Models.Declaration /// </summary> private sealed class DecisionFactor : LookupData<MeterPerSecond, MeterPerSecond, double> { - private readonly LACDecisionFactorVTarget _vTarget = new LACDecisionFactorVTarget(); - private readonly LACDecisionFactorVdrop _vDrop = new LACDecisionFactorVdrop(); + private readonly LACDecisionFactorVTarget _vTarget; + private readonly LACDecisionFactorVdrop _vDrop; + private readonly double _offset; + private readonly double _scaling; + + public DecisionFactor(double offset, double scaling, DataTable vTargetLookup, DataTable vDropLookup) + { + _offset = offset; + _scaling = scaling; + _vTarget = new LACDecisionFactorVTarget(vTargetLookup); + _vDrop = new LACDecisionFactorVdrop(vDropLookup); + } + + public DecisionFactor() + { + _offset = 2.5; + _scaling = 1.5; + _vTarget = new LACDecisionFactorVTarget(); + _vDrop = new LACDecisionFactorVdrop(); + } + public override double Lookup(MeterPerSecond targetVelocity, MeterPerSecond velocityDrop) { // normalize values inverse from [0 .. 1] to [2.5 .. 1] - return 2.5 - 1.5 * _vTarget.Lookup(targetVelocity) * _vDrop.Lookup(velocityDrop); + return _offset - _scaling * _vTarget.Lookup(targetVelocity) * _vDrop.Lookup(velocityDrop); } protected override void ParseData(DataTable table) {} @@ -40,6 +69,11 @@ namespace TUGraz.VectoCore.Models.Declaration ParseData(ReadCsvResource(ResourceId)); } + public LACDecisionFactorVdrop(DataTable vDrop) + { + ParseData(vDrop ?? ReadCsvResource(ResourceId)); + } + public override double Lookup(MeterPerSecond targetVelocity) { var section = Data.GetSection(kv => kv.Key < targetVelocity); @@ -77,6 +111,11 @@ namespace TUGraz.VectoCore.Models.Declaration ParseData(ReadCsvResource(ResourceId)); } + public LACDecisionFactorVTarget(DataTable vTargetLookup) + { + ParseData(vTargetLookup ?? ReadCsvResource(ResourceId)); + } + public override double Lookup(MeterPerSecond targetVelocity) { var section = Data.GetSection(kv => kv.Key < targetVelocity); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/DriverData.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/DriverData.cs index 0d59ed65f85511253e05bd01adcca9acf094f3b9..7a9edd0cc632be5fcc1f463e53a94ae8b33c8244 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Data/DriverData.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/DriverData.cs @@ -31,6 +31,7 @@ using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation.Data; namespace TUGraz.VectoCore.Models.SimulationComponent.Data @@ -60,6 +61,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public bool Enabled; //public MeterPerSquareSecond Deceleration; public MeterPerSecond MinSpeed; + + public double LookAheadDistanceFactor; + public LACDecisionFactor LookAheadDecisionFactor; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs index 27a6ef06c48f37773e31320feb5976ad318309c7..c2ebce67e71082662da050ece3d13f0006acec1e 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs @@ -277,8 +277,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var currentSpeed = Driver.DataBus.VehicleSpeed; // distance until halt - var lookaheadDistance = (currentSpeed.Value() * 3.6 * 10).SI<Meter>(); - lookaheadDistance = VectoMath.Max(2 * ds, 1.2 * lookaheadDistance); + var lookaheadDistance = + (currentSpeed.Value() * 3.6 * Driver.DriverData.LookAheadCoasting.LookAheadDistanceFactor).SI<Meter>(); + var stopDistance = Driver.ComputeDecelerationDistance(0.SI<MeterPerSecond>()); + lookaheadDistance = VectoMath.Max(2 * ds, lookaheadDistance, 1.2 * stopDistance); var lookaheadData = Driver.DataBus.LookAhead(lookaheadDistance); Log.Debug("Lookahead distance: {0} @ current speed {1}", lookaheadDistance, currentSpeed); @@ -364,7 +366,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl //var CDP = F_dec_average / -F_coasting; - var DF_coasting = LACDecisionFactor.Lookup(v_target, v_veh - v_target); + var DF_coasting = Driver.DriverData.LookAheadCoasting.LookAheadDecisionFactor.Lookup(v_target, v_veh - v_target); var delta_x = (delta_E / (DF_coasting * F_coasting)).Cast<Meter>(); @@ -446,7 +448,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl //DriverStrategy.BrakeTrigger = DriverStrategy.NextDrivingAction; } - var newOperatingPoint = VectoMath.ComputeTimeInterval(DataBus.VehicleSpeed, response.Acceleration, DataBus.Distance, ds); + var newOperatingPoint = VectoMath.ComputeTimeInterval(DataBus.VehicleSpeed, response.Acceleration, DataBus.Distance, + ds); if (newOperatingPoint.SimulationInterval.IsSmaller(Constants.SimulationSettings.LowerBoundTimeInterval)) { // the next time interval will be too short, this may lead to issues with inertia etc. // instead of accelerating, drive at constant speed.