Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

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

Change CurrentState only if not dryRun; Minor renamings

parent cbb4e524
No related branches found
No related tags found
No related merge requests found
......@@ -49,8 +49,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private readonly IShiftStrategy _strategy;
protected internal readonly TorqueConverter TorqueConverter;
private IIdleController _idleController;
protected bool RequestAfterGearshift;
protected readonly KilogramSquareMeter EngineInertia;
private bool _requestAfterGearshift;
private readonly KilogramSquareMeter _engineInertia;
public bool TorqueConverterLocked
{
......@@ -65,7 +65,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
_strategy = strategy;
_strategy.Gearbox = this;
LastShift = double.MinValue.SI<Second>();
EngineInertia = engineInertia;
_engineInertia = engineInertia;
TorqueConverter = new TorqueConverter(this, _strategy, container, gearboxModelData.TorqueConverterData,
engineInertia);
}
......@@ -199,7 +199,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
IResponse retVal;
var count = 0;
var loop = false;
if (RequestAfterGearshift) {
if (_requestAfterGearshift) {
LastShift = absTime;
Gear = _strategy.Engage(absTime, dt, outTorque, outAngularVelocity);
CurrentState.PowershiftLosses = ComputeShiftLosses(dt, outTorque, outAngularVelocity);
......@@ -221,7 +221,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
GearboxPowerRequest =
outTorque * (PreviousState.OutAngularVelocity + outAngularVelocity) / 2.0
};
RequestAfterGearshift = true;
_requestAfterGearshift = true;
} else {
loop = true;
Gear = _strategy.Engage(absTime, dt, outTorque, outAngularVelocity);
......@@ -239,7 +239,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var torqueGbxIn = outTorque / ModelData.Gears[Gear].Ratio;
var deltaEngineSpeed = DataBus.EngineSpeed - outAngularVelocity * ModelData.Gears[Gear].Ratio;
var deltaClutchSpeed = (DataBus.EngineSpeed - PreviousState.OutAngularVelocity * ModelData.Gears[Gear].Ratio) / 2;
var torqueInertia = EngineInertia * deltaEngineSpeed / dt;
var torqueInertia = _engineInertia * deltaEngineSpeed / dt;
var averageEngineSpeed = (DataBus.EngineSpeed + outAngularVelocity * ModelData.Gears[Gear].Ratio) / 2;
var torqueLoss = (torqueGbxIn + torqueInertia) * deltaClutchSpeed / averageEngineSpeed;
......@@ -263,6 +263,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private IResponse RequestEngaged(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity,
bool dryRun)
{
if (!CurrentState.TorqueConverterLocked && !ModelData.Gears[Gear].HasTorqueConverter) {
throw new VectoSimulationException(
"Torque converter requested by strategy for gear without torque converter!");
}
var effectiveRatio = ModelData.Gears[Gear].Ratio;
var effectiveLossMap = ModelData.Gears[Gear].LossMap;
if (!CurrentState.TorqueConverterLocked) {
......@@ -271,32 +276,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
var avgOutAngularVelocity = (PreviousState.OutAngularVelocity + outAngularVelocity) / 2.0;
var inTorqueLossResult = effectiveLossMap.GetTorqueLoss(avgOutAngularVelocity, outTorque);
CurrentState.TorqueLossResult = inTorqueLossResult;
var inTorque = outTorque / effectiveRatio + inTorqueLossResult.Value;
if (!CurrentState.TorqueConverterLocked && !ModelData.Gears[Gear].HasTorqueConverter) {
throw new VectoSimulationException(
"Torque converter requested by strategy for gear without torque converter!");
}
var inAngularVelocity = outAngularVelocity * effectiveRatio;
CurrentState.InertiaTorqueLossOut = !inAngularVelocity.IsEqual(0)
var inertiaTorqueLossOut = !inAngularVelocity.IsEqual(0)
? Formulas.InertiaPower(outAngularVelocity, PreviousState.OutAngularVelocity, ModelData.Inertia, dt) /
avgOutAngularVelocity
: 0.SI<NewtonMeter>();
inTorque += CurrentState.InertiaTorqueLossOut / effectiveRatio;
inTorque += inertiaTorqueLossOut / effectiveRatio;
if (CurrentState.PowershiftLosses != null) {
inTorque += CurrentState.PowershiftLosses;
}
CurrentState.SetState(inTorque, inAngularVelocity, outTorque, outAngularVelocity);
CurrentState.Gear = Gear;
CurrentState.TransmissionTorqueLoss = inTorque - outTorque / effectiveRatio;
if (!dryRun) {
CurrentState.InertiaTorqueLossOut = inertiaTorqueLossOut;
CurrentState.TorqueLossResult = inTorqueLossResult;
CurrentState.SetState(inTorque, inAngularVelocity, outTorque, outAngularVelocity);
CurrentState.Gear = Gear;
CurrentState.TransmissionTorqueLoss = inTorque - outTorque / effectiveRatio;
TorqueConverter.Locked(CurrentState.InTorque, CurrentState.InAngularVelocity);
}
if (!CurrentState.TorqueConverterLocked) {
return TorqueConverter.Request(absTime, dt, inTorque, inAngularVelocity, dryRun);
......@@ -304,17 +304,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (!dryRun &&
_strategy.ShiftRequired(absTime, dt, outTorque, outAngularVelocity, inTorque, inAngularVelocity, Gear,
LastShift)) {
return new ResponseGearShift() {
Source = this
};
return new ResponseGearShift { Source = this };
}
TorqueConverter.Locked(CurrentState.InTorque, CurrentState.InAngularVelocity);
return NextComponent.Request(absTime, dt, inTorque, inAngularVelocity, dryRun);
}
private IResponse RequestDisengaged(Second absTime, Second dt, NewtonMeter outTorque,
PerSecond outAngularVelocity,
private IResponse RequestDisengaged(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity,
bool dryRun)
{
var avgAngularVelocity = (PreviousState.OutAngularVelocity + outAngularVelocity) / 2.0;
......@@ -349,12 +345,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var retval = IdleController.Request(absTime, dt, 0.SI<NewtonMeter>(), null);
retval.ClutchPowerRequest = 0.SI<Watt>();
CurrentState.SetState(0.SI<NewtonMeter>(), 0.SI<PerSecond>(), outTorque, outAngularVelocity);
TorqueConverter.Locked(CurrentState.InTorque, retval.EngineSpeed);
CurrentState.Gear = 1;
CurrentState.TorqueConverterLocked = !ModelData.Gears[Gear].HasTorqueConverter;
if (!dryRun) {
CurrentState.SetState(0.SI<NewtonMeter>(), 0.SI<PerSecond>(), outTorque, outAngularVelocity);
CurrentState.Gear = 1;
CurrentState.TorqueConverterLocked = !ModelData.Gears[Gear].HasTorqueConverter;
TorqueConverter.Locked(CurrentState.InTorque, retval.EngineSpeed);
}
return retval;
}
......@@ -388,7 +385,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
ModelData.Gears[Gear].Ratio);
}
}
RequestAfterGearshift = false;
_requestAfterGearshift = false;
if (DataBus.VehicleStopped) {
CurrentState.Disengaged = true;
......
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