diff --git a/VectoCore/Models/SimulationComponent/IShiftStrategy.cs b/VectoCore/Models/SimulationComponent/IShiftStrategy.cs index c9541b25f4442e75def0790e1337172abd6f1c42..55b5ee590408d50d84be52e7d66170494f1393c7 100644 --- a/VectoCore/Models/SimulationComponent/IShiftStrategy.cs +++ b/VectoCore/Models/SimulationComponent/IShiftStrategy.cs @@ -7,7 +7,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent { bool ShiftRequired(uint gear, NewtonMeter torque, PerSecond angularSpeed); uint InitGear(NewtonMeter torque, PerSecond angularSpeed); - uint Engage(NewtonMeter outTorque, PerSecond outEngineSpeed); + uint Engage(NewtonMeter outTorque, PerSecond outEngineSpeed, bool skipGears); void Disengage(NewtonMeter outTorque, PerSecond outEngineSpeed); Gearbox Gearbox { get; set; } } diff --git a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 036e87fee3d9f243b57864d72726c2bc2023e613..0ea75d234846339afefb1dce314eed708076c759 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -181,7 +181,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } if (DataBus.VehicleSpeed.IsEqual(0)) { - Gear = _strategy.Engage(outTorque, outEngineSpeed); + Gear = _strategy.Engage(outTorque, outEngineSpeed, Data.SkipGears); } var response = NextComponent.Request(absTime, dt, 0.SI<NewtonMeter>(), null); @@ -204,7 +204,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { // Set a Gear if no gear was set if (_disengaged) { - Gear = _strategy.Engage(outTorque, outEngineSpeed); + Gear = _strategy.Engage(outTorque, outEngineSpeed, Data.SkipGears); _disengaged = false; Log.Debug("Gearbox engaged gear {0}", Gear); } @@ -216,6 +216,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var torqueLossInertia = !inEngineSpeed.IsEqual(0) ? Formulas.InertiaPower(inEngineSpeed, _previousInEnginespeed, Data.Inertia, dt) / inEngineSpeed : 0.SI<NewtonMeter>(); + _previousInEnginespeed = inEngineSpeed; inTorque += torqueLossInertia; diff --git a/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs b/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs index c5db964fb5b1919209975f9087a2ba761a709163..dce629977e008c394530627105b7e4df699d21ad 100644 --- a/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs +++ b/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs @@ -7,7 +7,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public abstract class ShiftStrategy : IShiftStrategy { - public abstract uint Engage(NewtonMeter torque, PerSecond angularSpeed); + public abstract uint Engage(NewtonMeter torque, PerSecond angularSpeed, bool skipGears); public abstract void Disengage(NewtonMeter outTorque, PerSecond outEngineSpeed); public abstract bool ShiftRequired(uint gear, NewtonMeter torque, PerSecond angularSpeed); public abstract uint InitGear(NewtonMeter torque, PerSecond angularSpeed); @@ -74,13 +74,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { protected uint LastGear; - public AMTShiftStrategy(GearboxData data) - : base(data) + public AMTShiftStrategy(GearboxData data) : base(data) { LastGear = 1; } - public uint GetGear(uint gear, NewtonMeter outTorque, PerSecond outEngineSpeed) + public uint GetGear(uint gear, NewtonMeter outTorque, PerSecond outEngineSpeed, bool skipGears) { var loopCount = Data.Gears.Count; // protection against infinite loops do { @@ -96,23 +95,23 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl continue; } break; - } while (Data.SkipGears && loopCount-- > 0); + } while (skipGears && loopCount-- > 0); if (gear == 0) { throw new VectoSimulationException("Could not find gear! outTorque: {0}, outEngineSpeed: {1}, skipGears: {2}", - outTorque, outEngineSpeed, Data.SkipGears); + outTorque, outEngineSpeed, skipGears); } return gear; } - public override uint Engage(NewtonMeter outTorque, PerSecond outEngineSpeed) + public override uint Engage(NewtonMeter outTorque, PerSecond outEngineSpeed, bool skipGears) { - return GetGear(LastGear, outTorque, outEngineSpeed); + return GetGear(LastGear, outTorque, outEngineSpeed, skipGears); } public override void Disengage(NewtonMeter outTorque, PerSecond outEngineSpeed) { - LastGear = GetGear(Gearbox.Gear, outTorque, outEngineSpeed); + LastGear = GetGear(Gearbox.Gear, outTorque, outEngineSpeed, Data.SkipGears); } public override bool ShiftRequired(uint gear, NewtonMeter torque, PerSecond angularSpeed) @@ -122,7 +121,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public override uint InitGear(NewtonMeter torque, PerSecond angularSpeed) { - return Engage(torque, angularSpeed); + return Engage(torque, angularSpeed, true); } } @@ -131,7 +130,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public MTShiftStrategy(GearboxData data) : base(data) {} - public override uint Engage(NewtonMeter torque, PerSecond angularSpeed) + public override uint Engage(NewtonMeter torque, PerSecond angularSpeed, bool skipGears) { throw new System.NotImplementedException(); } @@ -157,7 +156,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { public ATShiftStrategy(GearboxData data) : base(data) {} - public override uint Engage(NewtonMeter torque, PerSecond angularSpeed) + public override uint Engage(NewtonMeter torque, PerSecond angularSpeed, bool skipGears) { throw new System.NotImplementedException(); }