Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

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

Merge branch 'feature/VECTO-112-simple-shifting-strategy' of...

Merge branch 'feature/VECTO-112-simple-shifting-strategy' of https://webgate.ec.europa.eu/CITnet/stash/scm/~emkrispmi/vecto-sim into feature/VECTO-116-refactor-driver-implementation
parents 7bb56450 f985fb32
Branches
Tags
No related merge requests found
Showing
with 212 additions and 207 deletions
using System.Collections.Generic;
using JetBrains.Annotations;
using Newtonsoft.Json;
using TUGraz.VectoCore.FileIO.DeclarationFile;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.FileIO.EngineeringFile
{
......@@ -62,31 +62,56 @@ namespace TUGraz.VectoCore.FileIO.EngineeringFile
[JsonProperty(Required = Required.Always)] public double Inertia;
/// <summary>
/// [s] Interruption during gear shift event
/// [s] Interruption time during gear shift event
/// </summary>
[JsonProperty("TracInt", Required = Required.Always)] public double TractionInterruption;
/// <summary>
/// [%] This parameter is required for the "Allow shift-up inside polygons" and "Skip Gears" option
/// [%] (0-1) Defines the torque reserve for EarlyUpShift and SkipGears in the Shifting Strategy.
/// </summary>
[JsonProperty("TqReserve")] public double TorqueReserve;
/// <remarks>Is serialized via the property <see cref="TorqueReserveConverterProperty"/>.</remarks>
public double TorqueReserve
{
get { return _torqueReserve; }
set { _torqueReserve = value; }
}
[JsonProperty("TqReserve"), UsedImplicitly]
private double TorqueReserveConverterProperty
{
get { return (int)_torqueReserve * 100; }
set { _torqueReserve = value / 100; }
}
[JsonProperty] public bool SkipGears;
/// <summary>
/// min. time interval between two gearshifts
/// [s] Minimum time interval between two gearshifts
/// </summary>
[JsonProperty] public double ShiftTime;
/// <summary>
/// ???
/// [true/false] true if earlyUpShift in Gearbox is active
/// </summary>
[JsonProperty] public bool EarlyShiftUp;
/// <summary>
/// ???
/// [%] (0-1) The start torque reserve for finding the starting gear.
/// </summary>
[JsonProperty("StartTqReserve")] public double StartTorqueReserve;
/// <remarks>Is serialized via the property <see cref="StartTorqueReserveConverterProperty"/>.</remarks>
public double StartTorqueReserve
{
get { return _startTorqueReserve; }
set { _startTorqueReserve = value; }
}
[JsonProperty("StartTqReserve"), UsedImplicitly]
private double StartTorqueReserveConverterProperty
{
get { return (int)_startTorqueReserve * 100; }
set { _startTorqueReserve = value / 100; }
}
/// <summary>
/// [m/s] vehicle speed at start
......@@ -98,11 +123,13 @@ namespace TUGraz.VectoCore.FileIO.EngineeringFile
/// </summary>
[JsonProperty("StartAcc")] public double StartAcceleration;
/// <summary>
/// Contains all parameters of the torque converter if used
/// </summary>
[JsonProperty] public TorqueConverterDataEng TorqueConverter;
private double _startTorqueReserve;
private double _torqueReserve;
}
public class GearDataEng : GearDataDecl
......
......@@ -195,7 +195,7 @@ namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
new GearData {
LossMap = gearLossMap,
ShiftPolygon = shiftPolygon,
FullLoadCurve = gearFullLoad,
FullLoadCurve = gearFullLoad ?? engine.FullLoadCurve,
Ratio = gear.Ratio,
TorqueConverterActive = false
});
......
using System;
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.Linq;
using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.FileIO.EngineeringFile;
using TUGraz.VectoCore.Models.Declaration;
......@@ -10,7 +7,6 @@ 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;
using TUGraz.VectoCore.Models.SimulationComponent.Impl;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
......@@ -45,7 +41,7 @@ namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
{
var fileV5Eng = gearbox as GearboxFileV5Engineering;
if (fileV5Eng != null) {
return CreateGearboxData(fileV5Eng);
return CreateGearboxData(fileV5Eng, engine);
}
throw new VectoException("Unsupported GearboxData File Instance");
}
......@@ -142,8 +138,9 @@ namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
/// Gearbox, File-format Version 4
/// </summary>
/// <param name="gearbox"></param>
/// <param name="engineData"></param>
/// <returns></returns>
internal GearboxData CreateGearboxData(GearboxFileV5Engineering gearbox)
internal GearboxData CreateGearboxData(GearboxFileV5Engineering gearbox, CombustionEngineData engineData)
{
var retVal = SetCommonGearboxData(gearbox.Body);
......@@ -161,22 +158,25 @@ namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
retVal.HasTorqueConverter = data.TorqueConverter.Enabled;
var engineFullLoadCurve = (engineData != null) ? engineData.FullLoadCurve : null;
for (uint i = 0; i < gearbox.Body.Gears.Count; i++) {
var gearSettings = gearbox.Body.Gears[(int)i];
var lossMapPath = Path.Combine(gearbox.BasePath, gearSettings.LossMap);
TransmissionLossMap lossMap = TransmissionLossMap.ReadFromFile(lossMapPath, gearSettings.Ratio);
var lossMap = TransmissionLossMap.ReadFromFile(lossMapPath, gearSettings.Ratio);
var shiftPolygon = !string.IsNullOrEmpty(gearSettings.ShiftPolygon)
? ShiftPolygon.ReadFromFile(Path.Combine(gearbox.BasePath, gearSettings.ShiftPolygon))
: null;
var fullLoad = !string.IsNullOrEmpty(gearSettings.FullLoadCurve) && !gearSettings.FullLoadCurve.Equals("<NOFILE>")
? FullLoadCurve.ReadFromFile(Path.Combine(gearbox.BasePath, gearSettings.FullLoadCurve))
: null;
var shiftPolygon = string.IsNullOrEmpty(gearSettings.ShiftPolygon)
? null
: ShiftPolygon.ReadFromFile(Path.Combine(gearbox.BasePath, gearSettings.ShiftPolygon));
var fullLoad = string.IsNullOrEmpty(gearSettings.FullLoadCurve) || gearSettings.FullLoadCurve.Equals("<NOFILE>")
? null
: FullLoadCurve.ReadFromFile(Path.Combine(gearbox.BasePath, gearSettings.FullLoadCurve));
var gear = new GearData {
LossMap = lossMap,
ShiftPolygon = shiftPolygon,
FullLoadCurve = fullLoad,
FullLoadCurve = fullLoad ?? engineFullLoadCurve,
Ratio = gearSettings.Ratio,
TorqueConverterActive = gearSettings.TCactive
};
......
......@@ -96,12 +96,13 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
}
var dao = new EngineeringDataAdapter();
var driver = dao.CreateDriverData(job);
var engineData = dao.CreateEngineData(Engine);
foreach (var cycle in job.Body.Cycles) {
var simulationRunData = new VectoRunData {
BasePath = job.BasePath,
JobFileName = job.JobFile,
EngineData = dao.CreateEngineData(Engine),
GearboxData = dao.CreateGearboxData(Gearbox, null),
EngineData = engineData,
GearboxData = dao.CreateGearboxData(Gearbox, engineData),
VehicleData = dao.CreateVehicleData(Vehicle),
DriverData = driver,
Aux = Aux,
......
......@@ -69,6 +69,6 @@ namespace TUGraz.VectoCore.Models.Connector.Ports
IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient);
IResponse Initialize(MeterPerSecond vehicleSpeed, MeterPerSquareSecond startAcceleration, Radian roadGradient);
IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient, MeterPerSquareSecond startAcceleration);
}
}
\ No newline at end of file
......@@ -178,8 +178,8 @@ namespace TUGraz.VectoCore.Models.Declaration
public static class Gearbox
{
public const double TorqueReserve = 20;
public const double TorqueReserveStart = 20;
public const double TorqueReserve = 0.2;
public const double TorqueReserveStart = 0.2;
public const double StartSpeed = 2;
public const double StartAcceleration = 0.6;
public const double Inertia = 0;
......
using System;
using System.Collections;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
......@@ -100,14 +101,24 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
protected IGearbox GetGearbox(VehicleContainer container, GearboxData data)
{
IShiftStrategy strategy;
switch (data.Type) {
case GearboxType.AMT:
strategy = new AMTShiftStrategy(data, container);
break;
case GearboxType.MT:
strategy = new MTShiftStrategy(data, container);
break;
case GearboxType.AT:
throw new VectoSimulationException("Unsupported Geabox type: Automatic Transmission (AT)");
strategy = new ATShiftStrategy(data, container);
break;
case GearboxType.Custom:
throw new VectoSimulationException("Custom Gearbox not supported");
strategy = new CustomShiftStrategy(data, container);
break;
default:
return new Gearbox(container, data);
throw new VectoSimulationException("Unknown Gearbox Type: {0}", data.Type);
}
return new Gearbox(container, data, strategy);
}
protected virtual IDriver AddComponent(IDrivingCycle prev, IDriver next)
......
......@@ -47,13 +47,25 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
[DebuggerHidden]
public MeterPerSecond StartSpeed
{
get { return Gearbox.StartSpeed; }
get
{
if (Gearbox == null) {
throw new VectoException("No Gearbox available. StartSpeed unkown");
}
return Gearbox.StartSpeed;
}
}
[DebuggerHidden]
public MeterPerSquareSecond StartAcceleration
{
get { return Gearbox.StartAcceleration; }
get
{
if (Gearbox == null) {
throw new VectoException("No Gearbox available. StartAcceleration unknown.");
}
return Gearbox.StartAcceleration;
}
}
#endregion
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Data
......@@ -17,43 +7,24 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
{
public string ModelName { get; internal set; }
/// <summary>
/// [m^3]
/// </summary>
public CubicMeter Displacement { get; internal set; }
/// <summary>
/// [rad/s]
/// </summary>
public PerSecond IdleSpeed { get; internal set; }
/// <summary>
/// [kgm^2]
/// </summary>
public KilogramSquareMeter Inertia { get; internal set; }
/// <summary>
/// [kg/Ws]
/// </summary>
public KilogramPerWattSecond WHTCUrban { get; internal set; }
/// <summary>
/// [kg/Ws]
/// </summary>
public KilogramPerWattSecond WHTCRural { get; internal set; }
/// <summary>
/// [kg/Ws]
/// </summary>
public KilogramPerWattSecond WHTCMotorway { get; internal set; }
public FuelConsumptionMap ConsumptionMap { get; internal set; }
public EngineFullLoadCurve FullLoadCurve { get; internal set; }
#region Equality Member
protected bool Equals(CombustionEngineData other)
{
return Equals(FullLoadCurve, other.FullLoadCurve) && string.Equals(ModelName, other.ModelName) &&
......@@ -91,77 +62,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
return hashCode;
}
}
public class RangeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return value.GetType() == typeof(string)
? new Range((string)value)
: base.ConvertFrom(context, culture, value);
}
}
[TypeConverter(typeof(RangeConverter))]
private class Range
{
private readonly uint _end;
private readonly uint _start;
public Range(string range)
{
Contract.Requires(range != null);
_start = uint.Parse(range.Split('-').First().Trim());
_end = uint.Parse(range.Split('-').Last().Trim());
}
public override string ToString()
{
return string.Format("{0} - {1}", _start, _end);
}
public bool Contains(uint value)
{
return _start <= value && value <= _end;
}
#region Equality members
protected bool Equals(Range other)
{
Contract.Requires(other != null);
return _start == other._start && _end == other._end;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != GetType()) {
return false;
}
return Equals((Range)obj);
}
public override int GetHashCode()
{
unchecked {
return (int)((_start * 397) ^ _end);
}
}
#endregion
}
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -25,12 +25,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
public Second TractionInterruption { get; internal set; }
/// <summary>
/// [%] (0-1)
/// [%] (0-1) The torque reserve for shift strategy (early upshift, skipgears)
/// </summary>
public double TorqueReserve { get; internal set; }
/// <summary>
/// used by gear-shift model
/// Indicates if gears can be skipped in Gear Shift Strategy.
/// </summary>
public bool SkipGears { get; internal set; }
......@@ -39,7 +39,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
public bool EarlyShiftUp { get; internal set; }
/// <summary>
/// [%] (0-1)
/// [%] (0-1) The starting torque reserve for finding the starting gear after standstill.
/// </summary>
public double StartTorqueReserve { get; internal set; }
......
......@@ -3,6 +3,9 @@ using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent
{
/// <summary>
/// Interface for the ShiftStrategy. Decides when to shift and which gear to take.
/// </summary>
public interface IShiftStrategy
{
/// <summary>
......@@ -15,7 +18,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent
bool ShiftRequired(uint gear, NewtonMeter torque, PerSecond angularSpeed);
/// <summary>
/// Returns an appropriate starting gear.
/// Returns an appropriate starting gear after a vehicle standstill.
/// </summary>
/// <param name="absTime">The abs time.</param>
/// <param name="dt">The dt.</param>
......@@ -25,7 +28,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent
uint InitGear(Second absTime, Second dt, NewtonMeter torque, PerSecond outEngineSpeed);
/// <summary>
/// Engages a gear
/// Engages a gear.
/// </summary>
/// <param name="absTime">The abs time.</param>
/// <param name="dt">The dt.</param>
......
......@@ -189,8 +189,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
CurrentState = PreviousState.Clone();
if (CycleIntervalIterator.LeftSample.VehicleTargetSpeed.IsEqual(0)) {
var retVal = NextComponent.Initialize(DataBus.StartSpeed, DataBus.StartAcceleration,
CycleIntervalIterator.LeftSample.RoadGradient);
var retVal = NextComponent.Initialize(DataBus.StartSpeed,
CycleIntervalIterator.LeftSample.RoadGradient, DataBus.StartAcceleration);
if (!(retVal is ResponseSuccess)) {
throw new UnexpectedResponseException("Couldn't find start gear.", retVal);
}
......
......@@ -62,7 +62,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return NextComponent.Initialize(vehicleSpeed, roadGradient);
}
public IResponse Initialize(MeterPerSecond vehicleSpeed, MeterPerSquareSecond startAcceleration, Radian roadGradient)
public IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient, MeterPerSquareSecond startAcceleration)
{
VehicleStopped = vehicleSpeed.IsEqual(0);
var retVal = NextComponent.Initialize(vehicleSpeed, startAcceleration, roadGradient);
......@@ -76,8 +76,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
VehicleStopped = false;
Log.Debug("==== DRIVER Request ====");
Log.Debug(
"Request: absTime: {0}, ds: {1}, targetVelocity: {2}, gradient: {3} | distance: {4}, velocity: {5} gear: {6}, vehicle stopped: {7}",
absTime, ds, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed, DataBus.Gear, VehicleStopped);
"Request: absTime: {0}, ds: {1}, targetVelocity: {2}, gradient: {3} | distance: {4}, velocity: {5}, vehicle stopped: {7}",
absTime, ds, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed, VehicleStopped);
var retVal = DriverStrategy.Request(absTime, ds, targetVelocity, gradient);
//DoHandleRequest(absTime, ds, targetVelocity, gradient);
......
......@@ -55,15 +55,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public bool ClutchClosed(Second absTime)
{
return _shiftTime.IsSmaller(absTime);
return _shiftTime.IsSmallerOrEqual(absTime);
}
public Gearbox(IVehicleContainer container, GearboxData gearboxData, IShiftStrategy strategy = null) : base(container)
public Gearbox(IVehicleContainer container, GearboxData gearboxData, IShiftStrategy strategy) : base(container)
{
// TODO: do not set a default strategy! gearbox should be called with explicit shift strategy! this is just for debug
if (strategy == null) {
strategy = new AMTShiftStrategy(gearboxData, container);
}
Data = gearboxData;
_strategy = strategy;
_strategy.Gearbox = this;
......@@ -311,7 +307,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
if (!outEngineSpeed.IsEqual(0)) {
var isShiftAllowed = (_shiftTime + Data.ShiftTime).IsSmaller(absTime);
var isShiftAllowed = (_shiftTime + Data.ShiftTime).IsSmallerOrEqual(absTime);
if (isShiftAllowed && _strategy.ShiftRequired(Gear, inTorque, inEngineSpeed)) {
_shiftTime = absTime + Data.TractionInterruption;
......
......@@ -7,9 +7,6 @@ using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
// TODO:
// * EarlyUpshift (shift before outside of up-shift curve if outTorque reserve for the next higher gear is fullfilled)
public abstract class ShiftStrategy : IShiftStrategy
{
protected IDataBus DataBus;
......@@ -31,7 +28,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
/// <summary>
/// Tests if the gearbox should shift down.
/// Tests if the operating point is below the down-shift curve (=outside of shift curve).
/// </summary>
protected virtual bool IsBelowDownShiftCurve(uint gear, NewtonMeter inTorque, PerSecond inEngineSpeed)
{
......@@ -44,7 +41,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}
/// <summary>
/// Tests if the gearbox should shift up.
/// Tests if the gearbox is above the up-shift curve (=outside of shift curve).
/// </summary>
protected virtual bool IsAboveUpShiftCurve(uint gear, NewtonMeter inTorque, PerSecond inEngineSpeed)
{
......@@ -59,23 +56,33 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
/// <summary>
/// Tests if current power request is left or right of the shiftpolygon segment
/// </summary>
protected static bool IsOnLeftSide(PerSecond angularSpeed, NewtonMeter torque, ShiftPolygon.ShiftPolygonEntry from,
/// <remarks>
/// Computes a simplified cross product for the vectors: from-->X, from-->to and checks
/// if the z-component is positive (which means that X was on the right side of from-->to).
/// </remarks>
private static bool IsOnLeftSide(PerSecond angularSpeed, NewtonMeter torque, ShiftPolygon.ShiftPolygonEntry from,
ShiftPolygon.ShiftPolygonEntry to)
{
var ab = new { X = to.AngularSpeed - from.AngularSpeed, Y = to.Torque - from.Torque };
var ac = new { X = angularSpeed - from.AngularSpeed, Y = torque - from.Torque };
return (ab.X * ac.Y - ab.Y * ac.X).IsGreater(0);
var z = ab.X * ac.Y - ab.Y * ac.X;
return z.IsGreater(0);
}
/// <summary>
/// Tests if current power request is left or right of the shiftpolygon segment
/// </summary>
protected static bool IsOnRightSide(PerSecond angularSpeed, NewtonMeter torque, ShiftPolygon.ShiftPolygonEntry from,
/// <remarks>
/// Computes a simplified cross product for the vectors: from-->X, from-->to and checks
/// if the z-component is negative (which means that X was on the left side of from-->to).
/// </remarks>
private static bool IsOnRightSide(PerSecond angularSpeed, NewtonMeter torque, ShiftPolygon.ShiftPolygonEntry from,
ShiftPolygon.ShiftPolygonEntry to)
{
var ab = new { X = to.AngularSpeed - from.AngularSpeed, Y = to.Torque - from.Torque };
var ac = new { X = angularSpeed - from.AngularSpeed, Y = torque - from.Torque };
return (ab.X * ac.Y - ab.Y * ac.X).IsSmaller(0);
var z = ab.X * ac.Y - ab.Y * ac.X;
return z.IsSmaller(0);
}
}
......@@ -111,7 +118,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var inAngularSpeed = outEngineSpeed * Data.Gears[gear].Ratio;
var inTorque = currentPower / inAngularSpeed;
if (!IsBelowDownShiftCurve(gear, inTorque, inAngularSpeed) && reserve >= torqueReserve / 100) {
if (!IsBelowDownShiftCurve(gear, inTorque, inAngularSpeed) && reserve >= torqueReserve) {
return gear;
}
}
......@@ -130,6 +137,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public override bool ShiftRequired(uint gear, NewtonMeter torque, PerSecond angularSpeed)
{
// todo: early upshift
return IsBelowDownShiftCurve(gear, torque, angularSpeed) || IsAboveUpShiftCurve(gear, torque, angularSpeed);
}
......@@ -139,7 +147,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
for (var gear = (uint)Data.Gears.Count; gear > 1; gear--) {
var inAngularSpeed = outEngineSpeed * Data.Gears[gear].Ratio;
if (inAngularSpeed > Data.Gears[gear].FullLoadCurve.RatedSpeed) {
if (inAngularSpeed > Data.Gears[gear].FullLoadCurve.RatedSpeed || inAngularSpeed.IsEqual(0)) {
continue;
}
......@@ -151,13 +159,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var fullLoadPower = currentPower - response.DeltaFullLoad;
var reserve = 1 - (currentPower / fullLoadPower).Cast<Scalar>();
// if in shift curve and above idle speed and torque reserve is provided.
if (!IsBelowDownShiftCurve(gear, inTorque, inAngularSpeed) && inAngularSpeed > DataBus.EngineIdleSpeed &&
reserve >= Data.StartTorqueReserve / 100) {
reserve >= Data.StartTorqueReserve) {
return gear;
}
}
return 1;
}
} else {
for (var gear = (uint)Data.Gears.Count; gear > 1; gear--) {
var response = Gearbox.Initialize(gear, outTorque, outEngineSpeed);
......@@ -168,20 +177,25 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var fullLoadPower = currentPower - response.DeltaFullLoad;
var reserve = 1 - (currentPower / fullLoadPower).Cast<Scalar>();
// if in shift curve and torque reserve is provided: return the current gear
if (!IsBelowDownShiftCurve(gear, inTorque, inAngularSpeed) && !IsAboveUpShiftCurve(gear, inTorque, inAngularSpeed) &&
reserve >= Data.StartTorqueReserve / 100) {
reserve >= Data.StartTorqueReserve) {
return gear;
}
// if over the up shift curve: return the previous gear (even thou it did not provide the required torque reserve)
if (IsAboveUpShiftCurve(gear, inTorque, inAngularSpeed) && gear < Data.Gears.Count) {
return gear + 1;
}
}
}
// fallback: return first gear
return 1;
}
}
//TODO Implementd MTShiftStrategy
//TODO Implement MTShiftStrategy
public class MTShiftStrategy : ShiftStrategy
{
public MTShiftStrategy(GearboxData data, IDataBus bus) : base(data, bus) {}
......@@ -232,4 +246,30 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
throw new System.NotImplementedException();
}
}
// TODO Implement CustomShiftStrategy
public class CustomShiftStrategy : ShiftStrategy
{
public CustomShiftStrategy(GearboxData data, IDataBus dataBus) : base(data, dataBus) {}
public override uint InitGear(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outEngineSpeed)
{
throw new NotImplementedException();
}
public override uint Engage(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outEngineSpeed)
{
throw new NotImplementedException();
}
public override void Disengage(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outEngineSpeed)
{
throw new NotImplementedException();
}
public override bool ShiftRequired(uint gear, NewtonMeter torque, PerSecond angularSpeed)
{
throw new NotImplementedException();
}
}
}
\ No newline at end of file
......@@ -978,7 +978,7 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy
tmp = Port.AddComponent(tmp, new Wheels(container, vehicleData.DynamicTyreRadius));
tmp = Port.AddComponent(tmp, new Brakes(container));
tmp = Port.AddComponent(tmp, new AxleGear(container, axleGearData));
tmp = Port.AddComponent(tmp, new Gearbox(container, gearboxData));
tmp = Port.AddComponent(tmp, new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)));
tmp = Port.AddComponent(tmp, new Clutch(container, engineData));
var aux = new Auxiliary(container);
......@@ -1011,6 +1011,9 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy
ShiftTime = 2.SI<Second>(),
Inertia = 0.SI<KilogramSquareMeter>(),
TractionInterruption = 1.SI<Second>(),
StartSpeed = 2.SI<MeterPerSecond>(),
StartAcceleration = 0.6.SI<MeterPerSquareSecond>(),
StartTorqueReserve = 0.2
};
}
......
......@@ -56,7 +56,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
tmp = Port.AddComponent(tmp, new Wheels(container, vehicleData.DynamicTyreRadius));
tmp = Port.AddComponent(tmp, new Brakes(container));
tmp = Port.AddComponent(tmp, new AxleGear(container, axleGearData));
var gbx = new Gearbox(container, gearboxData);
var gbx = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container));
tmp = Port.AddComponent(tmp, gbx);
tmp = Port.AddComponent(tmp, new Clutch(container, engineData));
Port.AddComponent(tmp, new CombustionEngine(container, engineData));
......@@ -112,7 +112,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
tmp = Port.AddComponent(tmp, new Wheels(container, vehicleData.DynamicTyreRadius));
tmp = Port.AddComponent(tmp, new Brakes(container));
tmp = Port.AddComponent(tmp, new AxleGear(container, axleGearData));
var gbx = new Gearbox(container, gearboxData);
var gbx = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container));
tmp = Port.AddComponent(tmp, gbx);
tmp = Port.AddComponent(tmp, new Clutch(container, engineData));
Port.AddComponent(tmp, new CombustionEngine(container, engineData));
......@@ -185,7 +185,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
tmp = Port.AddComponent(tmp, new Wheels(container, vehicleData.DynamicTyreRadius));
tmp = Port.AddComponent(tmp, new Brakes(container));
tmp = Port.AddComponent(tmp, new AxleGear(container, axleGearData));
tmp = Port.AddComponent(tmp, new Gearbox(container, gearboxData));
tmp = Port.AddComponent(tmp, new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)));
tmp = Port.AddComponent(tmp, new Clutch(container, engineData));
Port.AddComponent(tmp, new CombustionEngine(container, engineData));
......@@ -274,6 +274,10 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
ShiftTime = 2.SI<Second>(),
Inertia = 0.SI<KilogramSquareMeter>(),
TractionInterruption = 1.SI<Second>(),
StartSpeed = 2.SI<MeterPerSecond>(),
StartAcceleration = 0.6.SI<MeterPerSquareSecond>(),
StartTorqueReserve = 0.2,
TorqueReserve = 0.2
};
}
......@@ -303,7 +307,11 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
},
Inertia = 0.SI<KilogramSquareMeter>(),
TractionInterruption = 0.SI<Second>(),
ShiftTime = 2.SI<Second>()
ShiftTime = 2.SI<Second>(),
StartSpeed = 2.SI<MeterPerSecond>(),
StartAcceleration = 0.6.SI<MeterPerSquareSecond>(),
StartTorqueReserve = 0.2,
TorqueReserve = 0.2
};
}
......@@ -353,6 +361,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
AccelerationCurve = AccelerationCurveData.ReadFromFile(accelerationFile),
LookAheadCoasting = new DriverData.LACData {
Enabled = false,
Deceleration = -0.5.SI<MeterPerSquareSecond>()
},
OverSpeedEcoRoll = new DriverData.OverSpeedEcoRollData {
Mode = DriverData.DriverMode.Off
......
......@@ -262,6 +262,7 @@ namespace TUGraz.VectoCore.Tests.Integration.SimulationRuns
AccelerationCurve = AccelerationCurveData.ReadFromFile(accelerationFile),
LookAheadCoasting = new DriverData.LACData {
Enabled = false,
Deceleration = -0.5.SI<MeterPerSquareSecond>()
},
OverSpeedEcoRoll = new DriverData.OverSpeedEcoRollData {
Mode = DriverData.DriverMode.Off
......
......@@ -18,11 +18,11 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
[TestMethod]
public void TestClutch()
{
var vehicle = new VehicleContainer();
var container = new VehicleContainer();
var engineData = EngineeringModeSimulationDataReader.CreateEngineDataFromFile(CoachEngine);
var gearbox = new MockGearbox(vehicle);
var gearbox = new MockGearbox(container);
var clutch = new Clutch(vehicle, engineData);
var clutch = new Clutch(container, engineData);
var inPort = clutch.InPort();
var outPort = new MockTnOutPort();
......@@ -31,9 +31,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
var clutchOutPort = clutch.OutPort();
//Test - Clutch slipping
gearbox.Gear = 1;
var driver = new MockDriver(container);
//Test - Clutch slipping
clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), 100.SI<NewtonMeter>(), 0.SI<PerSecond>());
Assert.AreEqual(0, outPort.Torque.Value(), 0.001);
......@@ -45,14 +45,14 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
Assert.AreEqual(62.119969, outPort.AngularVelocity.Value(), 0.001);
//Test - Clutch opened
gearbox.Gear = 0;
driver.VehicleStopped = true;
clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), 100.SI<NewtonMeter>(), 30.SI<PerSecond>());
Assert.AreEqual(0, outPort.Torque.Value(), 0.001);
Assert.AreEqual(engineData.IdleSpeed.Value(), outPort.AngularVelocity.Value(), 0.001);
//Test - Clutch closed
gearbox.Gear = 1;
driver.VehicleStopped = false;
clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), 100.SI<NewtonMeter>(), 80.SI<PerSecond>());
Assert.AreEqual(100.0, outPort.Torque.Value(), 0.001);
......
......@@ -201,14 +201,16 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
[TestMethod]
public void EngineIdleJump()
{
var vehicleContainer = new VehicleContainer();
var gearbox = new MockGearbox(vehicleContainer);
var container = new VehicleContainer();
var gearbox = new MockGearbox(container);
var engineData = EngineeringModeSimulationDataReader.CreateEngineDataFromFile(CoachEngine);
var engine = new CombustionEngine(vehicleContainer, engineData);
var engine = new CombustionEngine(container, engineData);
var clutch = new Clutch(container, engineData);
var clutch = new Clutch(vehicleContainer, engineData);
var driver = new MockDriver(container);
var aux = new Auxiliary(vehicleContainer);
var aux = new Auxiliary(container);
aux.AddConstant("", 5000.SI<Watt>());
gearbox.Gear = 1;
......@@ -224,7 +226,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
//vehicleContainer.DataWriter = new ModalDataWriter("engine_idle_test.csv");
var dataWriter = new MockModalDataWriter();
vehicleContainer.DataWriter = dataWriter;
container.DataWriter = dataWriter;
var torque = 1200.SI<NewtonMeter>();
var angularVelocity = 800.RPMtoRad();
......@@ -239,7 +241,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
var response = requestPort.Request(absTime, dt, torque, angularVelocity);
Assert.IsInstanceOfType(response, typeof(ResponseSuccess));
vehicleContainer.CommitSimulationStep(absTime, dt);
container.CommitSimulationStep(absTime, dt);
var row = dataWriter.Data.Rows.Cast<DataRow>().Last();
Assert.AreEqual(105530.96491487339.SI<Watt>(), row[ModalResultField.Pe_eng.GetName()]);
Assert.AreEqual(5000.SI<Watt>(), row[ModalResultField.Paux.GetName()]);
......@@ -255,7 +257,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
response = gearbox.Request(absTime, dt, torque, angularVelocity);
Assert.IsInstanceOfType(response, typeof(ResponseSuccess));
vehicleContainer.CommitSimulationStep(absTime, dt);
container.CommitSimulationStep(absTime, dt);
row = dataWriter.Data.Rows.Cast<DataRow>().Last();
Assert.AreEqual(5000.SI<Watt>(), row[ModalResultField.Pe_eng.GetName()]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment