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

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

HybridController: Code formatting and removal of hamster-code

parent fbd439ab
No related branches found
No related tags found
No related merge requests found
...@@ -11,11 +11,9 @@ using TUGraz.VectoCore.Models.Connector.Ports.Impl; ...@@ -11,11 +11,9 @@ using TUGraz.VectoCore.Models.Connector.Ports.Impl;
using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.DataBus;
using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
using TUGraz.VectoCore.Models.SimulationComponent.Strategies;
using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.OutputData;
using TUGraz.VectoCore.Utils; using TUGraz.VectoCore.Utils;
...@@ -62,14 +60,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -62,14 +60,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
_electricMotorCtl[pos] = new ElectricMotorController(this, motorData); _electricMotorCtl[pos] = new ElectricMotorController(this, motorData);
} }
//public ResponseDryRun RequestDryRun(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, HybridStrategyResponse strategySettings)
//{
// ApplyStrategySettings(strategySettings);
// var retVal = NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, true);
// return retVal as ResponseDryRun;
//}
private void ApplyStrategySettings(HybridStrategyResponse strategySettings) private void ApplyStrategySettings(HybridStrategyResponse strategySettings)
{ {
Gearbox.SwitchToNeutral = strategySettings.GearboxInNeutral; Gearbox.SwitchToNeutral = strategySettings.GearboxInNeutral;
...@@ -78,17 +68,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -78,17 +68,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (DataBus.VehicleInfo.VehicleStopped && strategySettings.NextGear.Gear != 0) { if (DataBus.VehicleInfo.VehicleStopped && strategySettings.NextGear.Gear != 0) {
_shiftStrategy.SetNextGear(strategySettings.NextGear); _shiftStrategy.SetNextGear(strategySettings.NextGear);
} }
//if (strategySettings.ShiftRequired) {
// _shiftStrategy.SetNextGear(strategySettings.NextGear);
//}
} }
SimpleComponentState IHybridController.PreviousState => PreviousState; SimpleComponentState IHybridController.PreviousState => PreviousState;
public virtual IElectricMotorControl ElectricMotorControl(PowertrainPosition pos) public virtual IElectricMotorControl ElectricMotorControl(PowertrainPosition pos) => _electricMotorCtl[pos];
{
return _electricMotorCtl[pos];
}
public virtual IShiftStrategy ShiftStrategy => _shiftStrategy; public virtual IShiftStrategy ShiftStrategy => _shiftStrategy;
...@@ -96,10 +80,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -96,10 +80,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public bool GearboxEngaged => CurrentStrategySettings.GearboxEngaged; public bool GearboxEngaged => CurrentStrategySettings.GearboxEngaged;
public PerSecond ElectricMotorSpeed(PowertrainPosition pos) public PerSecond ElectricMotorSpeed(PowertrainPosition pos) => CurrentStrategySettings.MechanicalAssistPower[pos].Item1;
{
return CurrentStrategySettings.MechanicalAssistPower[pos].Item1;
}
public Second SimulationInterval => CurrentStrategySettings.SimulationInterval; public Second SimulationInterval => CurrentStrategySettings.SimulationInterval;
...@@ -119,8 +100,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -119,8 +100,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
retry = false; retry = false;
var strategyResponse = Strategy.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); var strategyResponse = Strategy.Request(absTime, dt, outTorque, outAngularVelocity, dryRun);
if (strategyResponse is HybridStrategyLimitedResponse) { if (strategyResponse is HybridStrategyLimitedResponse ovl) {
var ovl = strategyResponse as HybridStrategyLimitedResponse;
if (dryRun) { if (dryRun) {
return new ResponseDryRun(this) { return new ResponseDryRun(this) {
DeltaDragLoad = ovl.Delta, DeltaDragLoad = ovl.Delta,
...@@ -168,8 +148,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -168,8 +148,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
CurrentStrategySettings = strategySettings; CurrentStrategySettings = strategySettings;
retVal = NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, dryRun); retVal = NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, dryRun);
DebugData.Add(new { DebugData.Add(new {
DrivingAction = DataBus.DriverInfo.DrivingAction, StrategySettings = strategySettings, DrivingAction = DataBus.DriverInfo.DrivingAction,
Response = retVal, DryRun = dryRun StrategySettings = strategySettings,
Response = retVal,
DryRun = dryRun
}); });
if (!dryRun && strategySettings.CombustionEngineOn && retVal is ResponseSuccess && if (!dryRun && strategySettings.CombustionEngineOn && retVal is ResponseSuccess &&
...@@ -181,18 +163,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -181,18 +163,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
continue; continue;
} }
var gear = DataBus.GearboxInfo.Gear; var gear = DataBus.GearboxInfo.Gear;
var maxSpeed = VectoMath.Min(DataBus.GearboxInfo.GetGearData(gear.Gear).MaxSpeed, var maxSpeed = VectoMath.Min(DataBus.GearboxInfo.GetGearData(gear.Gear).MaxSpeed,
DataBus.EngineInfo.EngineN95hSpeed); DataBus.EngineInfo.EngineN95hSpeed);
if (!dryRun && retVal is ResponseSuccess && DataBus.GearboxInfo.GearEngaged(absTime) && retVal.Gearbox.InputSpeed.IsGreater(maxSpeed)) { if (!dryRun && retVal is ResponseSuccess && DataBus.GearboxInfo.GearEngaged(absTime) && retVal.Gearbox.InputSpeed.IsGreater(maxSpeed)) {
Strategy.AllowEmergencyShift = true; Strategy.AllowEmergencyShift = true;
retryCount++; retryCount++;
retry = true; retry = true;
Strategy.OperatingpointChangedDuringRequest(absTime, dt, outTorque, outAngularVelocity, false, retVal); Strategy.OperatingpointChangedDuringRequest(absTime, dt, outTorque, outAngularVelocity, false, retVal);
continue; continue;
} }
if (!dryRun && strategySettings.CombustionEngineOn && retVal is ResponseEngineSpeedTooHigh && !strategySettings.ProhibitGearshift) { if (!dryRun && strategySettings.CombustionEngineOn && retVal is ResponseEngineSpeedTooHigh && !strategySettings.ProhibitGearshift) {
retryCount++; retryCount++;
retry = true; retry = true;
Strategy.AllowEmergencyShift = true; Strategy.AllowEmergencyShift = true;
...@@ -236,7 +218,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -236,7 +218,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
PreviousState.StrategyResponse = strategyResponse as HybridStrategyResponse; PreviousState.StrategyResponse = strategyResponse as HybridStrategyResponse;
_electricMotorTorque = PreviousState.StrategyResponse.MechanicalAssistPower; _electricMotorTorque = PreviousState.StrategyResponse.MechanicalAssistPower;
var retVal = NextComponent.Initialize(outTorque, outAngularVelocity); var retVal = NextComponent.Initialize(outTorque, outAngularVelocity);
SelectedGear =DataBus.GearboxInfo.Gear; SelectedGear = DataBus.GearboxInfo.Gear;
return retVal; return retVal;
} }
...@@ -255,12 +237,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -255,12 +237,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
} }
private NewtonMeter MechanicalAssistPower(PowertrainPosition pos, Second absTime, Second dt, private NewtonMeter MechanicalAssistPower(PowertrainPosition pos, Second absTime, Second dt,
NewtonMeter outTorque, PerSecond prevOutAngularVelocity, PerSecond currOutAngularVelocity, bool dryRun) NewtonMeter outTorque, PerSecond prevOutAngularVelocity, PerSecond currOutAngularVelocity, bool dryRun) =>
{ _electricMotorTorque[pos]?.Item2;
return _electricMotorTorque[pos]?.Item2;
//return CurrentState.StrategyResponse.MechanicalAssistPower[pos];
}
public GearshiftPosition NextGear => CurrentState.StrategyResponse.NextGear; public GearshiftPosition NextGear => CurrentState.StrategyResponse.NextGear;
...@@ -381,7 +359,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -381,7 +359,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (DataBus.VehicleInfo.VehicleSpeed.IsEqual(0)) { if (DataBus.VehicleInfo.VehicleSpeed.IsEqual(0)) {
return InitStartGear(absTime, outTorque, outAngularVelocity); return InitStartGear(absTime, outTorque, outAngularVelocity);
} }
foreach (var entry in GearList.Reverse()) { foreach (var entry in GearList.Reverse()) {
var gear = entry; var gear = entry;
//for (var gear = (uint)GearboxModelData.Gears.Count; gear > 1; gear--) { //for (var gear = (uint)GearboxModelData.Gears.Count; gear > 1; gear--) {
...@@ -442,7 +420,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -442,7 +420,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
if (_runData != null && _runData.HybridStrategyParameters.MaxPropulsionTorque?.GetVECTOValueOrDefault(gear) != null) { if (_runData != null && _runData.HybridStrategyParameters.MaxPropulsionTorque?.GetVECTOValueOrDefault(gear) != null) {
var tqRequest = response.Gearbox.InputTorque; var tqRequest = response.Gearbox.InputTorque;
var maxTorque = _runData.HybridStrategyParameters.MaxPropulsionTorque[gear].FullLoadDriveTorque(response.Gearbox.InputSpeed); var maxTorque = _runData.HybridStrategyParameters.MaxPropulsionTorque[gear].FullLoadDriveTorque(response.Gearbox.InputSpeed);
reserve = 1 - VectoMath.Min(response.Engine.TorqueOutDemand / fullLoadPower, tqRequest / maxTorque); reserve = 1 - VectoMath.Min(response.Engine.TorqueOutDemand / fullLoadPower, tqRequest / maxTorque);
} }
if (response.Engine.EngineSpeed > DataBus.EngineInfo.EngineIdleSpeed && if (response.Engine.EngineSpeed > DataBus.EngineInfo.EngineIdleSpeed &&
...@@ -514,8 +492,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -514,8 +492,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public override IGearbox Gearbox public override IGearbox Gearbox
{ {
get => _gearbox; get => _gearbox;
set set {
{
var myGearbox = value as Gearbox; var myGearbox = value as Gearbox;
if (myGearbox == null) { if (myGearbox == null) {
throw new VectoException("This shift strategy can't handle gearbox of type {0}", throw new VectoException("This shift strategy can't handle gearbox of type {0}",
...@@ -542,21 +519,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -542,21 +519,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected new ATGearbox _gearbox; protected new ATGearbox _gearbox;
public HybridCtlATShiftStrategy(HybridController hybridController, IVehicleContainer container) : base( public HybridCtlATShiftStrategy(HybridController hybridController, IVehicleContainer container) : base(
hybridController, container) { } hybridController, container)
{ }
public override IGearbox Gearbox public override IGearbox Gearbox
{ {
get => _gearbox; get => _gearbox;
set set => _gearbox = value as ATGearbox ?? throw new VectoException("This shift strategy can't handle gearbox of type {0}", value.GetType());
{
var myGearbox = value as ATGearbox;
if (myGearbox == null) {
throw new VectoException("This shift strategy can't handle gearbox of type {0}",
value.GetType());
}
_gearbox = myGearbox;
}
} }
public override GearshiftPosition InitGear(Second absTime, Second dt, NewtonMeter torque, PerSecond outAngularVelocity) public override GearshiftPosition InitGear(Second absTime, Second dt, NewtonMeter torque, PerSecond outAngularVelocity)
...@@ -585,30 +554,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -585,30 +554,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return Gears.First(); return Gears.First();
} }
protected override bool DoCheckShiftRequired(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, protected override bool DoCheckShiftRequired(Second absTime, Second dt, NewtonMeter outTorque,
NewtonMeter inTorque, PerSecond inAngularVelocity, GearshiftPosition gear, Second lastShiftTime, PerSecond outAngularVelocity, NewtonMeter inTorque, PerSecond inAngularVelocity, GearshiftPosition gear,
IResponse response) Second lastShiftTime, IResponse response) =>
{ false;
return false;
}
//public override GearshiftPosition Engage(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity)
//{
// if (_nextGear.AbsTime != null && _nextGear.AbsTime.IsEqual(absTime)) {
// //_gearbox.Gear = _nextGear.Gear;
// _gearbox.Disengaged = _nextGear.Disengaged;
// _nextGear.AbsTime = null;
// return _nextGear.Gear;
// }
// _nextGear.AbsTime = null;
// return _gearbox.Gear;
//}
public override void Disengage(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity) public override void Disengage(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity) =>
{
throw new NotImplementedException("AT Shift Strategy does not support disengaging."); throw new NotImplementedException("AT Shift Strategy does not support disengaging.");
}
protected override bool SpeedTooLowForEngine(GearshiftPosition gear, PerSecond outAngularSpeed) protected override bool SpeedTooLowForEngine(GearshiftPosition gear, PerSecond outAngularSpeed)
{ {
...@@ -617,7 +569,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -617,7 +569,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
} }
return base.SpeedTooLowForEngine(gear, outAngularSpeed); return base.SpeedTooLowForEngine(gear, outAngularSpeed);
//(outAngularSpeed * GearboxModelData.Gears[gear.Gear].Ratio).IsSmaller(DataBus.EngineInfo.EngineIdleSpeed);
} }
protected override bool SpeedTooHighForEngine(GearshiftPosition gear, PerSecond outAngularSpeed) protected override bool SpeedTooHighForEngine(GearshiftPosition gear, PerSecond outAngularSpeed)
...@@ -627,12 +578,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -627,12 +578,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
} }
return base.SpeedTooHighForEngine(gear, outAngularSpeed); return base.SpeedTooHighForEngine(gear, outAngularSpeed);
//(outAngularSpeed * GearboxModelData.Gears[gear.Gear].Ratio).IsGreaterOrEqual(VectoMath.Min(
// GearboxModelData.Gears[gear.Gear].MaxSpeed,
// DataBus.EngineInfo.EngineN95hSpeed));
} }
} }
} }
} }
\ No newline at end of file
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