diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs index 17026041ba85c76ef886135a03e700a558157b97..10881e1aae80cc2f057f5d82c2dfb7ff8b6b1ca1 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs @@ -115,6 +115,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Log.Debug("to Engine: torque: {0}, angularVelocity: {1}, power {2}", torqueIn, angularVelocityIn, Formulas.TorqueToPower(torqueIn, angularVelocityIn)); + var avgOutAngularVelocity = (PreviousState.OutAngularVelocity + outAngularVelocity) / 2.0; + var avgInAngularVelocity = (PreviousState.InAngularVelocity + angularVelocityIn) / 2.0; + var clutchLoss = torqueIn * avgInAngularVelocity - outTorque * avgOutAngularVelocity; + if (clutchLoss < 0) { + // we don't want to have negative clutch losses, so adapt input torque to match the average output power + torqueIn = outTorque * avgOutAngularVelocity / avgInAngularVelocity; + } var retVal = NextComponent.Request(absTime, dt, torqueIn, angularVelocityIn, dryRun); if (!dryRun) { diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index df510d00ab4563d5bc19b3416f2e7ecc0997ad66..7cb0e4d8fe8e745df893f2328c9965943e84229f 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -548,17 +548,23 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (_idleStart == null) { _idleStart = absTime; _engineTargetSpeed = _engine.PreviousState.EngineSpeed / _dataBus.GetGearData(_dataBus.Gear).Ratio * - _dataBus.GetGearData(_dataBus.NextGear.Gear).Ratio; + _dataBus.GetGearData(_dataBus.NextGear.Gear).Ratio; } - - var velocitySlope = (_engineTargetSpeed - _engine.PreviousState.EngineSpeed) / (_dataBus.TractionInterruption - (absTime - _idleStart)); - var nextAngularSpeed = (velocitySlope * dt + _engine.PreviousState.EngineSpeed); + var velocitySlope = (_engineTargetSpeed - _engine.PreviousState.EngineSpeed) / + (_dataBus.TractionInterruption - (absTime - _idleStart)); + + var nextAngularSpeed = (velocitySlope * dt + _engine.PreviousState.EngineSpeed); + + nextAngularSpeed = velocitySlope < 0 + ? VectoMath.Max(_engineTargetSpeed, nextAngularSpeed) + : VectoMath.Min(_engineTargetSpeed, nextAngularSpeed); if (nextAngularSpeed < _engine.ModelData.IdleSpeed) { nextAngularSpeed = _engine.ModelData.IdleSpeed; } + var retVal = RequestPort.Request(absTime, dt, 0.SI<NewtonMeter>(), nextAngularSpeed); retVal.Switch(). Case<ResponseSuccess>().