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

Skip to content
Snippets Groups Projects
Commit 3fe6446e authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Adapting Auxiliary to work with Units class

parent c5a19943
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ using System.Linq; ...@@ -3,6 +3,7 @@ using System.Linq;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using Common.Logging; using Common.Logging;
using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Data namespace TUGraz.VectoCore.Models.SimulationComponent.Data
{ {
...@@ -24,15 +25,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -24,15 +25,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
} }
} }
public double GetPowerDemand(TimeSpan absTime, TimeSpan dt) public Watt GetPowerDemand(TimeSpan absTime, TimeSpan dt)
{ {
var entry = _drivingCycle.Entries.FindIndex(x => x.Time > absTime.TotalSeconds); var entry = _drivingCycle.Entries.FindLastIndex(x => x.Time <= absTime.TotalSeconds);
//if (entry == null) { //if (entry == null) {
// Log.ErrorFormat("could not find entry in driving cycle for time {0}", absTime.TotalSeconds); // Log.ErrorFormat("could not find entry in driving cycle for time {0}", absTime.TotalSeconds);
// return 0; // return 0;
//} //}
Log.ErrorFormat("Found Entry at index {0}", entry); Log.ErrorFormat("Found Entry at index {0}", entry);
return _auxiliaryId == null ? _drivingCycle.Entries[entry].AdditionalAuxPowerDemand * 1000 : _drivingCycle.Entries[entry].AuxiliarySupplyPower[_auxiliaryId] * 1000; return _auxiliaryId == null ? _drivingCycle.Entries[entry].AdditionalAuxPowerDemand : _drivingCycle.Entries[entry].AuxiliarySupplyPower[_auxiliaryId];
} }
} }
......
...@@ -122,7 +122,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -122,7 +122,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
/// Auxiliary. ID's are not case sensitive and must not contain /// Auxiliary. ID's are not case sensitive and must not contain
/// space or special characters. /// space or special characters.
/// </summary> /// </summary>
public Dictionary<string, double> AuxiliarySupplyPower { get; set; } public Dictionary<string, Watt> AuxiliarySupplyPower { get; set; }
/// <summary> /// <summary>
/// [rad/s] If "n" is defined VECTO uses that instead of the /// [rad/s] If "n" is defined VECTO uses that instead of the
...@@ -223,12 +223,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -223,12 +223,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
/// <summary> /// <summary>
/// [W]. Reads Auxiliary Supply Power (defined by Fields.AuxiliarySupplyPower-Prefix). /// [W]. Reads Auxiliary Supply Power (defined by Fields.AuxiliarySupplyPower-Prefix).
/// </summary> /// </summary>
public static Dictionary<string, double> Read(DataRow row) public static Dictionary<string, Watt> Read(DataRow row)
{ {
return row.Table.Columns.Cast<DataColumn>(). return row.Table.Columns.Cast<DataColumn>().
Where(col => col.ColumnName.StartsWith(Fields.AuxiliarySupplyPower)). Where(col => col.ColumnName.StartsWith(Fields.AuxiliarySupplyPower)).
ToDictionary(col => col.ColumnName.Substring(Fields.AuxiliarySupplyPower.Length - 1), ToDictionary(col => col.ColumnName.Substring(Fields.AuxiliarySupplyPower.Length - 1),
col => (double)row.ParseDouble(col).SI().Kilo.Watt); col => row.ParseDouble(col).SI().Kilo.Watt.To<Watt>());
} }
} }
...@@ -366,6 +366,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -366,6 +366,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
public IEnumerable<DrivingCycleEntry> Parse(DataTable table) public IEnumerable<DrivingCycleEntry> Parse(DataTable table)
{ {
ValidateHeader(table.Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray()); ValidateHeader(table.Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray());
TimeSpan absTime = new TimeSpan(hours: 0, minutes:0, seconds: 0);
foreach (DataRow row in table.Rows) foreach (DataRow row in table.Rows)
{ {
...@@ -390,6 +391,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -390,6 +391,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
entry.EngineTorque = Formulas.PowerToTorque(row.ParseDouble(Fields.EnginePower).SI().Kilo.Watt.To<Watt>(), entry.EngineTorque = Formulas.PowerToTorque(row.ParseDouble(Fields.EnginePower).SI().Kilo.Watt.To<Watt>(),
entry.EngineSpeed); entry.EngineSpeed);
} }
entry.Time = absTime.TotalSeconds;
absTime += new TimeSpan(hours: 0, minutes: 0, seconds: 1);
yield return entry; yield return entry;
} }
} }
......
...@@ -12,7 +12,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -12,7 +12,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{ {
private ITnOutPort _outPort; private ITnOutPort _outPort;
private AuxiliariesDemandAdapter _demand; private AuxiliariesDemandAdapter _demand;
private double _powerDemand; private Watt _powerDemand;
public EngineOnlyAuxiliary(IVehicleContainer container, AuxiliariesDemandAdapter demand) : base(container) public EngineOnlyAuxiliary(IVehicleContainer container, AuxiliariesDemandAdapter demand) : base(container)
...@@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
_outPort = other; _outPort = other;
} }
public void Request(TimeSpan absTime, TimeSpan dt, double torque, double engineSpeed) public void Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, RadianPerSecond engineSpeed)
{ {
if (_outPort == null) if (_outPort == null)
{ {
...@@ -43,13 +43,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -43,13 +43,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
throw new VectoSimulationException(String.Format("{0} cannot handle incoming request - no outport available", absTime.TotalSeconds)); throw new VectoSimulationException(String.Format("{0} cannot handle incoming request - no outport available", absTime.TotalSeconds));
} }
_powerDemand = _demand.GetPowerDemand(absTime, dt); _powerDemand = _demand.GetPowerDemand(absTime, dt);
var tq = VectoMath.ConvertPowerRpmToTorque(_powerDemand, engineSpeed); var tq = Formulas.PowerToTorque(_powerDemand, engineSpeed);
_outPort.Request(absTime, dt, torque + tq, engineSpeed); _outPort.Request(absTime, dt, (torque + tq).To<NewtonMeter>(), engineSpeed);
} }
public override void CommitSimulationStep(IModalDataWriter writer) public override void CommitSimulationStep(IModalDataWriter writer)
{ {
writer[ModalResultField.Paux] = _powerDemand; writer[ModalResultField.Paux] = (double)_powerDemand;
} }
} }
} }
\ No newline at end of file
...@@ -27,7 +27,7 @@ namespace TUGraz.VectoCore.Tests.Utils ...@@ -27,7 +27,7 @@ namespace TUGraz.VectoCore.Tests.Utils
public void CommitSimulationStep(TimeSpan absTime, TimeSpan simulationInterval) public void CommitSimulationStep(TimeSpan absTime, TimeSpan simulationInterval)
{ {
CurrentRow[ModalResultField.time.GetName()] = (absTime - TimeSpan.FromTicks(simulationInterval.Ticks / 2)).TotalSeconds; CurrentRow[ModalResultField.time.GetName()] = (absTime + TimeSpan.FromTicks(simulationInterval.Ticks / 2)).TotalSeconds;
CurrentRow[ModalResultField.simulationInterval.GetName()] = simulationInterval.TotalSeconds; CurrentRow[ModalResultField.simulationInterval.GetName()] = simulationInterval.TotalSeconds;
CommitSimulationStep(); CommitSimulationStep();
} }
......
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