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

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

PTO Cycle now works, but stop-times have to be split up

parent 43b4dece
No related branches found
Tags Build/v0.7.9.2741
No related merge requests found
...@@ -400,7 +400,7 @@ namespace TUGraz.VectoCore.InputData.Reader ...@@ -400,7 +400,7 @@ namespace TUGraz.VectoCore.InputData.Reader
crossWindRequired ? row.ParseDouble(Fields.AirSpeedRelativeToVehicle).KMPHtoMeterPerSecond() : null, crossWindRequired ? row.ParseDouble(Fields.AirSpeedRelativeToVehicle).KMPHtoMeterPerSecond() : null,
WindYawAngle = crossWindRequired ? row.ParseDoubleOrGetDefault(Fields.WindYawAngle) : 0, WindYawAngle = crossWindRequired ? row.ParseDoubleOrGetDefault(Fields.WindYawAngle) : 0,
AuxiliarySupplyPower = row.GetAuxiliaries(), AuxiliarySupplyPower = row.GetAuxiliaries(),
PTOActive = table.Columns.Contains(Fields.PTOActive) && row.Field<char>(Fields.PTOActive) == '1' PTOActive = table.Columns.Contains(Fields.PTOActive) && row.Field<string>(Fields.PTOActive) == "1"
}); });
} }
......
...@@ -70,8 +70,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -70,8 +70,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
return BuildMeasuredSpeed(data); return BuildMeasuredSpeed(data);
case CycleType.MeasuredSpeedGear: case CycleType.MeasuredSpeedGear:
return BuildMeasuredSpeedGear(data); return BuildMeasuredSpeedGear(data);
case CycleType.DistanceBased:
return BuildFullPowertrain(data);
default:
throw new VectoException("Powertrain Builder cannot build Powertrain for CycleType: {0}", data.Cycle.CycleType);
} }
return BuildFullPowertrain(data);
} }
private VehicleContainer BuildEngineOnly(VectoRunData data) private VehicleContainer BuildEngineOnly(VectoRunData data)
...@@ -110,7 +113,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -110,7 +113,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
.AddComponent(gearbox, data.Retarder, data.PTO, container) .AddComponent(gearbox, data.Retarder, data.PTO, container)
.AddComponent(new CycleClutch(container)); .AddComponent(new CycleClutch(container));
var engine = new CombustionEngine(container, data.EngineData, pt1Disabled: true); var engine = new CombustionEngine(container, data.EngineData, pt1Disabled: true);
var idleController = GetIdleController(data.PTO, engine, container); var idleController = GetIdleController(data.PTO, engine);
powertrain.AddComponent(engine, idleController, container) powertrain.AddComponent(engine, idleController, container)
.AddAuxiliaries(container, data); .AddAuxiliaries(container, data);
...@@ -141,7 +144,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -141,7 +144,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
} }
var engine = new CombustionEngine(container, data.EngineData); var engine = new CombustionEngine(container, data.EngineData);
var idleController = GetIdleController(data.PTO, engine, container); var idleController = GetIdleController(data.PTO, engine);
powertrain.AddComponent(engine, idleController, container) powertrain.AddComponent(engine, idleController, container)
.AddAuxiliaries(container, data); .AddAuxiliaries(container, data);
...@@ -170,7 +173,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -170,7 +173,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
.AddComponent(new CycleClutch(container)); .AddComponent(new CycleClutch(container));
var engine = new CombustionEngine(container, data.EngineData); var engine = new CombustionEngine(container, data.EngineData);
powertrain.AddComponent(engine, GetIdleController(data.PTO, engine, container), container) powertrain.AddComponent(engine, GetIdleController(data.PTO, engine), container)
.AddAuxiliaries(container, data); .AddAuxiliaries(container, data);
return container; return container;
...@@ -199,7 +202,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -199,7 +202,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
} }
var engine = new CombustionEngine(container, data.EngineData); var engine = new CombustionEngine(container, data.EngineData);
var idleController = GetIdleController(data.PTO, engine, container); var idleController = GetIdleController(data.PTO, engine);
cycle.IdleController = idleController as IdleControllerSwitcher; cycle.IdleController = idleController as IdleControllerSwitcher;
powertrain.AddComponent(engine, idleController, container) powertrain.AddComponent(engine, idleController, container)
...@@ -210,11 +213,14 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ...@@ -210,11 +213,14 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
return container; return container;
} }
private static IIdleController GetIdleController(PTOData pto, CombustionEngine engine, IVehicleContainer container) private static IIdleController GetIdleController(PTOData pto, ICombustionEngine engine)
{ {
return pto == null if (pto == null)
? engine.IdleController return engine.IdleController;
: new IdleControllerSwitcher(engine.IdleController, new PTOCycleController(container, pto.PTOCycle)); else {
var ptoController = new PTOCycleController(pto.PTOCycle);
return new IdleControllerSwitcher(engine.IdleController, ptoController);
}
} }
internal static IAuxInProvider CreateAdvancedAuxiliaries(VectoRunData data, IVehicleContainer container) internal static IAuxInProvider CreateAdvancedAuxiliaries(VectoRunData data, IVehicleContainer container)
......
...@@ -57,6 +57,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -57,6 +57,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private readonly DrivingCycleData _data; private readonly DrivingCycleData _data;
internal readonly DrivingCycleEnumerator CycleIntervalIterator; internal readonly DrivingCycleEnumerator CycleIntervalIterator;
private bool _intervalProlonged; private bool _intervalProlonged;
internal IdleControllerSwitcher IdleController;
public DistanceBasedDrivingCycle(IVehicleContainer container, DrivingCycleData cycle) : base(container) public DistanceBasedDrivingCycle(IVehicleContainer container, DrivingCycleData cycle) : base(container)
{ {
...@@ -106,17 +107,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -106,17 +107,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
throw new VectoSimulationException("Stopping Time only allowed when target speed is zero!"); throw new VectoSimulationException("Stopping Time only allowed when target speed is zero!");
} }
var dt = CycleIntervalIterator.LeftSample.StoppingTime - PreviousState.WaitTime; var dt = CycleIntervalIterator.LeftSample.StoppingTime - PreviousState.WaitTime;
if (CycleIntervalIterator.LeftSample.StoppingTime.IsGreater(3 * Constants.SimulationSettings.TargetTimeInterval)) {
// split into 3 parts if (CycleIntervalIterator.LeftSample.PTOActive) {
if (PreviousState.WaitTime.IsEqual(0)) { if (PreviousState.WaitTime.IsEqual(0)) {
// waiting just started. Activate PTO
IdleController.Reset();
IdleController.ActivatePTO();
} else {
// we already started pto cycle and are now in the follow up call.
// So we have to manually commit the previous simulation step to go further.
IdleController.CommitSimulationStep();
}
var nextCycleTime = IdleController.GetNextCycleTime();
if (nextCycleTime == null) {
// PTO Cycle has finished. Switch to normal idle controller.
IdleController.ActivateIdle();
dt = Constants.SimulationSettings.TargetTimeInterval; dt = Constants.SimulationSettings.TargetTimeInterval;
} else { } else {
if (dt > Constants.SimulationSettings.TargetTimeInterval) { // set dt to the next time interval in the pto cycle (to synchronize driving cycle with pto cycle)
dt -= Constants.SimulationSettings.TargetTimeInterval; dt = nextCycleTime - PreviousState.WaitTime;
}
} else {
if (CycleIntervalIterator.LeftSample.StoppingTime.IsGreater(3 * Constants.SimulationSettings.TargetTimeInterval)) {
// split into 3 parts or use idle controller time intervals
if (PreviousState.WaitTime.IsEqual(0)) {
dt = Constants.SimulationSettings.TargetTimeInterval;
} else {
if (dt > Constants.SimulationSettings.TargetTimeInterval) {
dt -= Constants.SimulationSettings.TargetTimeInterval;
}
} }
} }
} }
CurrentState.Response = DriveTimeInterval(absTime, dt); CurrentState.Response = DriveTimeInterval(absTime, dt);
return CurrentState.Response; return CurrentState.Response;
} }
......
using System;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Connector.Ports;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class IdleControllerSwitcher : IIdleController
{
private readonly IIdleController _idleController;
private readonly PTOCycleController _ptoController;
private IIdleController _currentController;
public IdleControllerSwitcher(IIdleController idleController, PTOCycleController ptoController)
{
_idleController = idleController;
_ptoController = ptoController;
// default state is idleController
_currentController = _idleController;
}
public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity,
bool dryRun = false)
{
return _currentController.Request(absTime, dt, outTorque, outAngularVelocity, dryRun);
}
public IResponse Initialize(NewtonMeter outTorque, PerSecond outAngularVelocity)
{
throw new InvalidOperationException(string.Format("{0} cannot initialize.", GetType().FullName));
}
public ITnOutPort RequestPort
{
set
{
_idleController.RequestPort = value;
_ptoController.RequestPort = value;
}
}
public void Reset()
{
_idleController.Reset();
_ptoController.Reset();
_currentController = _idleController;
}
public void ActivatePTO()
{
_currentController = _ptoController;
}
public void ActivateIdle()
{
_currentController = _idleController;
}
public Second GetNextCycleTime()
{
return _ptoController.GetNextCycleTime();
}
public void CommitSimulationStep()
{
_ptoController.CommitSimulationStep(null);
}
}
}
\ No newline at end of file
...@@ -3,7 +3,6 @@ using TUGraz.VectoCommon.Models; ...@@ -3,7 +3,6 @@ using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils; using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Connector.Ports.Impl;
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
...@@ -17,8 +16,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -17,8 +16,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected Second IdleStart; protected Second IdleStart;
public PTOCycleController(IVehicleContainer container, DrivingCycleData cycle) public PTOCycleController(DrivingCycleData cycle) : base(null, cycle) {}
: base(container, cycle) {}
public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity,
bool dryRun = false) bool dryRun = false)
...@@ -42,10 +40,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -42,10 +40,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public void Reset() public void Reset()
{ {
LeftSample = Data.Entries.GetEnumerator(); LeftSample.Reset();
LeftSample.MoveNext(); LeftSample.MoveNext();
RightSample = Data.Entries.GetEnumerator(); RightSample.Reset();
RightSample.MoveNext(); RightSample.MoveNext();
RightSample.MoveNext(); RightSample.MoveNext();
...@@ -54,7 +52,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -54,7 +52,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public Second GetNextCycleTime() public Second GetNextCycleTime()
{ {
return IdleStart + RightSample.Current.Time; if (RightSample.Current == null)
return null;
return RightSample.Current.Time;
} }
} }
} }
\ No newline at end of file
...@@ -52,7 +52,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent ...@@ -52,7 +52,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent
protected VectoSimulationComponent(IVehicleContainer dataBus) protected VectoSimulationComponent(IVehicleContainer dataBus)
{ {
DataBus = dataBus; DataBus = dataBus;
dataBus.AddComponent(this);
// if a component doesn't want to be registered in DataBus, it supplies null to the constructor
// (mk 2016-08-31: currently the only example is PTOCycleController, to not interfere with the real DrivingCycle)
if (dataBus != null)
dataBus.AddComponent(this);
} }
public virtual void CommitSimulationStep(IModalDataContainer container) public virtual void CommitSimulationStep(IModalDataContainer container)
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.InputData.Reader; using TUGraz.VectoCore.InputData.Reader;
using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Declaration;
...@@ -134,62 +133,4 @@ namespace TUGraz.VectoCore.Utils ...@@ -134,62 +133,4 @@ namespace TUGraz.VectoCore.Utils
} }
} }
} }
public class IdleControllerSwitcher : IIdleController
{
private readonly IIdleController _idleController;
private readonly PTOCycleController _ptoController;
private IIdleController _currentController;
public IdleControllerSwitcher(IIdleController idleController, PTOCycleController ptoController)
{
_idleController = idleController;
_ptoController = ptoController;
// default state is idleController
_currentController = _idleController;
}
public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity,
bool dryRun = false)
{
return _currentController.Request(absTime, dt, outTorque, outAngularVelocity, dryRun);
}
public IResponse Initialize(NewtonMeter outTorque, PerSecond outAngularVelocity)
{
throw new InvalidOperationException(string.Format("{0} cannot initialize.", GetType().FullName));
}
public ITnOutPort RequestPort
{
set
{
_idleController.RequestPort = value;
_ptoController.RequestPort = value;
}
}
public void Reset()
{
_idleController.Reset();
_ptoController.Reset();
_currentController = _idleController;
}
public void ActivatePTO()
{
_currentController = _ptoController;
}
public void ActivateIdle()
{
_currentController = _idleController;
}
public Second GetNextCycleTime()
{
return _ptoController.GetNextCycleTime();
}
}
} }
\ No newline at end of file
...@@ -153,6 +153,7 @@ ...@@ -153,6 +153,7 @@
<Compile Include="Models\SimulationComponent\Impl\PTOCycleController.cs" /> <Compile Include="Models\SimulationComponent\Impl\PTOCycleController.cs" />
<Compile Include="Models\SimulationComponent\Impl\PWheelCycle.cs" /> <Compile Include="Models\SimulationComponent\Impl\PWheelCycle.cs" />
<Compile Include="Models\SimulationComponent\Impl\TorqueConverter.cs" /> <Compile Include="Models\SimulationComponent\Impl\TorqueConverter.cs" />
<Compile Include="Models\SimulationComponent\Impl\IdleControllerSwitcher.cs" />
<Compile Include="Utils\ProviderExtensions.cs" /> <Compile Include="Utils\ProviderExtensions.cs" />
<Compile Include="Models\Declaration\AirDrag.cs" /> <Compile Include="Models\Declaration\AirDrag.cs" />
<Compile Include="Models\Declaration\Fan.cs" /> <Compile Include="Models\Declaration\Fan.cs" />
......
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