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

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

minimal dirvingcycle test - modal results output, refactoring si units output,...

minimal dirvingcycle test - modal results output, refactoring si units output, interface for vehicle distance
parent 0abdcc57
No related branches found
No related tags found
No related merge requests found
Showing
with 98 additions and 33 deletions
namespace TUGraz.VectoCore.Models.Simulation.Cockpit
{
/// <summary>
/// Defines interfaces for all different cockpits to access shared data of the powertrain.
/// </summary>
public interface ICockpit : IGearboxCockpit, IEngineCockpit, IVehicleCockpit {}
/// <summary>
/// Defines interfaces for all different cockpits to access shared data of the powertrain.
/// </summary>
public interface ICockpit : IGearboxCockpit, IEngineCockpit, IVehicleCockpit, IMileageCounter {}
}
\ No newline at end of file
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Simulation.Cockpit
{
public interface IMileageCounter
{
Meter Distance();
}
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
if (!_engineOnly) {
dataColumns.AddRange(new[] {
//ModalResultField.time,
ModalResultField.simulationInterval,
ModalResultField.dist,
ModalResultField.v_act,
ModalResultField.v_targ,
......
......@@ -71,7 +71,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
/// <summary>
/// Simulation interval around the current time step. [s]
/// </summary>
[ModalResultField(typeof(SI), "simulation_interval", "simulation_interval [s]")] simulationInterval,
[ModalResultField(typeof(SI), "simulation_interval", "dt [s]")] simulationInterval,
/// <summary>
/// Engine speed [1/min].
......@@ -166,7 +166,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
/// <summary>
/// [%] Road gradient.
/// </summary>
[ModalResultField(typeof(SI))] grad,
[ModalResultField(typeof(double))] grad,
/// <summary>
/// [-] GearData. "0" = clutch opened / neutral. "0.5" = lock-up clutch is open (AT with torque converter only, see
......
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using Common.Logging;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
......@@ -17,6 +18,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
internal IGearboxCockpit _gearbox;
internal IVehicleCockpit _vehicle;
internal IMileageCounter _milageCounter;
internal ISimulationOutPort _cycle;
internal ISummaryDataWriter _sumWriter;
......@@ -109,6 +112,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
if (cycle != null) {
_cycle = cycle;
}
var milage = component as IMileageCounter;
if (milage != null) {
_milageCounter = milage;
}
}
......@@ -120,7 +128,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
}
if (_dataWriter != null) {
_dataWriter[ModalResultField.time] = time;
_dataWriter[ModalResultField.time] = time + simulationInterval / 2;
_dataWriter[ModalResultField.simulationInterval] = simulationInterval;
_dataWriter.CommitSimulationStep();
}
......@@ -140,5 +148,10 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
{
return new ReadOnlyCollection<VectoSimulationComponent>(_components);
}
public Meter Distance()
{
return _milageCounter.Distance();
}
}
}
\ No newline at end of file
......@@ -111,17 +111,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
CurrentState.AbsTime = PreviousState.AbsTime + dt;
CurrentState.WaitTime = PreviousState.WaitTime + dt;
CurrentState.Gradient = ComputeGradient();
return _outPort.Request(absTime, dt, CycleIntervalIterator.LeftSample.VehicleTargetSpeed, ComputeGradient());
return _outPort.Request(absTime, dt, CycleIntervalIterator.LeftSample.VehicleTargetSpeed, CurrentState.Gradient);
}
private IResponse DriveDistance(Second absTime, Meter ds)
{
CurrentState.Distance = PreviousState.Distance + ds;
CurrentState.VehicleTargetSpeed = CycleIntervalIterator.LeftSample.VehicleTargetSpeed;
CurrentState.Gradient = ComputeGradient();
return _outPort.Request(absTime, ds, CurrentState.VehicleTargetSpeed, ComputeGradient());
return _outPort.Request(absTime, ds, CurrentState.VehicleTargetSpeed, CurrentState.Gradient);
}
private Radian ComputeGradient()
......@@ -164,7 +165,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
#region VectoSimulationComponent
protected override void DoWriteModalResults(IModalDataWriter writer) {}
protected override void DoWriteModalResults(IModalDataWriter writer)
{
writer[ModalResultField.v_targ] = CurrentState.VehicleTargetSpeed;
writer[ModalResultField.grad] = Math.Tan(CurrentState.Gradient.Value()) * 100;
}
protected override void DoCommitSimulationStep()
{
......@@ -274,6 +279,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public Meter Altitude;
public Radian Gradient;
public IResponse Response;
}
}
......
......@@ -97,6 +97,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
solutions.Sort();
dt = solutions.First().SI<Second>();
}
CurrentState.Acceleration = requiredAcceleration;
var retVal = Next.Request(absTime, dt, requiredAcceleration, gradient);
retVal.SimulationInterval = dt;
return retVal;
......@@ -121,7 +123,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected override void DoWriteModalResults(IModalDataWriter writer)
{
// todo??
writer[ModalResultField.acc] = CurrentState.Acceleration;
}
protected override void DoCommitSimulationStep()
......@@ -134,6 +136,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public class DriverState
{
public MeterPerSquareSecond Acceleration;
public IResponse Response;
}
}
......
using System;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Simulation.Cockpit;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
......@@ -7,7 +8,7 @@ using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class Vehicle : VectoSimulationComponent, IVehicle, IFvInPort, IDriverDemandOutPort
public class Vehicle : VectoSimulationComponent, IVehicle, IMileageCounter, IFvInPort, IDriverDemandOutPort
{
private IFvOutPort _nextInstance;
......@@ -46,6 +47,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
protected override void DoWriteModalResults(IModalDataWriter writer)
{
writer[ModalResultField.v_act] = (_previousState.Velocity + _currentState.Velocity) / 2;
writer[ModalResultField.dist] = (_previousState.Distance - _currentState.Distance) / 2;
}
protected override void DoCommitSimulationStep()
......@@ -56,7 +58,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public IResponse Request(Second absTime, Second dt, MeterPerSquareSecond accelleration, Radian gradient)
{
_currentState.Velocity = _previousState.Velocity + (accelleration * (dt / 2.0)).Cast<MeterPerSecond>();
_currentState.Velocity = (_previousState.Velocity + (accelleration * dt)).Cast<MeterPerSecond>();
_currentState.dt = dt;
_currentState.Distance = ((_previousState.Velocity + _currentState.Velocity) / 2 * _currentState.dt).Cast<Meter>();
// DriverAcceleration = vehicleAccelerationForce - RollingResistance - AirDragResistance - SlopeResistance
var vehicleAccelerationForce = DriverAcceleration(accelleration) + RollingResistance(gradient) +
......@@ -68,6 +72,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public IResponse Initialize()
{
_previousState = new VehicleState() { Distance = 0.SI<Meter>(), Velocity = 0.SI<MeterPerSecond>() };
_currentState = new VehicleState() { Distance = 0.SI<Meter>(), Velocity = 0.SI<MeterPerSecond>() };
return _nextInstance.Initialize();
}
......@@ -130,6 +136,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public class VehicleState
{
public MeterPerSecond Velocity;
public Second dt;
public Meter Distance;
}
public Meter Distance()
{
return _previousState.Distance;
}
}
}
\ No newline at end of file
......@@ -3,9 +3,11 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json;
using TUGraz.VectoCore.Exceptions;
......@@ -932,10 +934,10 @@ namespace TUGraz.VectoCore.Utils
public virtual string ToString(string format)
{
if (string.IsNullOrEmpty(format)) {
format = "";
format = "F4";
}
return string.Format("{0:" + format + "} [{2}]", Val, format, GetUnitString());
return string.Format(CultureInfo.InvariantCulture, "{0:" + format + "} [{2}]", Val, format, GetUnitString());
}
#endregion
......@@ -1019,5 +1021,14 @@ namespace TUGraz.VectoCore.Utils
}
#endregion
public virtual string ToOutpuFormat(uint deciamls = 4, double outputFactor = 1.0, bool showUnit = false)
{
var fmt = new StringBuilder("{0:F").Append(deciamls).Append("}");
if (showUnit) {
fmt.Append(" [{2}]");
}
return string.Format(CultureInfo.InvariantCulture, fmt.ToString(), Val * outputFactor, GetUnitString());
}
}
}
\ No newline at end of file
......@@ -154,11 +154,8 @@ namespace TUGraz.VectoCore.Utils
foreach (DataRow row in table.Rows) {
var formattedList = new List<string>();
foreach (var item in row.ItemArray) {
var formattable = item as IFormattable;
var formattedValue = formattable != null
? formattable.ToString("", CultureInfo.InvariantCulture)
: item.ToString();
formattedList.Add(formattedValue);
var si = item as SI;
formattedList.Add(si != null ? si.ToOutpuFormat() : string.Format(CultureInfo.InvariantCulture, "{0}", item));
}
sb.AppendLine(string.Join(Delimiter.ToString(), formattedList));
}
......
......@@ -153,6 +153,7 @@
<Compile Include="Models\Declaration\MissionType.cs" />
<Compile Include="Models\SimulationComponent\Data\Engine\PT1Curve.cs" />
<Compile Include="Models\SimulationComponent\Data\GearFullLoadCurve.cs" />
<Compile Include="Models\Simulation\Cockpit\IMileageCounter.cs" />
<Compile Include="Models\Simulation\Impl\DistanceRun.cs" />
<Compile Include="Models\Simulation\Impl\PowertrainBuilder.cs" />
<Compile Include="Models\Simulation\Impl\TimeRun.cs" />
......
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.FileIO.Reader;
using TUGraz.VectoCore.FileIO.Reader.Impl;
using TUGraz.VectoCore.Models.Connector.Ports;
......@@ -22,7 +23,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
public const string CycleFile = @"TestData\Integration\MinimalPowerTrain\Coach_24t_xshort.vdri";
public const string EngineFile = @"TestData\Integration\MinimalPowerTrain\24t Coach.veng";
public const string AccelerationFile = @"TestData\Components\Truck.vacc";
public const string AccelerationFile = @"TestData\Components\Coach.vacc";
[TestMethod]
public void TestWheelsAndEngine()
......@@ -82,17 +83,27 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
Assert.IsInstanceOfType(response, typeof(ResponseSuccess));
vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval);
absTime += response.SimulationInterval;
gbx.CurrentGear = 1;
for (int i = 0; i < 10; i++) {
absTime += response.SimulationInterval;
response = cyclePort.Request(absTime, 1.SI<Meter>());
var ds = Constants.SimulationSettings.DriveOffDistance;
while (vehicleContainer.Distance().Value() < 825) {
response = cyclePort.Request(absTime, ds);
switch (response.ResponseType) {
case ResponseType.DrivingCycleDistanceExceeded:
var rsp = response as ResponseDrivingCycleDistanceExceeded;
ds = rsp.MaxDistance;
continue;
}
Assert.IsInstanceOfType(response, typeof(ResponseSuccess));
ds = vehicleContainer.VehicleSpeed().IsEqual(0)
? Constants.SimulationSettings.DriveOffDistance
: (Constants.SimulationSettings.TargetTimeInterval * vehicleContainer.VehicleSpeed()).Cast<Meter>();
vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval);
absTime += response.SimulationInterval;
}
modalWriter.Finish();
......
......@@ -182,8 +182,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
engineLoadPower = idlePower;
}
requestPort.Request(t, dt, Formulas.PowerToTorque(engineLoadPower, angularSpeed), angularSpeed);
modalData[ModalResultField.time] = t.Value();
modalData[ModalResultField.simulationInterval] = dt.Value();
modalData[ModalResultField.time] = t;
modalData[ModalResultField.simulationInterval] = dt;
engine.CommitSimulationStep(modalData);
// todo: compare results...
Assert.AreEqual(expectedResults.Rows[i].ParseDouble(0), t.Value(), 0.001, "Time");
......
......@@ -49,8 +49,8 @@ namespace TUGraz.VectoCore.Tests.Utils
public void CommitSimulationStep(Second absTime, Second simulationInterval)
{
CurrentRow[ModalResultField.time.GetName()] = (absTime + simulationInterval / 2).Value();
CurrentRow[ModalResultField.simulationInterval.GetName()] = simulationInterval.Value();
CurrentRow[ModalResultField.time.GetName()] = (absTime + simulationInterval / 2);
CurrentRow[ModalResultField.simulationInterval.GetName()] = simulationInterval;
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