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

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

reading driver data in engineering and declaration mode

parent 95758e8e
No related branches found
No related tags found
No related merge requests found
Showing with 147 additions and 43 deletions
......@@ -83,8 +83,8 @@ namespace TUGraz.VectoCore.FileIO.EngineeringFile
public class AuxDataEng : DataBodyDecl.AuxDataDecl
{
[JsonProperty(Required = Required.Always)] public string ID;
[JsonProperty(Required = Required.Always)] public string Type;
//[JsonProperty(Required = Required.Always)] public string ID;
//[JsonProperty(Required = Required.Always)] public string Type;
[JsonProperty(Required = Required.Always)] public string Path;
}
......
......@@ -6,6 +6,7 @@ using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.FileIO.DeclarationFile;
using TUGraz.VectoCore.FileIO.EngineeringFile;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
......@@ -51,8 +52,52 @@ namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
throw new VectoException("Unsupported GearboxData File Instance");
}
public override DriverData CreateDriverData(VectoJobFile job)
{
var fileV2Decl = job as VectoJobFileV2Declaration;
if (fileV2Decl != null) {
return CreateDriverData(fileV2Decl);
}
throw new VectoException("Unsupported Job File Instance");
}
//==========================
public DriverData CreateDriverData(VectoJobFileV2Declaration job)
{
var data = job.Body;
var lookAheadData = new DriverData.LACData() {
Enabled = DeclarationData.Driver.LookAhead.Enabled,
Deceleration = DeclarationData.Driver.LookAhead.Deceleration,
MinSpeed = DeclarationData.Driver.LookAhead.MinimumSpeed
};
var overspeedData = new DriverData.OverSpeedEcoRollData() {
Mode = DriverData.ParseDriverMode(data.OverSpeedEcoRoll.Mode),
MinSpeed = DeclarationData.Driver.OverSpeedEcoRoll.MinSpeed,
OverSpeed = DeclarationData.Driver.OverSpeedEcoRoll.OverSpeed,
UnderSpeed = DeclarationData.Driver.OverSpeedEcoRoll.UnderSpeed
};
if (!DeclarationData.Driver.OverSpeedEcoRoll.AllowedModes.Contains(overspeedData.Mode)) {
throw new VectoSimulationException(
String.Format("Specified Overspeed/EcoRoll Mode not allowed in declaration mode! {0}", overspeedData.Mode));
}
var startstopData = new VectoRunData.StartStopData() {
Enabled = data.StartStop.Enabled,
Delay = DeclarationData.Driver.StartStop.Delay,
MinTime = DeclarationData.Driver.StartStop.MinTime,
MaxSpeed = DeclarationData.Driver.StartStop.MaxSpeed,
};
var retVal = new DriverData() {
LookAheadCoasting = lookAheadData,
OverSpeedEcoRoll = overspeedData,
StartStop = startstopData,
};
return retVal;
}
internal VehicleData CreateVehicleData(VehicleFileV5Declaration vehicle, Mission mission, Kilogram loading)
{
var data = vehicle.Body;
......@@ -134,7 +179,7 @@ namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
for (uint i = 0; i < gearbox.Body.Gears.Count; i++) {
var gearSettings = gearbox.Body.Gears[(int) i];
var gearSettings = gearbox.Body.Gears[(int)i];
var lossMapPath = Path.Combine(gearbox.BasePath, gearSettings.LossMap);
TransmissionLossMap lossMap = TransmissionLossMap.ReadFromFile(lossMapPath, gearSettings.Ratio);
......
......@@ -67,19 +67,19 @@ namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
var lookAheadData = new DriverData.LACData() {
Enabled = data.LookAheadCoasting.Enabled,
Deceleration = DoubleExtensionMethods.SI<MeterPerSquareSecond>(data.LookAheadCoasting.Dec),
MinSpeed = data.LookAheadCoasting.MinSpeed.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(),
MinSpeed = data.LookAheadCoasting.MinSpeed.KMPHtoMeterPerSecond(),
};
var overspeedData = new DriverData.OverSpeedEcoRollData() {
Mode = EnumHelper.ParseDriverMode(data.OverSpeedEcoRoll.Mode),
MinSpeed = data.OverSpeedEcoRoll.MinSpeed.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(),
OverSpeed = data.OverSpeedEcoRoll.OverSpeed.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(),
UnderSpeed = data.OverSpeedEcoRoll.UnderSpeed.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(),
Mode = DriverData.ParseDriverMode(data.OverSpeedEcoRoll.Mode),
MinSpeed = data.OverSpeedEcoRoll.MinSpeed.KMPHtoMeterPerSecond(),
OverSpeed = data.OverSpeedEcoRoll.OverSpeed.KMPHtoMeterPerSecond(),
UnderSpeed = data.OverSpeedEcoRoll.UnderSpeed.KMPHtoMeterPerSecond(),
};
var startstopData = new VectoRunData.StartStopData() {
Enabled = data.StartStop.Enabled,
Delay = data.StartStop.Delay.SI<Second>(),
MinTime = data.StartStop.MinTime.SI<Second>(),
MaxSpeed = data.StartStop.MaxSpeed.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(),
MaxSpeed = data.StartStop.MaxSpeed.KMPHtoMeterPerSecond(),
};
var retVal = new DriverData() {
AccelerationCurve = accelerationData,
......
......@@ -30,9 +30,8 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
var tmpVehicle = dao.CreateVehicleData(Vehicle);
var segment = GetVehicleClassification(tmpVehicle.VehicleCategory, tmpVehicle.AxleConfiguration,
tmpVehicle.GrossVehicleMassRating, tmpVehicle.CurbWeight);
var accelerationCurve = AccelerationCurveData.ReadFromStream(segment.AccelerationFile);
var driverdata = new DriverData(new VectoRunData.StartStopData(), new DriverData.OverSpeedEcoRollData(),
new DriverData.LACData(), accelerationCurve);
var driverdata = dao.CreateDriverData(Job);
driverdata.AccelerationCurve = AccelerationCurveData.ReadFromStream(segment.AccelerationFile);
foreach (var mission in segment.Missions) {
foreach (var loading in mission.Loadings) {
var engineData = dao.CreateEngineData(Engine);
......
......@@ -76,6 +76,7 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
yield break;
}
var dao = new EngineeringDataAdapter();
var driver = dao.CreateDriverData(job);
foreach (var cycle in job.Body.Cycles) {
var simulationRunData = new VectoRunData() {
BasePath = job.BasePath,
......@@ -83,7 +84,7 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
EngineData = dao.CreateEngineData(Engine),
GearboxData = dao.CreateGearboxData(Gearbox, null),
VehicleData = dao.CreateVehicleData(Vehicle),
//DriverData = new DriverData(),
DriverData = driver,
//Aux =
// TODO: distance or time-based cycle!
Cycle = DrivingCycleData.ReadFromFile(Path.Combine(job.BasePath, cycle), DrivingCycleData.CycleType.DistanceBased),
......@@ -104,6 +105,12 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
return new EngineeringDataAdapter().CreateVehicleData(data);
}
public static DriverData CreateDriverDataFromFile(string file)
{
var data = DoReadJobFile(file);
return new EngineeringDataAdapter().CreateDriverData(data);
}
/// <summary>
/// Create CombustionEngineData instance directly from a file
/// </summary>
......@@ -126,25 +133,14 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
return new EngineeringDataAdapter().CreateGearboxData(data, null);
}
/// <summary>
/// initialize Job member (deserialize Job-file)
/// initialize vecto job member (deserialize Vecot-file
/// </summary>
/// <param name="file">file</param>
/// <param name="file"></param>
protected override void ReadJobFile(string file)
{
var json = File.ReadAllText(file);
var fileInfo = GetFileVersion(json);
CheckForEngineeringMode(fileInfo, "Job");
switch (fileInfo.Version) {
case 2:
Job = JsonConvert.DeserializeObject<VectoJobFileV2Engineering>(json);
Job.BasePath = Path.GetDirectoryName(file) + Path.DirectorySeparatorChar;
Job.JobFile = Path.GetFileName(file);
break;
default:
throw new UnsupportedFileVersionException("Unsupported version of job-file. Got version " + fileInfo.Version);
}
Job = DoReadJobFile(file);
}
/// <summary>
......@@ -165,6 +161,29 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
Gearbox = DoReadGearboxFile(file);
}
//==============================================================
/// <summary>
/// initialize Job member (deserialize Job-file)
/// </summary>
/// <param name="file">file</param>
protected static VectoJobFile DoReadJobFile(string file)
{
var json = File.ReadAllText(file);
var fileInfo = GetFileVersion(json);
CheckForEngineeringMode(fileInfo, "Job");
switch (fileInfo.Version) {
case 2:
var tmp = JsonConvert.DeserializeObject<VectoJobFileV2Engineering>(json);
tmp.BasePath = Path.GetDirectoryName(file) + Path.DirectorySeparatorChar;
tmp.JobFile = Path.GetFileName(file);
return tmp;
default:
throw new UnsupportedFileVersionException("Unsupported version of job-file. Got version " + fileInfo.Version);
}
}
/// <summary>
/// De-serialize engine-file (JSON)
/// </summary>
......
using System;
using TUGraz.VectoCore.Utils;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
......@@ -29,10 +30,5 @@ namespace TUGraz.VectoCore.Models.Declaration
{
return EnumHelper.Parse<AxleConfiguration>(Prefix + typeString);
}
public static DriverData.DriverMode ParseDriverMode(string driverString)
{
return (DriverData.DriverMode)Enum.Parse(typeof(DriverData.DriverMode), driverString.Replace("-", ""), true);
}
}
}
\ No newline at end of file
......@@ -111,6 +111,35 @@ namespace TUGraz.VectoCore.Models.Declaration
//Public Const AuxESeff As Single = 0.7
public static class Driver
{
public static class LookAhead
{
public const Boolean Enabled = true;
public static readonly MeterPerSquareSecond Deceleration = 0.5.SI<MeterPerSquareSecond>();
public static readonly MeterPerSecond MinimumSpeed = 50.KMPHtoMeterPerSecond();
}
public static class OverSpeedEcoRoll
{
public static readonly IList<DriverData.DriverMode> AllowedModes = new List<DriverData.DriverMode>() {
DriverData.DriverMode.EcoRoll,
DriverData.DriverMode.Overspeed
};
public static readonly MeterPerSecond MinSpeed = 50.KMPHtoMeterPerSecond();
public static readonly MeterPerSecond OverSpeed = 5.KMPHtoMeterPerSecond();
public static readonly MeterPerSecond UnderSpeed = 5.KMPHtoMeterPerSecond();
}
public static class StartStop
{
public static readonly MeterPerSecond MaxSpeed = 5.KMPHtoMeterPerSecond();
public static readonly Second Delay = 5.SI<Second>();
public static readonly Second MinTime = 5.SI<Second>();
}
}
public static class Trailer
{
public const double RollResistanceCoefficient = 0.00555;
......
......@@ -19,6 +19,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
public LACData LookAheadCoasting;
public AccelerationCurveData AccelerationCurve;
public static DriverMode ParseDriverMode(string mode)
{
return EnumHelper.Parse<DriverMode>(mode.Replace("-", ""));
}
public class OverSpeedEcoRollData
{
......
......@@ -95,6 +95,11 @@ namespace TUGraz.VectoCore.Utils
return self.SI().Rounds.Per.Minute.ConvertTo().Radian.Per.Second.Cast<PerSecond>();
}
public static MeterPerSecond KMPHtoMeterPerSecond(this double self)
{
return self.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>();
}
/// <summary>
/// Creates an SI object for the number (unit-less: [-]).
/// </summary>
......
......@@ -12,6 +12,12 @@ namespace TUGraz.VectoCore.Utils
return d.SI().Rounds.Per.Minute.ConvertTo().Radian.Per.Second.Cast<PerSecond>();
}
public static MeterPerSecond KMPHtoMeterPerSecond(this int d)
{
return d.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>();
}
/// <summary>
/// Gets the SI representation of the number (unit-less).
/// </summary>
......@@ -32,15 +38,15 @@ namespace TUGraz.VectoCore.Utils
return SIBase<T>.Create(d);
}
/// <summary>
/// Modulo functions which also works on negative Numbers (not like the built-in %-operator which just returns the remainder).
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Mod(this int a, int b)
{
return (a %= b) < 0 ? a + b : a;
}
/// <summary>
/// Modulo functions which also works on negative Numbers (not like the built-in %-operator which just returns the remainder).
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Mod(this int a, int b)
{
return (a %= b) < 0 ? a + b : a;
}
}
}
\ No newline at end of file
......@@ -154,6 +154,7 @@
<Compile Include="Models\Simulation\Impl\DistanceRun.cs" />
<Compile Include="Models\Simulation\Impl\PowertrainBuilder.cs" />
<Compile Include="Utils\DataTableExtensionMethods.cs" />
<Compile Include="Utils\EnumHelper.cs" />
<Compile Include="Utils\RessourceHelper.cs" />
<Compile Include="Models\Declaration\Segment.cs" />
<Compile Include="Models\SimulationComponent\Data\AuxiliaryCycleDataAdapter.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