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

Skip to content
Snippets Groups Projects
Commit f8758c2c authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

driver strategy: lookahead coasting

IDriverActions: adapt interface
parent 291f475a
No related branches found
No related tags found
No related merge requests found
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Simulation.DataBus;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent
......@@ -93,6 +94,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent
/// </summary>
IDataBus DataBus { get; }
MeterPerSquareSecond LookaheadDeceleration { get; }
DriverData DriverData { get; }
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Connector.Ports.Impl;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
......@@ -92,9 +93,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return retVal;
}
// if the speed at the end of the simulation interval is below the next target speed
// we are fine (no need to brake right now)
var v2 = Driver.DataBus.VehicleSpeed + retVal.Acceleration * retVal.SimulationInterval;
if (v2 <= nextAction.NextTargetSpeed) {
return retVal;
}
var coastingDistance = Formulas.DecelerationDistance(v2, nextAction.NextTargetSpeed,
Driver.LookaheadDeceleration);
Driver.DriverData.LookAheadCoasting.Deceleration);
//if (Driver.DataBus.Distance.IsEqual(nextAction.TriggerDistance - coastingDistance,
// Constants.SimulationSettings.DriverActionDistanceTolerance.Value())) {
......@@ -125,11 +131,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// s_acc(dt) = currentSpeed * dt + a / 2 * dt^2
// => solve for dt, compute ds = currentSpeed * dt + a / 2 * dt^2
var dtList = VectoMath.QuadraticEquationSolver(
(retVal.Acceleration / 2 - retVal.Acceleration * retVal.Acceleration / 2 / Driver.LookaheadDeceleration).Value(),
(Driver.DataBus.VehicleSpeed - Driver.DataBus.VehicleSpeed * retVal.Acceleration / Driver.LookaheadDeceleration)
(retVal.Acceleration / 2 -
retVal.Acceleration * retVal.Acceleration / 2 / Driver.DriverData.LookAheadCoasting.Deceleration).Value(),
(Driver.DataBus.VehicleSpeed -
Driver.DataBus.VehicleSpeed * retVal.Acceleration / Driver.DriverData.LookAheadCoasting.Deceleration)
.Value
(),
(-Driver.DataBus.VehicleSpeed * Driver.DataBus.VehicleSpeed / 2 / Driver.LookaheadDeceleration -
(-Driver.DataBus.VehicleSpeed * Driver.DataBus.VehicleSpeed / 2 / Driver.DriverData.LookAheadCoasting.Deceleration -
(nextAction.TriggerDistance - Driver.DataBus.Distance)).Value());
dtList.Sort();
var dt = dtList.First(x => x > 0).SI<Second>();
......@@ -150,25 +158,36 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// distance until halt
var lookaheadDistance = Formulas.DecelerationDistance(currentSpeed, 0.SI<MeterPerSecond>(),
Driver.LookaheadDeceleration);
Driver.DriverData.LookAheadCoasting.Deceleration);
var lookaheadData = Driver.DataBus.LookAhead(1.2 * lookaheadDistance);
Log.Debug("Lookahead distance: {0} @ current speed {1}", lookaheadDistance, currentSpeed);
var nextActions = new List<DrivingBehaviorEntry>();
for (var i = 0; i < lookaheadData.Count; i++) {
var entry = lookaheadData[i];
foreach (var entry in lookaheadData) {
if (entry.VehicleTargetSpeed < currentSpeed) {
var coastingDistance = Formulas.DecelerationDistance(currentSpeed, entry.VehicleTargetSpeed,
Driver.LookaheadDeceleration);
Log.Debug("adding 'Coasting' starting at distance {0}", entry.Distance - coastingDistance);
nextActions.Add(
new DrivingBehaviorEntry {
Action = DefaultDriverStrategy.DrivingBehavior.Coasting,
ActionDistance = entry.Distance - coastingDistance,
if (!Driver.DriverData.LookAheadCoasting.Enabled ||
currentSpeed < Driver.DriverData.LookAheadCoasting.MinSpeed) {
var brakingDistance = Driver.ComputeDecelerationDistance(entry.VehicleTargetSpeed);
Log.Debug("adding 'Braking' starting at distance {0}", entry.Distance - brakingDistance);
nextActions.Add(new DrivingBehaviorEntry {
Action = DrivingBehavior.Braking,
ActionDistance = entry.Distance - brakingDistance,
TriggerDistance = entry.Distance,
NextTargetSpeed = entry.VehicleTargetSpeed
});
} else {
var coastingDistance = Formulas.DecelerationDistance(currentSpeed, entry.VehicleTargetSpeed,
Driver.DriverData.LookAheadCoasting.Deceleration);
Log.Debug("adding 'Coasting' starting at distance {0}", entry.Distance - coastingDistance);
nextActions.Add(
new DrivingBehaviorEntry {
Action = DefaultDriverStrategy.DrivingBehavior.Coasting,
ActionDistance = entry.Distance - coastingDistance,
TriggerDistance = entry.Distance,
NextTargetSpeed = entry.VehicleTargetSpeed
});
}
}
if (entry.VehicleTargetSpeed > currentSpeed) {
nextActions.Add(new DrivingBehaviorEntry {
......
......@@ -24,11 +24,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected IDriverDemandOutPort NextComponent;
protected DriverData DriverData;
public DriverData DriverData { get; protected set; }
protected IDriverStrategy DriverStrategy;
public MeterPerSquareSecond LookaheadDeceleration { get; protected set; }
//public MeterPerSquareSecond LookaheadDeceleration { get; protected set; }
public Driver(VehicleContainer container, DriverData driverData, IDriverStrategy strategy) : base(container)
{
......@@ -36,7 +36,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
DriverStrategy = strategy;
strategy.Driver = this;
LookaheadDeceleration = DeclarationData.Driver.LookAhead.Deceleration;
//LookaheadDeceleration = DeclarationData.Driver.LookAhead.Deceleration;
}
public IDriverDemandInPort InPort()
......@@ -52,7 +52,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient)
{
LookaheadDeceleration = DriverData.AccelerationCurve.MinDeceleration();
//LookaheadDeceleration = DriverData.AccelerationCurve.MinDeceleration();
if (DriverData.LookAheadCoasting.Deceleration < DriverData.AccelerationCurve.MinDeceleration()) {
Log.Warn(
"LookAhead Coasting Deceleration is lower than Driver's min. Deceleration. Coasting may start too late. Lookahead dec.: {0}, Driver min. deceleration: {1}",
DriverData.LookAheadCoasting.Deceleration, DriverData.AccelerationCurve.MinDeceleration());
}
return NextComponent.Initialize(vehicleSpeed, roadGradient);
}
......@@ -61,9 +66,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
Log.Debug("==== DRIVER Request ====");
Log.Debug(
"Request: absTime: {0}, ds: {1}, targetVelocity: {2}, gradient: {3} | distance: {4}, velocity: {5}",
absTime, ds,
targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed);
"Request: absTime: {0}, ds: {1}, targetVelocity: {2}, gradient: {3} | distance: {4}, velocity: {5} gear: {6}",
absTime, ds, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed, DataBus.Gear);
var retVal = DriverStrategy.Request(absTime, ds, targetVelocity, gradient);
//DoHandleRequest(absTime, ds, targetVelocity, gradient);
......@@ -400,8 +404,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var limitApplied = false;
var originalAcceleration = operatingPoint.Acceleration;
if (((limits & LimitationMode.LimitDecelerationLookahead) != 0) &&
operatingPoint.Acceleration < LookaheadDeceleration) {
operatingPoint.Acceleration = LookaheadDeceleration;
operatingPoint.Acceleration < DriverData.LookAheadCoasting.Deceleration) {
operatingPoint.Acceleration = DriverData.LookAheadCoasting.Deceleration;
limitApplied = true;
}
var accelerationLimits = DriverData.AccelerationCurve.Lookup(DataBus.VehicleSpeed);
......@@ -453,11 +457,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Default(r => {
throw new UnexpectedResponseException("cannot use response for searching braking power!", r);
});
var delta = searchInterval;
var delta = 0.SI<Watt>();
debug.Add(new { brakingPower = 0.SI<Watt>(), searchInterval, delta });
debug.Add(new { brakingPower = 0.SI<Watt>(), searchInterval, delta = origDelta, operatingPoint });
var breakingPower = origDelta.Abs();
var breakingPower = searchInterval * -delta.Sign();
// double the searchInterval until a good interval was found
var intervalFactor = 1.0;
......@@ -477,7 +481,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return operatingPoint;
}
debug.Add(new { breakingPower, searchInterval, delta });
debug.Add(new { breakingPower, searchInterval, delta, operatingPoint });
// check if a correct searchInterval was found (when the delta changed signs, we stepped through the 0-point)
// from then on the searchInterval can be bisected.
......
......@@ -281,6 +281,39 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy
CreatePowerTrain(cycle, "DriverStrategy_Decelerate_60_20_level.vmod").Run();
}
[TestMethod]
public void Decelerate_45_0_level()
{
var cycle = CreateCycleData(new[] {
// <s>,<v>,<grad>,<stop>
" 0, 45, 0, 0",
" 200, 0, 0, 2",
});
CreatePowerTrain(cycle, "DriverStrategy_Decelerate_45_0_level.vmod").Run();
}
[TestMethod]
public void Decelerate_45_0_uphill_5()
{
var cycle = CreateCycleData(new[] {
// <s>,<v>,<grad>,<stop>
" 0, 45, 5, 0",
" 200, 0, 5, 2",
});
CreatePowerTrain(cycle, "DriverStrategy_Decelerate_45_0_uphill_5.vmod").Run();
}
[TestMethod]
public void Decelerate_45_0_downhill_5()
{
var cycle = CreateCycleData(new[] {
// <s>,<v>,<grad>,<stop>
" 0, 45, -5, 0",
" 200, 0, -5, 2",
});
CreatePowerTrain(cycle, "DriverStrategy_Decelerate_45_0_downhill_5.vmod").Run();
}
[TestMethod]
public void Decelerate_60_20_uphill_5()
{
......@@ -1036,7 +1069,9 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy
return new DriverData {
AccelerationCurve = AccelerationCurveData.ReadFromFile(accelerationFile),
LookAheadCoasting = new DriverData.LACData {
Enabled = false,
Enabled = true,
MinSpeed = 50.KMPHtoMeterPerSecond(),
Deceleration = -0.5.SI<MeterPerSquareSecond>(),
},
OverSpeedEcoRoll = new DriverData.OverSpeedEcoRollData {
Mode = DriverData.DriverMode.Off
......
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