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

Skip to content
Snippets Groups Projects
Commit 1cb9cf32 authored by Markus QUARITSCH's avatar Markus QUARITSCH
Browse files

refactoring

parent 83507d71
No related branches found
No related tags found
No related merge requests found
...@@ -29,145 +29,152 @@ ...@@ -29,145 +29,152 @@
* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
*/ */
using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils; using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports;
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.Simulation.DataBus;
using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.OutputData;
using TUGraz.VectoCore.Utils; using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{ {
public class Clutch : StatefulProviderComponent<Clutch.ClutchState, ITnOutPort, ITnInPort, ITnOutPort>, IClutch, public class Clutch : StatefulProviderComponent<Clutch.ClutchState, ITnOutPort, ITnInPort, ITnOutPort>, IClutch,
ITnOutPort, ITnInPort ITnOutPort, ITnInPort
{ {
private readonly PerSecond _idleSpeed; private readonly PerSecond _idleSpeed;
private readonly PerSecond _ratedSpeed; private readonly PerSecond _ratedSpeed;
public IIdleController IdleController { public IIdleController IdleController
get { return _idleController; } {
set { get { return _idleController; }
_idleController = value; set
_idleController.RequestPort = NextComponent; {
} _idleController = value;
} _idleController.RequestPort = NextComponent;
}
private readonly SI _clutchSpeedSlippingFactor; }
private IIdleController _idleController;
private readonly SI _clutchSpeedSlippingFactor;
public Clutch(IVehicleContainer container, CombustionEngineData engineData) : base(container) private IIdleController _idleController;
{
_idleSpeed = engineData.IdleSpeed; public Clutch(IVehicleContainer container, CombustionEngineData engineData) : base(container)
_ratedSpeed = engineData.FullLoadCurves[0].RatedSpeed; {
_clutchSpeedSlippingFactor = Constants.SimulationSettings.ClutchClosingSpeedNorm * (_ratedSpeed - _idleSpeed) / _idleSpeed = engineData.IdleSpeed;
(_idleSpeed + Constants.SimulationSettings.ClutchClosingSpeedNorm * (_ratedSpeed - _idleSpeed)); _ratedSpeed = engineData.FullLoadCurves[0].RatedSpeed;
} _clutchSpeedSlippingFactor = Constants.SimulationSettings.ClutchClosingSpeedNorm * (_ratedSpeed - _idleSpeed) /
(_idleSpeed + Constants.SimulationSettings.ClutchClosingSpeedNorm * (_ratedSpeed - _idleSpeed));
public IResponse Initialize(NewtonMeter outTorque, PerSecond outAngularVelocity) }
{
NewtonMeter torqueIn; public IResponse Initialize(NewtonMeter outTorque, PerSecond outAngularVelocity)
PerSecond engineSpeedIn; {
if (DataBus.DriverBehavior == DrivingBehavior.Halted /*DataBus.VehicleStopped*/) { NewtonMeter torqueIn;
engineSpeedIn = _idleSpeed; PerSecond engineSpeedIn;
torqueIn = 0.SI<NewtonMeter>(); if (DataBus.DriverBehavior == DrivingBehavior.Halted /*DataBus.VehicleStopped*/) {
} else { engineSpeedIn = _idleSpeed;
AddClutchLoss(outTorque, outAngularVelocity, true, out torqueIn, out engineSpeedIn); torqueIn = 0.SI<NewtonMeter>();
} } else {
PreviousState.SetState(torqueIn, outAngularVelocity, outTorque, outAngularVelocity); AddClutchLoss(outTorque, outAngularVelocity, true, out torqueIn, out engineSpeedIn);
}
var retVal = NextComponent.Initialize(torqueIn, engineSpeedIn); PreviousState.SetState(torqueIn, outAngularVelocity, outTorque, outAngularVelocity);
retVal.ClutchPowerRequest = outTorque * outAngularVelocity;
return retVal; var retVal = NextComponent.Initialize(torqueIn, engineSpeedIn);
} retVal.ClutchPowerRequest = outTorque * outAngularVelocity;
return retVal;
public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, }
bool dryRun = false)
{ public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity,
var startClutch = DataBus.VehicleStopped || !PreviousState.ClutchLoss.IsEqual(0); bool dryRun = false)
if (!DataBus.ClutchClosed(absTime) && !dryRun) { {
Log.Debug("Invoking IdleController..."); var startClutch = DataBus.VehicleStopped || !PreviousState.ClutchLoss.IsEqual(0);
var retval = IdleController.Request(absTime, dt, outTorque, null, dryRun); if (!DataBus.ClutchClosed(absTime) && !dryRun) {
retval.ClutchPowerRequest = 0.SI<Watt>(); Log.Debug("Invoking IdleController...");
CurrentState.SetState(0.SI<NewtonMeter>(), retval.EngineSpeed, outTorque, outAngularVelocity); var retval = IdleController.Request(absTime, dt, outTorque, null, dryRun);
CurrentState.ClutchLoss = 0.SI<Watt>(); retval.ClutchPowerRequest = 0.SI<Watt>();
return retval; CurrentState.SetState(0.SI<NewtonMeter>(), retval.EngineSpeed, outTorque, outAngularVelocity);
} CurrentState.ClutchLoss = 0.SI<Watt>();
if (IdleController != null) { return retval;
IdleController.Reset(); }
} if (IdleController != null) {
IdleController.Reset();
Log.Debug("from Wheels: torque: {0}, angularVelocity: {1}, power {2}", outTorque, outAngularVelocity, }
Formulas.TorqueToPower(outTorque, outAngularVelocity));
Log.Debug("from Wheels: torque: {0}, angularVelocity: {1}, power {2}", outTorque, outAngularVelocity,
NewtonMeter torqueIn; Formulas.TorqueToPower(outTorque, outAngularVelocity));
PerSecond angularVelocityIn;
if (DataBus.DriverBehavior == DrivingBehavior.Halted /*DataBus.VehicleStopped*/) { NewtonMeter torqueIn;
angularVelocityIn = _idleSpeed; PerSecond angularVelocityIn;
torqueIn = 0.SI<NewtonMeter>();
} else { AddClutchLoss(outTorque, outAngularVelocity,
AddClutchLoss(outTorque, outAngularVelocity, (DataBus.Gear == 1 && outTorque > 0) ||startClutch || outAngularVelocity.IsEqual(0), out torqueIn, out angularVelocityIn); (DataBus.Gear == 1 && outTorque > 0) || startClutch || outAngularVelocity.IsEqual(0), out torqueIn,
} out angularVelocityIn);
Log.Debug("to Engine: torque: {0}, angularVelocity: {1}, power {2}", torqueIn, angularVelocityIn,
Formulas.TorqueToPower(torqueIn, angularVelocityIn)); 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 avgOutAngularVelocity = (PreviousState.OutAngularVelocity + outAngularVelocity) / 2.0;
var clutchLoss = torqueIn * avgInAngularVelocity - outTorque * avgOutAngularVelocity; var avgInAngularVelocity = (PreviousState.InAngularVelocity + angularVelocityIn) / 2.0;
if (!startClutch && !clutchLoss.IsEqual(0)) { var clutchLoss = torqueIn * avgInAngularVelocity - outTorque * avgOutAngularVelocity;
// we don't want to have negative clutch losses, so adapt input torque to match the average output power if (!startClutch && !clutchLoss.IsEqual(0)) {
torqueIn = outTorque * avgOutAngularVelocity / avgInAngularVelocity; // 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) { var retVal = NextComponent.Request(absTime, dt, torqueIn, angularVelocityIn, dryRun);
CurrentState.SetState(torqueIn, angularVelocityIn, outTorque, outAngularVelocity); if (!dryRun) {
CurrentState.ClutchLoss = torqueIn * avgInAngularVelocity - outTorque * avgOutAngularVelocity; CurrentState.SetState(torqueIn, angularVelocityIn, outTorque, outAngularVelocity);
} CurrentState.ClutchLoss = torqueIn * avgInAngularVelocity - outTorque * avgOutAngularVelocity;
retVal.ClutchPowerRequest = outTorque * }
((PreviousState.OutAngularVelocity ?? 0.SI<PerSecond>()) + CurrentState.OutAngularVelocity) / 2.0; retVal.ClutchPowerRequest = outTorque *
return retVal; ((PreviousState.OutAngularVelocity ?? 0.SI<PerSecond>()) + CurrentState.OutAngularVelocity) / 2.0;
} return retVal;
}
private void AddClutchLoss(NewtonMeter torque, PerSecond angularVelocity, bool startClutch, out NewtonMeter torqueIn, out PerSecond angularVelocityIn)
{ private void AddClutchLoss(NewtonMeter torque, PerSecond angularVelocity, bool startClutch, out NewtonMeter torqueIn,
torqueIn = torque; out PerSecond angularVelocityIn)
angularVelocityIn = angularVelocity; {
if (DataBus.DriverBehavior == DrivingBehavior.Halted) {
var engineSpeedNorm = (angularVelocity - _idleSpeed) / (_ratedSpeed - _idleSpeed); angularVelocityIn = _idleSpeed;
if (startClutch && engineSpeedNorm < Constants.SimulationSettings.ClutchClosingSpeedNorm) { torqueIn = 0.SI<NewtonMeter>();
// MQ: 27.5.2016: when angularVelocity is 0 (at the end of the simulation interval) don't use the return;
// angularVelocity but average angular velocity }
// Reason: if angularVelocity = 0 also the power (torque * angularVelocity) is 0 and then
// the torque demand for the engine is 0. no drag torque although vehicle has to decelerate torqueIn = torque;
// "the clutch" eats up the whole torque angularVelocityIn = angularVelocity;
var engineSpeed = VectoMath.Max(_idleSpeed, angularVelocity);
var engineSpeedNorm = (angularVelocity - _idleSpeed) / (_ratedSpeed - _idleSpeed);
angularVelocityIn = _clutchSpeedSlippingFactor * engineSpeed + _idleSpeed; if (startClutch && engineSpeedNorm < Constants.SimulationSettings.ClutchClosingSpeedNorm) {
// MQ: 27.5.2016: when angularVelocity is 0 (at the end of the simulation interval) don't use the
} // angularVelocity but average angular velocity
} // Reason: if angularVelocity = 0 also the power (torque * angularVelocity) is 0 and then
// the torque demand for the engine is 0. no drag torque although vehicle has to decelerate
protected override void DoWriteModalResults(IModalDataContainer container) // "the clutch" eats up the whole torque
{ var engineSpeed = VectoMath.Max(_idleSpeed, angularVelocity);
if (PreviousState.InAngularVelocity == null || CurrentState.InAngularVelocity == null) {
container[ModalResultField.P_clutch_out] = 0.SI<Watt>(); angularVelocityIn = _clutchSpeedSlippingFactor * engineSpeed + _idleSpeed;
container[ModalResultField.P_clutch_loss] = 0.SI<Watt>(); }
} else { }
var avgOutAngularVelocity = (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0;
var avgInAngularVelocity = (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0; protected override void DoWriteModalResults(IModalDataContainer container)
container[ModalResultField.P_clutch_out] = CurrentState.OutTorque * avgOutAngularVelocity; {
container[ModalResultField.P_clutch_loss] = CurrentState.InTorque * avgInAngularVelocity - if (PreviousState.InAngularVelocity == null || CurrentState.InAngularVelocity == null) {
CurrentState.OutTorque * avgOutAngularVelocity; container[ModalResultField.P_clutch_out] = 0.SI<Watt>();
} container[ModalResultField.P_clutch_loss] = 0.SI<Watt>();
} } else {
var avgOutAngularVelocity = (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0;
public class ClutchState : SimpleComponentState var avgInAngularVelocity = (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0;
{ container[ModalResultField.P_clutch_out] = CurrentState.OutTorque * avgOutAngularVelocity;
public Watt ClutchLoss = 0.SI<Watt>(); container[ModalResultField.P_clutch_loss] = CurrentState.InTorque * avgInAngularVelocity -
} CurrentState.OutTorque * avgOutAngularVelocity;
} }
}
public class ClutchState : SimpleComponentState
{
public Watt ClutchLoss = 0.SI<Watt>();
}
}
} }
\ No newline at end of file
...@@ -175,9 +175,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -175,9 +175,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// if the clutch disengages the idle controller should take over! // if the clutch disengages the idle controller should take over!
throw new VectoSimulationException("angular velocity is null! Clutch open without IdleController?"); throw new VectoSimulationException("angular velocity is null! Clutch open without IdleController?");
} }
if (angularVelocity < ModelData.IdleSpeed.Value() - EngineIdleSpeedStopThreshold) { //if (angularVelocity < ModelData.IdleSpeed.Value() - EngineIdleSpeedStopThreshold) {
CurrentState.OperationMode = EngineOperationMode.Stopped; // CurrentState.OperationMode = EngineOperationMode.Stopped;
} //}
var avgEngineSpeed = (PreviousState.EngineSpeed + angularVelocity) / 2.0; var avgEngineSpeed = (PreviousState.EngineSpeed + angularVelocity) / 2.0;
...@@ -192,9 +192,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -192,9 +192,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var fullDragTorque = ModelData.FullLoadCurves[DataBus.Gear].DragLoadStationaryTorque(avgEngineSpeed); var fullDragTorque = ModelData.FullLoadCurves[DataBus.Gear].DragLoadStationaryTorque(avgEngineSpeed);
var dynamicFullLoadPower = ComputeFullLoadPower(avgEngineSpeed, dt, dryRun); var dynamicFullLoadPower = ComputeFullLoadPower(avgEngineSpeed, dt, dryRun);
if (dynamicFullLoadPower < 0) {
dynamicFullLoadPower = 0.SI<Watt>();
}
var dynamicFullLoadTorque = dynamicFullLoadPower / avgEngineSpeed; var dynamicFullLoadTorque = dynamicFullLoadPower / avgEngineSpeed;
var inertiaTorqueLoss = var inertiaTorqueLoss =
Formulas.InertiaPower(angularVelocity, PreviousState.EngineSpeed, ModelData.Inertia, dt) / Formulas.InertiaPower(angularVelocity, PreviousState.EngineSpeed, ModelData.Inertia, dt) /
...@@ -460,6 +458,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -460,6 +458,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
dynFullPowerCalculated = stationaryFullLoadPower; dynFullPowerCalculated = stationaryFullLoadPower;
} }
if (dynFullPowerCalculated < 0) {
return 0.SI<Watt>();
}
return dynFullPowerCalculated; return dynFullPowerCalculated;
} }
...@@ -590,7 +591,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -590,7 +591,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
angularSpeed = angularSpeed.LimitTo(_engine.ModelData.IdleSpeed, _engine.EngineRatedSpeed); angularSpeed = angularSpeed.LimitTo(_engine.ModelData.IdleSpeed, _engine.EngineRatedSpeed);
retVal = RequestPort.Request(absTime, dt, 0.SI<NewtonMeter>(), angularSpeed); retVal = RequestPort.Request(absTime, dt, 0.SI<NewtonMeter>(), angularSpeed);
}). }).
Default(r => { throw new UnexpectedResponseException("searching Idling point", r); }); Default(r => {
throw new UnexpectedResponseException("searching Idling point", r);
});
return retVal; return retVal;
} }
...@@ -647,7 +650,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -647,7 +650,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
0.SI<NewtonMeter>(), angularSpeed); 0.SI<NewtonMeter>(), angularSpeed);
retVal = RequestPort.Request(absTime, dt, 0.SI<NewtonMeter>(), angularSpeed); retVal = RequestPort.Request(absTime, dt, 0.SI<NewtonMeter>(), angularSpeed);
}). }).
Default(r => { throw new UnexpectedResponseException("searching Idling point", r); }); Default(r => {
throw new UnexpectedResponseException("searching Idling point", r);
});
return retVal; return retVal;
} }
......
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