Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 98eef69e authored by Michael KRISPER's avatar Michael KRISPER
Browse files

further refinements for fullpowertrain test

parent 9a5ea750
Branches
Tags
No related merge requests found
using System.Linq;
using TUGraz.VectoCore.Utils; using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Connector.Ports.Impl namespace TUGraz.VectoCore.Models.Connector.Ports.Impl
...@@ -17,6 +18,12 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl ...@@ -17,6 +18,12 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl
public Watt WheelsPowerRequest { get; set; } public Watt WheelsPowerRequest { get; set; }
public Watt VehiclePowerRequest { get; set; } public Watt VehiclePowerRequest { get; set; }
public override string ToString()
{
var t = GetType();
return string.Format("{0}{{{1}}}", t.Name, ", ".Join(t.GetProperties().Select(p => string.Format("{0}: {1}", p.Name, p.GetValue(this)))));
}
} }
/// <summary> /// <summary>
......
...@@ -13,7 +13,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -13,7 +13,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
protected override IResponse DoSimulationStep() protected override IResponse DoSimulationStep()
{ {
// estimate distance to be traveled within the next TargetTimeInterval // estimate distance to be traveled within the next TargetTimeInterval
var ds = (Container.VehicleSpeed() * Constants.SimulationSettings.TargetTimeInterval).Cast<Meter>(); var ds = Container.VehicleSpeed() * Constants.SimulationSettings.TargetTimeInterval;
if (ds.IsEqual(0)) { if (ds.IsEqual(0)) {
// vehicle stands still, drive a certain distance... // vehicle stands still, drive a certain distance...
......
...@@ -74,6 +74,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -74,6 +74,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return retVal; return retVal;
} }
/// <summary>
/// Does the handle request.
/// </summary>
/// <param name="absTime">The abs time.</param>
/// <param name="ds">The ds.</param>
/// <returns></returns>
/// <exception cref="VectoSimulationException">Stopping Time only allowed when target speed is zero!</exception>
private IResponse DoHandleRequest(Second absTime, Meter ds) private IResponse DoHandleRequest(Second absTime, Meter ds)
{ {
if (CycleIntervalIterator.LastEntry && PreviousState.Distance.IsEqual(CycleIntervalIterator.RightSample.Distance)) { if (CycleIntervalIterator.LastEntry && PreviousState.Distance.IsEqual(CycleIntervalIterator.RightSample.Distance)) {
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Security.Cryptography.X509Certificates;
using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports;
...@@ -32,6 +34,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -32,6 +34,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
//OverSpeed, //OverSpeed,
} }
[DebuggerDisplay("ActionDistance: {ActionDistance}, TriggerDistance: {TriggerDistance}, Action: {Action}")]
public class DrivingBehaviorEntry public class DrivingBehaviorEntry
{ {
public DrivingBehavior Action; public DrivingBehavior Action;
...@@ -93,32 +96,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -93,32 +96,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var currentDistance = DataBus.Distance(); var currentDistance = DataBus.Distance();
var nextDrivingActions = GetNextDrivingActions(currentDistance); var nextDrivingActions = GetNextDrivingActions(currentDistance);
Log.DebugFormat(", ".Join(nextDrivingActions.Select(x => string.Format("[{0}]: {1}", x.ActionDistance, x.Action))));
if (CurrentState.DrivingAction.Action == DrivingBehavior.Stopped && targetVelocity >= DataBus.VehicleSpeed()) { if (CurrentState.DrivingAction.Action == DrivingBehavior.Stopped && targetVelocity >= DataBus.VehicleSpeed()) {
CurrentState.DrivingAction.Action = DrivingBehavior.Drive; CurrentState.DrivingAction.Action = DrivingBehavior.Drive;
} }
if (nextDrivingActions.Count > 0) { if (nextDrivingActions.Count > 0) {
// if we exceeded the previous action (by accident), set the action anyway in case there is no 'next action'... // if we exceeded the previous action (by accident), set the action anyway in case there is no 'next action'...
CurrentState.DrivingAction = nextDrivingActions.LastOrDefault(x => x.Key < currentDistance).Value ?? CurrentState.DrivingAction = nextDrivingActions.LastOrDefault(x => x.ActionDistance < currentDistance) ??
CurrentState.DrivingAction; CurrentState.DrivingAction;
var nextActions = nextDrivingActions.Where(x => x.Key >= currentDistance).ToList(); var nextActions = nextDrivingActions.Where(x => x.ActionDistance >= currentDistance).ToList();
var nextDrivingAction = nextActions.GetEnumerator(); var nextDrivingAction = nextActions.GetEnumerator();
nextDrivingAction.MoveNext(); nextDrivingAction.MoveNext();
var hasNextEntry = true; var hasNextEntry = true;
// if the current position matches the next action - set new action. // if the current position matches the next action - set new action.
if (nextDrivingAction.Current.Key.IsEqual(currentDistance, if (nextDrivingAction.Current.ActionDistance.IsEqual(currentDistance,
Constants.SimulationSettings.DriverActionDistanceTolerance.Value())) { Constants.SimulationSettings.DriverActionDistanceTolerance.Value())) {
CurrentState.DrivingAction = nextDrivingAction.Current.Value; CurrentState.DrivingAction = nextDrivingAction.Current;
hasNextEntry = nextDrivingAction.MoveNext(); // the current action has already been processed, look at next one... hasNextEntry = nextDrivingAction.MoveNext(); // the current action has already been processed, look at next one...
} }
// check if desired distance exceeds next action point // check if desired distance exceeds next action point
if (hasNextEntry && nextDrivingAction.Current.Key < currentDistance + ds) { if (hasNextEntry && nextDrivingAction.Current.ActionDistance < currentDistance + ds) {
Log.DebugFormat( Log.DebugFormat(
"current Distance: {3} -- Simulation Distance {0} exceeds next DrivingAction at {1}, reducing interval to {2}", ds, "current Distance: {3} -- Simulation Distance {0} exceeds next DrivingAction at {1}, reducing interval to {2}", ds,
nextDrivingAction.Current.Key, nextDrivingAction.Current.Key - currentDistance, currentDistance); nextDrivingAction.Current.ActionDistance, nextDrivingAction.Current.ActionDistance - currentDistance,
return new ResponseDrivingCycleDistanceExceeded { MaxDistance = nextDrivingAction.Current.Key - currentDistance }; currentDistance);
return new ResponseDrivingCycleDistanceExceeded {
MaxDistance = nextDrivingAction.Current.ActionDistance - currentDistance
};
} }
} else { } else {
if (targetVelocity > DataBus.VehicleSpeed()) { if (targetVelocity > DataBus.VehicleSpeed()) {
...@@ -267,7 +276,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -267,7 +276,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return new ResponseDrivingCycleDistanceExceeded { SimulationInterval = CurrentState.dt }; return new ResponseDrivingCycleDistanceExceeded { SimulationInterval = CurrentState.dt };
} }
protected SortedList<Meter, DrivingBehaviorEntry> GetNextDrivingActions(Meter minDistance) protected IList<DrivingBehaviorEntry> GetNextDrivingActions(Meter minDistance)
{ {
var currentSpeed = DataBus.VehicleSpeed(); var currentSpeed = DataBus.VehicleSpeed();
...@@ -278,7 +287,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -278,7 +287,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var lookaheadData = DataBus.LookAhead(1.2 * lookaheadDistance); var lookaheadData = DataBus.LookAhead(1.2 * lookaheadDistance);
Log.DebugFormat("Lookahead distance: {0} @ current speed {1}", lookaheadDistance, currentSpeed); Log.DebugFormat("Lookahead distance: {0} @ current speed {1}", lookaheadDistance, currentSpeed);
var nextActions = new SortedList<Meter, DrivingBehaviorEntry>(); var nextActions = new List<DrivingBehaviorEntry>();
for (var i = 0; i < lookaheadData.Count; i++) { for (var i = 0; i < lookaheadData.Count; i++) {
var entry = lookaheadData[i]; var entry = lookaheadData[i];
if (entry.VehicleTargetSpeed < currentSpeed) { if (entry.VehicleTargetSpeed < currentSpeed) {
...@@ -286,35 +295,35 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -286,35 +295,35 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Log.DebugFormat("distance to decelerate from {0} to {1}: {2}", currentSpeed, entry.VehicleTargetSpeed, Log.DebugFormat("distance to decelerate from {0} to {1}: {2}", currentSpeed, entry.VehicleTargetSpeed,
breakingDistance); breakingDistance);
Log.DebugFormat("adding 'Braking' starting at distance {0}", entry.Distance - breakingDistance); Log.DebugFormat("adding 'Braking' starting at distance {0}", entry.Distance - breakingDistance);
nextActions[entry.Distance - breakingDistance] = nextActions.Add(
new DrivingBehaviorEntry { new DrivingBehaviorEntry {
Action = DrivingBehavior.Breaking, Action = DrivingBehavior.Breaking,
ActionDistance = entry.Distance - breakingDistance, ActionDistance = entry.Distance - breakingDistance,
TriggerDistance = entry.Distance, TriggerDistance = entry.Distance,
NextTargetSpeed = entry.VehicleTargetSpeed NextTargetSpeed = entry.VehicleTargetSpeed
}; });
var coastingDistance = Formulas.DecelerationDistance(currentSpeed, entry.VehicleTargetSpeed, var coastingDistance = Formulas.DecelerationDistance(currentSpeed, entry.VehicleTargetSpeed,
DeclarationData.Driver.LookAhead.Deceleration); DeclarationData.Driver.LookAhead.Deceleration);
Log.DebugFormat("adding 'Coasting' starting at distance {0}", entry.Distance - coastingDistance); Log.DebugFormat("adding 'Coasting' starting at distance {0}", entry.Distance - coastingDistance);
nextActions[entry.Distance - coastingDistance] = nextActions.Add(
new DrivingBehaviorEntry { new DrivingBehaviorEntry {
Action = DrivingBehavior.Coasting, Action = DrivingBehavior.Coasting,
ActionDistance = entry.Distance - coastingDistance, ActionDistance = entry.Distance - coastingDistance,
TriggerDistance = entry.Distance, TriggerDistance = entry.Distance,
NextTargetSpeed = entry.VehicleTargetSpeed NextTargetSpeed = entry.VehicleTargetSpeed
}; });
} }
if (entry.VehicleTargetSpeed > currentSpeed) { if (entry.VehicleTargetSpeed > currentSpeed) {
nextActions[entry.Distance] = new DrivingBehaviorEntry { nextActions.Add(new DrivingBehaviorEntry {
Action = DrivingBehavior.Accelerating, Action = DrivingBehavior.Accelerating,
NextTargetSpeed = entry.VehicleTargetSpeed, NextTargetSpeed = entry.VehicleTargetSpeed,
TriggerDistance = entry.Distance, TriggerDistance = entry.Distance,
ActionDistance = entry.Distance ActionDistance = entry.Distance
}; });
} }
} }
return nextActions; return nextActions.OrderBy(x => x.ActionDistance).ToList();
} }
protected internal Meter ComputeDecelerationDistance(MeterPerSecond targetSpeed) protected internal Meter ComputeDecelerationDistance(MeterPerSecond targetSpeed)
...@@ -345,6 +354,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -345,6 +354,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Log.DebugFormat("Found operating point for coasting. dt: {0}, acceleration: {1}", CurrentState.dt, Log.DebugFormat("Found operating point for coasting. dt: {0}, acceleration: {1}", CurrentState.dt,
CurrentState.Acceleration); CurrentState.Acceleration);
if (CurrentState.Acceleration < DeclarationData.Driver.LookAhead.Deceleration) {
Log.DebugFormat("Limiting coasting deceleration from {0} to {1}", CurrentState.Acceleration,
DeclarationData.Driver.LookAhead.Deceleration);
CurrentState.Acceleration = DeclarationData.Driver.LookAhead.Deceleration;
CurrentState.dt = ComputeTimeInterval(CurrentState.Acceleration, ref ds);
Log.DebugFormat("Changed dt due to limited coasting deceleration. dt: {0}", CurrentState.dt);
}
var retVal = Next.Request(absTime, CurrentState.dt, CurrentState.Acceleration, gradient); var retVal = Next.Request(absTime, CurrentState.dt, CurrentState.Acceleration, gradient);
CurrentState.Response = retVal; CurrentState.Response = retVal;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using Common.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.FileIO.Reader; using TUGraz.VectoCore.FileIO.Reader;
...@@ -34,7 +35,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns ...@@ -34,7 +35,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
[TestMethod] [TestMethod]
public void Test_FullPowertrain_SimpleGearbox() public void Test_FullPowertrain_SimpleGearbox()
{ {
var modalWriter = new ModalDataWriter("Coach_FullPowertrain.vmod"); var modalWriter = new ModalDataWriter("Coach_FullPowertrain_SimpleGearbox.vmod");
var sumWriter = new TestSumWriter(); var sumWriter = new TestSumWriter();
var container = new VehicleContainer(modalWriter, sumWriter); var container = new VehicleContainer(modalWriter, sumWriter);
...@@ -80,7 +81,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns ...@@ -80,7 +81,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
ds = container.VehicleSpeed().IsEqual(0) ds = container.VehicleSpeed().IsEqual(0)
? Constants.SimulationSettings.DriveOffDistance ? Constants.SimulationSettings.DriveOffDistance
: (Constants.SimulationSettings.TargetTimeInterval * container.VehicleSpeed()).Cast<Meter>(); : Constants.SimulationSettings.TargetTimeInterval * container.VehicleSpeed();
if (cnt++ % 100 == 0) { if (cnt++ % 100 == 0) {
modalWriter.Finish(); modalWriter.Finish();
...@@ -122,7 +123,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns ...@@ -122,7 +123,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
cyclePort.Initialize(); cyclePort.Initialize();
container.Gear = 0; container.Gear = 0;
var Log = LogManager.GetLogger<FullPowerTrain>();
var absTime = 0.SI<Second>(); var absTime = 0.SI<Second>();
var ds = Constants.SimulationSettings.DriveOffDistance; var ds = Constants.SimulationSettings.DriveOffDistance;
var response = cyclePort.Request(absTime, ds); var response = cyclePort.Request(absTime, ds);
...@@ -133,11 +134,14 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns ...@@ -133,11 +134,14 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
container.Gear = 1; container.Gear = 1;
var cnt = 0; var cnt = 0;
while (!(response is ResponseCycleFinished) && container.Distance().Value() < 17000) { while (!(response is ResponseCycleFinished) && container.Distance().Value() < 17000) {
Log.InfoFormat("Test New Request absTime: {0}, ds: {1}", absTime, ds);
response = cyclePort.Request(absTime, ds); response = cyclePort.Request(absTime, ds);
Log.InfoFormat("Test Got Response: {0},", response);
response.Switch(). response.Switch().
Case<ResponseDrivingCycleDistanceExceeded>(r => ds = r.MaxDistance). Case<ResponseDrivingCycleDistanceExceeded>(r => ds = r.MaxDistance).
Case<ResponseCycleFinished>(r => { }). Case<ResponseCycleFinished>(r => { }).
Case<ResponseGearShift>(r => { Debug.WriteLine("Gearshift"); }). Case<ResponseGearShift>(r => { Log.Debug("Gearshift"); }).
Case<ResponseSuccess>(r => { Case<ResponseSuccess>(r => {
container.CommitSimulationStep(absTime, r.SimulationInterval); container.CommitSimulationStep(absTime, r.SimulationInterval);
absTime += r.SimulationInterval; absTime += r.SimulationInterval;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment