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

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

working on deceleration/braking test case

parent 279dbb2e
No related branches found
No related tags found
No related merge requests found
......@@ -129,7 +129,9 @@ namespace TUGraz.VectoCore.Models.Declaration
public static class LookAhead
{
public const bool Enabled = true;
public static readonly MeterPerSquareSecond Deceleration = -0.5.SI<MeterPerSquareSecond>();
public static MeterPerSquareSecond Deceleration = -0.5.SI<MeterPerSquareSecond>();
public static readonly MeterPerSecond MinimumSpeed = 50.KMPHtoMeterPerSecond();
}
......
......@@ -14,25 +14,27 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
protected override IResponse DoSimulationStep()
{
// estimate distance to be traveled within the next TargetTimeInterval
var ds = Container.VehicleSpeed() * Constants.SimulationSettings.TargetTimeInterval;
if (ds.IsEqual(0)) {
// vehicle stands still, drive a certain distance...
ds = Constants.SimulationSettings.DriveOffDistance;
}
var ds = Container.VehicleSpeed().IsEqual(0)
? Constants.SimulationSettings.DriveOffDistance
: Constants.SimulationSettings.TargetTimeInterval * Container.VehicleSpeed();
IResponse response;
do {
response = CyclePort.Request(AbsTime, ds);
response.Switch().
Case<ResponseSuccess>(r => {
ds = Container.VehicleSpeed().IsEqual(0)
? Constants.SimulationSettings.DriveOffDistance
: Constants.SimulationSettings.TargetTimeInterval * Container.VehicleSpeed();
dt = r.SimulationInterval;
}).
Case<ResponseDrivingCycleDistanceExceeded>(r => {
if (r.MaxDistance <= 0) {
throw new VectoSimulationException("DistanceExceeded, MaxDistance is invalid: {0}", r.MaxDistance);
}
ds = r.MaxDistance;
}).
Case<ResponseDrivingCycleDistanceExceeded>(r => ds = r.MaxDistance).
Case<ResponseCycleFinished>(r => { }).
Default(r => { throw new VectoException("DistanceRun got an unexpected response: {0}", r); });
Case<ResponseCycleFinished>(r => {}).
Default(r => {
throw new VectoException("DistanceRun got an unexpected response: {0}", r);
});
} while (!(response is ResponseSuccess || response is ResponseCycleFinished));
return response;
......
......@@ -42,7 +42,6 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
Initialize();
Container.Gear = 1;
do {
response = DoSimulationStep();
if (response is ResponseSuccess) {
......
......@@ -91,5 +91,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent
/// access the vehicle's data bus to get information from other components.
/// </summary>
IDataBus DataBus { get; }
MeterPerSquareSecond LookaheadDeceleration { get; }
}
}
\ No newline at end of file
......@@ -51,6 +51,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var nextAction = GetNextDrivingAction(currentDistance);
if (nextAction != null && currentDistance.IsEqual(nextAction.ActionDistance)) {
CurrentDrivingMode = DrivingMode.DrivingModeBrake;
DrivingModes[CurrentDrivingMode].ResetMode();
BrakeTrigger = nextAction;
break;
}
......@@ -63,6 +64,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
case DrivingMode.DrivingModeBrake:
if (Driver.DataBus.Distance() >= BrakeTrigger.TriggerDistance) {
CurrentDrivingMode = DrivingMode.DrivingModeDrive;
DrivingModes[CurrentDrivingMode].ResetMode();
}
break;
}
......@@ -83,7 +85,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// distance until halt
var lookaheadDistance = Formulas.DecelerationDistance(currentSpeed, 0.SI<MeterPerSecond>(),
DeclarationData.Driver.LookAhead.Deceleration);
Driver.LookaheadDeceleration);
var lookaheadData = Driver.DataBus.LookAhead(1.2 * lookaheadDistance);
......@@ -104,7 +106,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// NextTargetSpeed = entry.VehicleTargetSpeed
// });
var coastingDistance = Formulas.DecelerationDistance(currentSpeed, entry.VehicleTargetSpeed,
DeclarationData.Driver.LookAhead.Deceleration);
Driver.LookaheadDeceleration);
Log.Debug("adding 'Coasting' starting at distance {0}", entry.Distance - coastingDistance);
nextActions.Add(
new DrivingBehaviorEntry {
......@@ -139,6 +141,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
DefaultDriverStrategy DriverStrategy { get; set; }
IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient);
void ResetMode();
}
//=====================================
......@@ -174,6 +178,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
return response;
}
public void ResetMode() {}
}
//=====================================
......@@ -220,8 +226,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
MaxDistance = DriverStrategy.BrakeTrigger.TriggerDistance - breakingDistance - currentDistance
};
}
if (DriverStrategy.BrakeTrigger.TriggerDistance - breakingDistance >
currentDistance + Constants.SimulationSettings.DriverActionDistanceTolerance) {
if (currentDistance + Constants.SimulationSettings.DriverActionDistanceTolerance >
DriverStrategy.BrakeTrigger.TriggerDistance - breakingDistance) {
Phase = BrakingPhase.Brake;
}
}
......@@ -234,6 +240,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
response = DriverStrategy.Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed,
gradient, r);
Phase = BrakingPhase.Brake;
}).
Case<ResponseGearShift>(r => {
response = DriverStrategy.Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient);
});
break;
case BrakingPhase.Brake:
......@@ -241,8 +250,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
gradient);
break;
}
// todo: @@@quam: add resonse.switch to indicate expected responses?
return response;
}
public void ResetMode()
{
Phase = BrakingPhase.Coast;
}
}
//=====================================
......
......@@ -27,12 +27,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected IDriverStrategy DriverStrategy;
public MeterPerSquareSecond LookaheadDeceleration {get; protected set; }
public Driver(VehicleContainer container, DriverData driverData, IDriverStrategy strategy) : base(container)
{
DriverData = driverData;
DriverStrategy = strategy;
strategy.Driver = this;
LookaheadDeceleration = DeclarationData.Driver.LookAhead.Deceleration;
}
public IDriverDemandInPort InPort()
......@@ -48,6 +51,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient)
{
LookaheadDeceleration = DriverData.AccelerationCurve.MinDeceleration();
return Next.Initialize(vehicleSpeed, roadGradient);
}
......
......@@ -90,7 +90,57 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// * EarlyUpshift (shift before outside of up-shift curve if torque reserve for the next higher gear is fullfilled)
// * SkipGears (when already shifting to next gear, check if torque reserve is fullfilled for the overnext gear and eventually shift to it)
// * MT, AMT and AT .... different behaviour!
/*
if (dryRun) {
var gear = Gear;
if (gear == 0 && _shiftTime <= absTime) {
gear = FindGear(outTorque, outEngineSpeed, Data.SkipGears);
}
if (gear == 0) {
return new ResponseDryRun() { GearboxPowerRequest = outTorque * outEngineSpeed, Source = this };
} else {
var inEngineSpeedDry = outEngineSpeed * Data.Gears[gear].Ratio;
var inTorqueDry = Data.Gears[gear].LossMap.GearboxInTorque(inEngineSpeedDry, outTorque);
var dryRunResponse = Next.Request(absTime, dt, inTorqueDry, inEngineSpeedDry, true);
dryRunResponse.GearboxPowerRequest = outTorque * outEngineSpeed;
return dryRunResponse;
}
} else {
if (Gear == 0) {
if (_shiftTime <= absTime) {
Gear = FindGear(outTorque, outEngineSpeed, Data.SkipGears);
}
if (!outTorque.IsEqual(0))
{
return new ResponseOverload
{
Delta = outTorque * outEngineSpeed,
Source = this,
GearboxPowerRequest = outTorque * outEngineSpeed
};
}
}
// Check if shift is needed and eventually return ResponseGearShift
if (_shiftTime + Data.ShiftTime < absTime &&
(ShouldShiftUp(Gear, inEngineSpeed, inTorque) || ShouldShiftDown(Gear, inEngineSpeed, inTorque)))
{
_shiftTime = absTime + Data.TractionInterruption;
LastGear = Gear;
Gear = 0;
Log.Debug("Gearbox is shifting. absTime: {0}, shiftTime: {1}, outTorque:{2}, outEngineSpeed: {3}",
absTime, _shiftTime, outTorque, outEngineSpeed);
return new ResponseGearShift
{
SimulationInterval = Data.TractionInterruption,
Source = this,
GearboxPowerRequest = outTorque * outEngineSpeed
};
}
}
*/
if (Gear == 0) {
// if no gear is set and dry run: just set GearBoxPowerRequest
if (dryRun) {
......@@ -141,7 +191,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Log.Debug("Gearbox is shifting. absTime: {0}, shiftTime: {1}, outTorque:{2}, outEngineSpeed: {3}",
absTime, _shiftTime, outTorque, outEngineSpeed);
return new ResponseGearShift { SimulationInterval = Data.TractionInterruption, Source = this };
return new ResponseGearShift {
SimulationInterval = Data.TractionInterruption,
Source = this,
GearboxPowerRequest = outTorque * outEngineSpeed
};
}
// Normal Response
......
......@@ -49,10 +49,10 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy
{
var cycle = CreateCycleData(new string[] {
" 0,80,0,0",
"900, 0,0,0",
"2500, 0,0,0",
});
var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_0_80_level.vmod");
var run = CreatePowerTrain(cycle, "DriverStrategy_Accelerate_80_0_level.vmod");
run.Run();
}
......
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