Code development platform for open source projects from the European Union institutions

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

LookAheadCoasting and Debug Output in ModData

parent f1939edf
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ using System; ...@@ -33,6 +33,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Windows.Markup;
using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils; using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Configuration;
...@@ -40,6 +41,7 @@ using TUGraz.VectoCore.InputData.Impl; ...@@ -40,6 +41,7 @@ using TUGraz.VectoCore.InputData.Impl;
using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Connector.Ports.Impl;
using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Simulation.DataBus; using TUGraz.VectoCore.Models.Simulation.DataBus;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.OutputData;
using TUGraz.VectoCore.Utils; using TUGraz.VectoCore.Utils;
using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData; using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData;
...@@ -119,65 +121,99 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -119,65 +121,99 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
/// <summary> /// <summary>
/// Checks if Look Ahead Coasting triggers /// Checks if Look Ahead Coasting triggers
/// </summary> /// </summary>
private bool CheckLookAheadCoasting(Meter ds) public Dictionary<string, object> LookAheadCoasting(Meter ds)
{ {
var dict = new Dictionary<string, object>();
// (1) & (2) : x_decelerationpoint - d_prev <= x_veh < x_decelerationpoint // (1) & (2) : x_decelerationpoint - d_prev <= x_veh < x_decelerationpoint
var v_veh = Driver.DataBus.VehicleSpeed;
var d_prev = 10 * Driver.DataBus.VehicleSpeed.ConvertTo().Kilo.Meter.Per.Hour.Value(); var d_prev = 10 * Driver.DataBus.VehicleSpeed.ConvertTo().Kilo.Meter.Per.Hour.Value();
var lookAheadData = Driver.DataBus.LookAhead(d_prev.SI<Meter>()); var lookaheadData = Driver.DataBus.LookAhead(d_prev.SI<Meter>());
var nextActions = new SortedDictionary<Meter, DrivingCycleData.DrivingCycleEntry>();
foreach (var entry in lookaheadData.Where(e => e.VehicleTargetSpeed <= v_veh)) {
var nextTargetSpeed = entry.VehicleTargetSpeed;
if (nextTargetSpeed < Driver.DataBus.VehicleSpeed) {
var coastingDistance = Formulas.DecelerationDistance(Driver.DataBus.VehicleSpeed, nextTargetSpeed,
Driver.DriverData.LookAheadCoasting.Deceleration);
nextActions.Add(entry.Distance - coastingDistance, entry);
}
}
// only deceleration points! var dec = nextActions.FirstOrDefault().Value;
var v_veh = Driver.DataBus.VehicleSpeed;
var decelerationLookAhead = lookAheadData.Where(e => e.VehicleTargetSpeed <= v_veh);
// (4) v_veh < v_max_deceleration * 0.98 // (4) v_veh < v_max_deceleration * 0.98
foreach (var dec in decelerationLookAhead) { if (dec != null) {
var x_dec = dec.Distance; var x_dec = dec.Distance;
dict["x_dec"] = x_dec.Value();
var x_delta = x_dec - Driver.DataBus.Distance; var x_delta = x_dec - Driver.DataBus.Distance;
dict["x_delta"] = x_delta.Value();
var v_target = dec.VehicleTargetSpeed; var v_target = dec.VehicleTargetSpeed;
var retVal = new OperatingPoint { SimulationDistance = x_dec }; dict["v_target"] = v_target.Value();
var x_max_deceleration = Driver.ComputeDecelerationDistance(v_target); var x_max_deceleration = Driver.ComputeDecelerationDistance(v_target);
var coastingPossible = x_delta < x_max_deceleration * 0.98; dict["x_max_deceleration"] = x_max_deceleration.Value();
var coastingPossible = x_delta >= x_max_deceleration * 0.98;
dict["CoastingAllowed"] = coastingPossible ? 1 : 0;
// 3. CDP > DF_coasting // 3. CDP > DF_coasting
if (coastingPossible) { if (coastingPossible) {
var m = Driver.DataBus.VehicleMass; var m = Driver.DataBus.VehicleMass;
var g = Physics.GravityAccelleration; var g = Physics.GravityAccelleration;
var h_target = dec.Altitude; var h_target = dec.Altitude;
dict["h_target"] = h_target.Value();
// todo mk-2016-05-11 left or right sample of cycle data? // todo mk-2016-05-11 left or right sample of cycle data?
var h_vehicle = Driver.DataBus.CycleData.LeftSample.Altitude; var h_vehicle = Driver.DataBus.CycleData.LeftSample.Altitude;
dict["h_vehicle"] = h_vehicle.Value();
var E_kin_veh = m * v_veh * v_veh / 2; var E_kin_veh = m * v_veh * v_veh / 2;
var E_kin_target = m * v_target * v_target / 2; var E_kin_target = m * v_target * v_target / 2;
var E_pot_target = m * g * h_target; var E_pot_target = m * g * h_target;
var E_pot_veh = m * g * h_vehicle; var E_pot_veh = m * g * h_vehicle;
dict["E_kin_veh"] = E_kin_veh.Value();
dict["E_kin_target"] = E_kin_target.Value();
dict["E_pot_target"] = E_pot_target.Value();
dict["E_pot_veh"] = E_pot_veh.Value();
var delta_E_deceleration = (E_kin_veh + E_pot_veh) - (E_kin_target + E_pot_target); var delta_E = (E_kin_veh + E_pot_veh) - (E_kin_target + E_pot_target);
dict["delta_E"] = delta_E.Value();
var f_dec_average = delta_E_deceleration / x_delta; var F_dec_average = delta_E / x_delta;
dict["F_dec_average"] = F_dec_average.Value();
var avgVelocity = (v_veh + v_target) / 2; var avgVelocity = (v_veh + v_target) / 2;
var acc = (v_target - v_veh) * (avgVelocity / ds); var acc = (v_target - v_veh) * (avgVelocity / ds);
var F_air = Driver.DataBus.AirDragResistance(v_veh, acc, ds / v_veh); var F_air = Driver.DataBus.AirDragResistance(v_veh, acc, ds / v_veh);
dict["F_air"] = F_air.Value();
var F_roll = Driver.DataBus.RollingResistance(Driver.DataBus.CycleData.LeftSample.RoadGradient); var F_roll = Driver.DataBus.RollingResistance(Driver.DataBus.CycleData.LeftSample.RoadGradient);
dict["F_roll"] = F_roll.Value();
var P_enginedrag = Driver.DataBus.EngineDragPower(Driver.DataBus.EngineSpeed); var F_enginedrag = Driver.DataBus.EngineDragPower(Driver.DataBus.EngineSpeed) / v_veh;
var P_loss_gb = Driver.DataBus.GearboxLoss(Driver.DataBus.EngineSpeed, Driver.DataBus.EngineTorque); dict["F_enginedrag"] = F_enginedrag.Value();
var F_loss_gb = Driver.DataBus.GearboxLoss(Driver.DataBus.EngineSpeed, Driver.DataBus.EngineTorque) / v_veh;
dict["F_loss_gb"] = F_loss_gb.Value();
// todo mk-2016-05-11 calculate ra loss // todo mk-2016-05-11 calculate ra loss
var P_loss_ra = 0.SI<Watt>(); var F_loss_ra = 0.SI<Newton>();
dict["F_loss_ra"] = F_loss_ra.Value();
var F_coasting = F_air + F_roll + F_enginedrag + F_loss_gb + F_loss_ra;
dict["F_coasting"] = F_coasting.Value();
var f_coasting = F_air + F_roll + (P_enginedrag + P_loss_gb + P_loss_ra) / v_veh; var CDP = F_dec_average / F_coasting;
dict["CDP"] = CDP.Value();
var CDP = f_dec_average / f_coasting;
var DF_coasting = LACDecisionFactor.Lookup(v_target, v_veh - v_target); var DF_coasting = LACDecisionFactor.Lookup(v_target, v_veh - v_target);
dict["DF_coasting"] = DF_coasting;
return CDP > DF_coasting; dict["EnableCoasting"] = CDP > DF_coasting ? 1 : 0;
} }
} }
return dict;
return false;
} }
public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient)
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
*/ */
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using iTextSharp.text.pdf; using iTextSharp.text.pdf;
...@@ -57,6 +58,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -57,6 +58,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public DriverData DriverData { get; protected set; } public DriverData DriverData { get; protected set; }
protected IDriverStrategy DriverStrategy; protected IDriverStrategy DriverStrategy;
private Dictionary<string, object> _coastData = new Dictionary<string, object>(20);
private string CurrentAction = "";
//public MeterPerSquareSecond LookaheadDeceleration { get; protected set; } //public MeterPerSquareSecond LookaheadDeceleration { get; protected set; }
...@@ -108,7 +111,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -108,7 +111,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
absTime, ds, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed, DataBus.VehicleStopped); absTime, ds, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed, DataBus.VehicleStopped);
var retVal = DriverStrategy.Request(absTime, ds, targetVelocity, gradient); var retVal = DriverStrategy.Request(absTime, ds, targetVelocity, gradient);
//DoHandleRequest(absTime, ds, targetVelocity, gradient);
_coastData = ((DefaultDriverStrategy)DriverStrategy).LookAheadCoasting(ds);
CurrentState.Response = retVal; CurrentState.Response = retVal;
retVal.SimulationInterval = CurrentState.dt; retVal.SimulationInterval = CurrentState.dt;
...@@ -153,7 +157,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -153,7 +157,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
IResponse previousResponse = null) IResponse previousResponse = null)
{ {
IterationStatistics.Increment(this, "Accelerate"); IterationStatistics.Increment(this, "Accelerate");
CurrentAction = "Accelerate";
Log.Debug("DrivingAction Accelerate"); Log.Debug("DrivingAction Accelerate");
var operatingPoint = ComputeAcceleration(ds, targetVelocity); var operatingPoint = ComputeAcceleration(ds, targetVelocity);
...@@ -233,6 +237,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -233,6 +237,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public IResponse DrivingActionCoast(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient) public IResponse DrivingActionCoast(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient)
{ {
IterationStatistics.Increment(this, "Coast"); IterationStatistics.Increment(this, "Coast");
CurrentAction = "Coast";
Log.Debug("DrivingAction Coast"); Log.Debug("DrivingAction Coast");
return CoastOrRollAction(absTime, ds, maxVelocity, gradient, false); return CoastOrRollAction(absTime, ds, maxVelocity, gradient, false);
...@@ -248,6 +253,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -248,6 +253,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
/// <returns></returns> /// <returns></returns>
public IResponse DrivingActionRoll(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient) public IResponse DrivingActionRoll(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient)
{ {
CurrentAction = "Roll";
IterationStatistics.Increment(this, "Roll"); IterationStatistics.Increment(this, "Roll");
Log.Debug("DrivingAction Roll"); Log.Debug("DrivingAction Roll");
...@@ -353,7 +359,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -353,7 +359,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
IResponse previousResponse = null, Meter targetDistance = null) IResponse previousResponse = null, Meter targetDistance = null)
{ {
IterationStatistics.Increment(this, "Brake"); IterationStatistics.Increment(this, "Brake");
CurrentAction = "Brake";
Log.Debug("DrivingAction Brake"); Log.Debug("DrivingAction Brake");
IResponse retVal = null; IResponse retVal = null;
...@@ -761,6 +767,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -761,6 +767,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
/// <returns></returns> /// <returns></returns>
public IResponse DrivingActionHalt(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) public IResponse DrivingActionHalt(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient)
{ {
CurrentAction = "Halt";
if (!targetVelocity.IsEqual(0) || !DataBus.VehicleStopped) { if (!targetVelocity.IsEqual(0) || !DataBus.VehicleStopped) {
Log.Error("TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!", targetVelocity, Log.Error("TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!", targetVelocity,
DataBus.VehicleSpeed); DataBus.VehicleSpeed);
...@@ -787,6 +794,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -787,6 +794,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected override void DoWriteModalResults(IModalDataContainer container) protected override void DoWriteModalResults(IModalDataContainer container)
{ {
container[ModalResultField.acc] = CurrentState.Acceleration; container[ModalResultField.acc] = CurrentState.Acceleration;
//todo mk-2016-05-11: remove additional columns in moddata after testing of LAC finished
foreach (var kv in _coastData) {
container.SetDataValue(kv.Key, kv.Value);
}
container.SetDataValue("Alt", DataBus.CycleData.LeftSample.Altitude.Value());
container.SetDataValue("DrivingMode", ((DefaultDriverStrategy)DriverStrategy).CurrentDrivingMode);
container.SetDataValue("Action", CurrentAction);
_coastData.Clear();
} }
protected override void DoCommitSimulationStep() protected override void DoCommitSimulationStep()
...@@ -809,18 +825,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -809,18 +825,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected enum LimitationMode protected enum LimitationMode
{ {
NoLimitation = 0x0, NoLimitation = 0x0,
//LimitAccelerationDriver = 0x1,
LimitDecelerationDriver = 0x2, LimitDecelerationDriver = 0x2,
LimitDecelerationLookahead = 0x4 LimitDecelerationLookahead = 0x4
} }
public DrivingBehavior DriverBehavior { get; set; } public DrivingBehavior DriverBehavior { get; set; }
//public bool VehicleStopped { get; protected set; }
//public DrivingBehavior DrivingBehavior
//{
// get { return DriverStrategy.DriverBehavior; }
//}
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment