diff --git a/VectoCore/Exceptions/VectoSimulationException.cs b/VectoCore/Exceptions/VectoSimulationException.cs index ec56daa69d127fd7fd7e9a5ad49e126acbacafa4..ff729a3660a4398f8d505e14d33e53d0afc704de 100644 --- a/VectoCore/Exceptions/VectoSimulationException.cs +++ b/VectoCore/Exceptions/VectoSimulationException.cs @@ -17,7 +17,14 @@ namespace TUGraz.VectoCore.Exceptions { public IResponse Response; - public UnexpectedResponseException(string message, IResponse resp) : base(message + " {0}", resp) + public UnexpectedResponseException(string message, IResponse resp) + : base(message + Environment.NewLine + " {0}", resp) + { + Response = resp; + } + + public UnexpectedResponseException(string message, IResponse resp, params object[] args) + : base(message + Environment.NewLine + resp, args) { Response = resp; } diff --git a/VectoCore/Models/Connector/Ports/IResponse.cs b/VectoCore/Models/Connector/Ports/IResponse.cs index bdaec9e0cdd205e27e58567346057701ec60f00b..beab66c7b6e648e0d74827db040c108bbf608775 100644 --- a/VectoCore/Models/Connector/Ports/IResponse.cs +++ b/VectoCore/Models/Connector/Ports/IResponse.cs @@ -10,8 +10,14 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// </summary> public interface IResponse { + //Second AbsTime { get; set; } + Second SimulationInterval { get; set; } + //Meter Distance { get; set; } + + Meter SimulationDistance { get; set; } + Watt EnginePowerRequest { get; set; } Watt ClutchPowerRequest { get; set; } @@ -23,5 +29,9 @@ namespace TUGraz.VectoCore.Models.Connector.Ports Watt WheelsPowerRequest { get; set; } Watt VehiclePowerRequest { get; set; } + + Watt BrakePower { get; set; } + + uint Gear { get; set; } } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/Impl/Response.cs b/VectoCore/Models/Connector/Ports/Impl/Response.cs index 854cde1cc10813f48e81e60b126834a0ffaae059..8f426e3590f26df4342ba31fa266c87e4a8bdbbd 100644 --- a/VectoCore/Models/Connector/Ports/Impl/Response.cs +++ b/VectoCore/Models/Connector/Ports/Impl/Response.cs @@ -8,18 +8,24 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl { public Second SimulationInterval { get; set; } + public Meter SimulationDistance { get; set; } + public Watt EnginePowerRequest { get; set; } public Watt ClutchPowerRequest { get; set; } public Watt GearboxPowerRequest { get; set; } + public uint Gear { get; set; } + public Watt AxlegearPowerRequest { get; set; } public Watt WheelsPowerRequest { get; set; } public Watt VehiclePowerRequest { get; set; } + public Watt BrakePower { get; set; } + public VectoSimulationComponent Source { get; set; } public override string ToString() diff --git a/VectoCore/Models/SimulationComponent/Impl/Brakes.cs b/VectoCore/Models/SimulationComponent/Impl/Brakes.cs index f90c825e72067f477797efcbcbcfd9e9c2be9477..56597f1473fa2d532a5555720f2b87f626510cc4 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Brakes.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Brakes.cs @@ -40,7 +40,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (!dryRun && BreakPower < 0) { throw new VectoSimulationException("Negative Braking Power is not allowed!"); } - return Next.Request(absTime, dt, torque - torque.Sign() * BreakTorque, angularVelocity, dryRun); + var retVal = Next.Request(absTime, dt, torque - torque.Sign() * BreakTorque, angularVelocity, dryRun); + retVal.BrakePower = BreakPower; + return retVal; } public IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity) diff --git a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index ef72082f3122b17e343b89a129fd34282daadae0..223b041e6214b4dcc9c305817c64fcf1023454ac 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -98,13 +98,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl throw new VectoSimulationException("Stopping Time only allowed when target speed is zero!"); } var dt = CycleIntervalIterator.LeftSample.StoppingTime - PreviousState.WaitTime; - if (CycleIntervalIterator.LeftSample.StoppingTime >= 4 * Constants.SimulationSettings.TargetTimeInterval) { + if (CycleIntervalIterator.LeftSample.StoppingTime.IsGreater(3 * Constants.SimulationSettings.TargetTimeInterval)) { // split into 3 parts if (PreviousState.WaitTime.IsEqual(0)) { dt = Constants.SimulationSettings.TargetTimeInterval; } else { - if (dt > Constants.SimulationSettings.TargetTimeInterval) - { + if (dt > Constants.SimulationSettings.TargetTimeInterval) { dt -= Constants.SimulationSettings.TargetTimeInterval; } } @@ -216,14 +215,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState = CurrentState.Clone(); if (!CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0) && - CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(PreviousState.WaitTime)) - { + CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(PreviousState.WaitTime)) { // we needed to stop at the current interval in the cycle and have already waited enough time, move on.. CycleIntervalIterator.MoveNext(); } // separately test for equality and greater than to have tolerance for equality comparison - if (CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0) && + if (CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0) && CurrentState.Distance.IsGreaterOrEqual(CycleIntervalIterator.RightSample.Distance)) { // we have reached the end of the current interval in the cycle, move on... CycleIntervalIterator.MoveNext(); diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 89eef85ff6cd6e806c230093f0ade6b2536636d3..4960f4c644db86e328759d4c1a48b886c74148af 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -253,7 +253,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl }; }). Default(() => { - throw new UnexpectedResponseException("CoastOrRoll Action: unhandled response from powertrain", retVal); + throw new UnexpectedResponseException( + "CoastOrRoll Action: unhandled response from powertrain. absTime: {0}, distance: {1}, slope: {2}, ds: {3}", retVal, + absTime, + DataBus.Distance, gradient, ds); }); return retVal; } @@ -276,7 +279,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl // only decelerate more of the simulation interval is not modified // i.e., braking to the next sample point Log.Debug("adjusting acceleration from {0} to {1}", operatingPoint.Acceleration, tmp.Acceleration); - operatingPoint = tmp; // ComputeTimeInterval((operatingPoint.Acceleration + tmp.Acceleration) / 2, operatingPoint.SimulationDistance); + operatingPoint = tmp; + // ComputeTimeInterval((operatingPoint.Acceleration + tmp.Acceleration) / 2, operatingPoint.SimulationDistance); } @@ -288,11 +292,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Case<ResponseOverload>(r => retVal = r). Case<ResponseUnderload>(). // will be handled in SearchBrakingPower Case<ResponseGearShift>(). // will be handled in SearchBrakingPower - Case<ResponseFailTimeInterval>(r => + Case<ResponseFailTimeInterval>(r => retVal = new ResponseDrivingCycleDistanceExceeded() { - Source = this, - MaxDistance = DataBus.VehicleSpeed() * r.DeltaT + operatingPoint.Acceleration / 2 * r.DeltaT * r.DeltaT - }). + Source = this, + MaxDistance = DataBus.VehicleSpeed() * r.DeltaT + operatingPoint.Acceleration / 2 * r.DeltaT * r.DeltaT + }). Default(r => { throw new UnexpectedResponseException("DrivingAction Brake: first request", r); }); diff --git a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 951884d2a3d785a909147a432bc9446d8ace3eb0..cc5b6851dd831fd84ddb46420a717933d46b4f89 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -101,15 +101,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return new ResponseFailTimeInterval() { DeltaT = _shiftTime - absTime, GearboxPowerRequest = outTorque * outEngineSpeed, + Gear = Gear, Source = this }; } if (DataBus.VehicleSpeed().IsEqual(0)) { Gear = 1; } - return absTime < _shiftTime + var retVal = absTime < _shiftTime ? DoHandleRequestNeutralGear(absTime, dt, outTorque, outEngineSpeed, dryRun) : DoHandleRequestGearEngaged(absTime, dt, outTorque, outEngineSpeed, dryRun); + retVal.Gear = Gear; + return retVal; } private IResponse DoHandleRequestNeutralGear(Second absTime, Second dt, NewtonMeter outTorque, diff --git a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs index d622cc608febfab32667164974ea08cb85fe8024..cda30cc2c60e055a12966d7547d0985d09e2a91e 100644 --- a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs +++ b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTest.cs @@ -44,6 +44,70 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy run.Run(); } + [TestMethod] + public void Accelerate_0_85_uphill_1() + { + var cycle = CreateCycleData(new[] { + // <s>,<v>,<grad>,<stop> + " 0, 0, 0, 2", + " 0, 85, 1, 0", + "900, 85, 1, 0", + }); + + var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_0_85_uh_1.vmod"); + + run.Run(); + } + + [TestMethod] + public void Accelerate_0_85_uphill_5() + { + var cycle = CreateCycleData(new[] { + // <s>,<v>,<grad>,<stop> + " 0, 0, 0, 2", + " 0, 85, 5, 0", + "900, 85, 5, 0", + }); + + var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_0_85_uh_5.vmod"); + + run.Run(); + } + + [TestMethod] + public void Accelerate_0_85_uphill_15() + { + var cycle = CreateCycleData(new[] { + // <s>,<v>,<grad>,<stop> + " 0, 0, 0, 2", + " 0, 85, 15, 0", + "900, 85, 15, 0", + }); + + var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_0_85_uh_15.vmod"); + + run.Run(); + } + + [TestMethod] + public void Drive_80_uphill_0_15() + { + var cycle = CreateCycleData(new[] { + // <s>,<v>,<grad>,<stop> + " 0, 80, 0, 0", + " 50, 80, 1, 0", + "100, 80, 2, 0", + "150, 80, 3, 0", + "200, 80, 4, 0", + "250, 80, 5, 0", + "300, 80, 0, 0", + "350, 80, 0, 0", + }); + + var run = CreatePowerTrain(cycle, "DriverStrategy_Drive_80_slope_0_15.vmod"); + + run.Run(); + } [TestMethod] public void Accelerate_80_0_level() @@ -60,6 +124,21 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy run.Run(); } + [TestMethod] + public void Accelerate_80_50_level() + { + var cycle = CreateCycleData(new[] { + // <s>,<v>,<grad>,<stop> + " 0, 80, 0, 0", + "500, 50, 0, 0", + "600, 50, 0, 0" + }); + + var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_80_50_level.vmod"); + + run.Run(); + } + // =============================== public DrivingCycleData CreateCycleData(string[] entries)