diff --git a/VECTO/app.config b/VECTO/app.config index 7ae650822fdef20ec280fc4c705f5f4970bd7f63..96e61fb67a97a48111dc6b6283bd4e4bf6928593 100644 --- a/VECTO/app.config +++ b/VECTO/app.config @@ -18,7 +18,7 @@ </targets> <rules> <logger name="*" minlevel="Warn" writeTo="LogFile" /> - <logger name="*" minlevel="Warn" writeTo="WarningLogger" /> + <logger name="*" minlevel="Error" writeTo="WarningLogger" /> </rules> </nlog> <system.diagnostics> diff --git a/VECTO/mAAUX_Global.vb b/VECTO/mAAUX_Global.vb index 1deed0f8a7e14673d4f1e6af32915252d0dafdee..1eb3e26e569b7043e27eff5c55ea4c974d61b591 100644 --- a/VECTO/mAAUX_Global.vb +++ b/VECTO/mAAUX_Global.vb @@ -7,7 +7,7 @@ Module mAAUX_Global Public EngineDrivelinePower As Single Public EngineDrivelineTorque As Single Public EngineMotoringPower As Single - Public EngineSpeed As Integer + Public EngineSpeed As Single Public PreExistingAuxPower As Single Public Idle As Boolean Public InNeutral As Boolean diff --git a/VECTOAux/VectoAuxiliaries/DownstreamModules/M11.vb b/VECTOAux/VectoAuxiliaries/DownstreamModules/M11.vb index 22f80edd6bb1787ec16437726c4d18934a9dc9a1..8c500f704b3423831f08b4d2d4ca3ab1821e0a77 100644 --- a/VECTOAux/VectoAuxiliaries/DownstreamModules/M11.vb +++ b/VECTOAux/VectoAuxiliaries/DownstreamModules/M11.vb @@ -116,7 +116,7 @@ Namespace DownstreamModules Private ReadOnly Property Sum10 As Single Get - Return M6.AvgPowerDemandAtCrankFromElectricsIncHVAC \ Sum0(signals.EngineSpeed) + Return M6.AvgPowerDemandAtCrankFromElectricsIncHVAC / Sum0(signals.EngineSpeed) End Get End Property diff --git a/VECTOAux/VectoAuxiliaries/DownstreamModules/M8.vb b/VECTOAux/VectoAuxiliaries/DownstreamModules/M8.vb index 9af3bf48c12e614bc56e52e5186501e31f893f39..20019383d0a50cd3c8e5fc65a17ab1e2dd1bbdcc 100644 --- a/VECTOAux/VectoAuxiliaries/DownstreamModules/M8.vb +++ b/VECTOAux/VectoAuxiliaries/DownstreamModules/M8.vb @@ -15,118 +15,129 @@ Imports VectoAuxiliaries.Pneumatics Imports VectoAuxiliaries.Hvac Namespace DownstreamModules + Public Class M8 + Implements IM8 - Public Class M8 - Implements IM8 - - #Region "Private Fields" - - private _m1 As IM1_AverageHVACLoadDemand - private _m6 As IM6 - private _m7 As IM7 - private _signals As ISignals - - #End Region - - #Region "Internal Sums and Switches" - - 'Internal Staged Sums and Switches - private ReadOnly Property Sum1 As Single - Get - Return _m7.SmartElectricalAndPneumaticAuxAltPowerGenAtCrank + _m7.SmartElectricalAndPneumaticAuxAirCompPowerGenAtCrank - End Get -End Property - private ReadOnly Property Sum2 As Single - Get - Return _m7.SmartElectricalOnlyAuxAltPowerGenAtCrank +_m6.AveragePowerDemandAtCrankFromPneumatics - End Get -End Property - private ReadOnly Property Sum3 As Single - Get - Return _m7.SmartPneumaticOnlyAuxAirCompPowerGenAtCrank + _m6.AvgPowerDemandAtCrankFromElectricsIncHVAC - End Get -End Property - private ReadOnly Property Sum4 As Single - Get - Return _m6.AvgPowerDemandAtCrankFromElectricsIncHVAC + _m6.AveragePowerDemandAtCrankFromPneumatics - End Get -End Property - private ReadOnly Property Sum5 As Single - Get - Return _m1.AveragePowerDemandAtCrankFromHVACMechanicalsWatts + SW5 - End Get -End Property - Private ReadOnly Property Sum6 As Single - Get - Return Sum5 * SW6 - End Get - End Property - Private ReadOnly Property SW1 As Single - Get - Return If( _signals.SmartPneumatics, Sum1, Sum2) - End Get - End Property - Private ReadOnly Property SW2 As Single - Get - Return If( _signals.SmartPneumatics,Sum3,Sum4) - End Get -End Property - Private ReadOnly Property SW3 As Single - Get - Return If(_signals.SmartPneumatics,_m7.SmartElectricalAndPneumaticAuxAltPowerGenAtCrank,_m7.SmartElectricalOnlyAuxAltPowerGenAtCrank) - End Get -End Property - Private ReadOnly Property SW4 As integer - Get - Return If( _signals.SmartElectrics,_m6.SmartElecAndPneumaticsCompressorFlag,_m6.SmartPneumaticsOnlyCompressorFlag) - End Get -End Property - Private ReadOnly Property SW5 As Single - Get - Return If( _signals.SmartElectrics,SW1,SW2) - End Get - End Property - Private ReadOnly Property SW6 As Single - Get - Return If(_signals.EngineStopped, 0 , 1) - End Get - End Property +#Region "Private Fields" + + Private _m1 As IM1_AverageHVACLoadDemand + Private _m6 As IM6 + Private _m7 As IM7 + Private _signals As ISignals #End Region - - 'OUT1 - Public ReadOnly Property AuxPowerAtCrankFromElectricalHVACAndPneumaticsAncillaries As Single Implements IM8.AuxPowerAtCrankFromElectricalHVACAndPneumaticsAncillaries - Get - Return Sum6 - End Get - End Property - 'OUT2 - Public ReadOnly Property SmartElectricalAlternatorPowerGenAtCrank As Single Implements IM8.SmartElectricalAlternatorPowerGenAtCrank - Get - Return SW3 - End Get - End Property - 'OUT3 - Public ReadOnly Property CompressorFlag As Integer Implements IM8.CompressorFlag - Get - Return SW4 - End Get - End Property - - 'Constructor - Public Sub new( m1 As IM1_AverageHVACLoadDemand, m6 As IM6, m7 As IM7, signals As ISignals) - - _m1=m1 - _m6=m6 - _m7=m7 - _signals=signals - - End Sub - - -End Class -End Namespace +#Region "Internal Sums and Switches" + + 'Internal Staged Sums and Switches + Private ReadOnly Property Sum1 As Single + Get + Return _ + _m7.SmartElectricalAndPneumaticAuxAltPowerGenAtCrank + _m7.SmartElectricalAndPneumaticAuxAirCompPowerGenAtCrank + End Get + End Property + + Private ReadOnly Property Sum2 As Single + Get + Return _m7.SmartElectricalOnlyAuxAltPowerGenAtCrank + _m6.AveragePowerDemandAtCrankFromPneumatics + End Get + End Property + + Private ReadOnly Property Sum3 As Single + Get + Return _m7.SmartPneumaticOnlyAuxAirCompPowerGenAtCrank + _m6.AvgPowerDemandAtCrankFromElectricsIncHVAC + End Get + End Property + + Private ReadOnly Property Sum4 As Single + Get + Return _m6.AvgPowerDemandAtCrankFromElectricsIncHVAC + _m6.AveragePowerDemandAtCrankFromPneumatics + End Get + End Property + + Private ReadOnly Property Sum5 As Single + Get + Return _m1.AveragePowerDemandAtCrankFromHVACMechanicalsWatts + SW5 + End Get + End Property + + Private ReadOnly Property Sum6 As Single + Get + Return Sum5 * SW6 + End Get + End Property + + Private ReadOnly Property SW1 As Single + Get + Return If(_signals.SmartPneumatics, Sum1, Sum2) + End Get + End Property + + Private ReadOnly Property SW2 As Single + Get + Return If(_signals.SmartPneumatics, Sum3, Sum4) + End Get + End Property + + Private ReadOnly Property SW3 As Single + Get + Return _ + If _ + (_signals.SmartPneumatics, _m7.SmartElectricalAndPneumaticAuxAltPowerGenAtCrank, + _m7.SmartElectricalOnlyAuxAltPowerGenAtCrank) + End Get + End Property + + Private ReadOnly Property SW4 As Integer + Get + Return If(_signals.SmartElectrics, _m6.SmartElecAndPneumaticsCompressorFlag, _m6.SmartPneumaticsOnlyCompressorFlag) + End Get + End Property + + Private ReadOnly Property SW5 As Single + Get + Return If(_signals.SmartElectrics, SW1, SW2) + End Get + End Property + + Private ReadOnly Property SW6 As Single + Get + Return If(_signals.EngineStopped, 0, 1) + End Get + End Property +#End Region + + 'OUT1 + Public ReadOnly Property AuxPowerAtCrankFromElectricalHVACAndPneumaticsAncillaries As Single _ + Implements IM8.AuxPowerAtCrankFromElectricalHVACAndPneumaticsAncillaries + Get + Return Sum6 + End Get + End Property + 'OUT2 + Public ReadOnly Property SmartElectricalAlternatorPowerGenAtCrank As Single _ + Implements IM8.SmartElectricalAlternatorPowerGenAtCrank + Get + Return SW3 + End Get + End Property + 'OUT3 + Public ReadOnly Property CompressorFlag As Integer Implements IM8.CompressorFlag + Get + Return SW4 + End Get + End Property + + 'Constructor + Public Sub New(m1 As IM1_AverageHVACLoadDemand, m6 As IM6, m7 As IM7, signals As ISignals) + + _m1 = m1 + _m6 = m6 + _m7 = m7 + _signals = signals + End Sub + End Class +End Namespace diff --git a/VECTOAux/VectoAuxiliaries/Pneumatics/CompressorMap.vb b/VECTOAux/VectoAuxiliaries/Pneumatics/CompressorMap.vb index a8d2ef5100f68076ae67d15216cf064eeebe80b0..1e88f01bcd04240967debdf0125bf5708bf3218b 100644 --- a/VECTOAux/VectoAuxiliaries/Pneumatics/CompressorMap.vb +++ b/VECTOAux/VectoAuxiliaries/Pneumatics/CompressorMap.vb @@ -108,7 +108,7 @@ Namespace Pneumatics ''' <param name="rpm">compressor rotation speed</param> ''' <returns></returns> ''' <remarks>Single</remarks> - Public Function GetFlowRate(ByVal rpm As Integer) As Single Implements ICompressorMap.GetFlowRate + Public Function GetFlowRate(ByVal rpm As Double) As Single Implements ICompressorMap.GetFlowRate Dim val As CompressorMapValues = InterpolatedTuple(rpm) Return val.FlowRate End Function @@ -119,7 +119,7 @@ Namespace Pneumatics ''' <param name="rpm">compressor rotation speed</param> ''' <returns></returns> ''' <remarks>Single</remarks> - Public Function GetPowerCompressorOn(ByVal rpm As Integer) As Single Implements ICompressorMap.GetPowerCompressorOn + Public Function GetPowerCompressorOn(ByVal rpm As Double) As Single Implements ICompressorMap.GetPowerCompressorOn Dim val As CompressorMapValues = InterpolatedTuple(rpm) Return val.PowerCompressorOn End Function @@ -130,7 +130,7 @@ Namespace Pneumatics ''' <param name="rpm">compressor rotation speed</param> ''' <returns></returns> ''' <remarks>Single</remarks> - Public Function GetPowerCompressorOff(ByVal rpm As Integer) As Single Implements ICompressorMap.GetPowerCompressorOff + Public Function GetPowerCompressorOff(ByVal rpm As Double) As Single Implements ICompressorMap.GetPowerCompressorOff Dim val As CompressorMapValues = InterpolatedTuple(rpm) Return val.PowerCompressorOff End Function @@ -140,7 +140,7 @@ Namespace Pneumatics ''' </summary> ''' <returns>CompressorMapValues</returns> ''' <remarks>Throws exception if rpm are outside map</remarks> - Private Function InterpolatedTuple(ByVal rpm As Integer) As CompressorMapValues + Private Function InterpolatedTuple(ByVal rpm As Double) As CompressorMapValues 'check the rpm is within the map Dim min As Integer = map.Keys.Min() Dim max As Integer = map.Keys.Max() diff --git a/VECTOAux/VectoAuxiliaries/Pneumatics/ICompressorMap.vb b/VECTOAux/VectoAuxiliaries/Pneumatics/ICompressorMap.vb index 683312eb845076a6a377d5b9427d903f63c120f3..914a00a2a66656d2da3c633cdf4c39b92371f614 100644 --- a/VECTOAux/VectoAuxiliaries/Pneumatics/ICompressorMap.vb +++ b/VECTOAux/VectoAuxiliaries/Pneumatics/ICompressorMap.vb @@ -26,23 +26,23 @@ Namespace Pneumatics ''' <param name="rpm">compressor rotation speed</param> ''' <returns></returns> ''' <remarks>Single</remarks> - Function GetFlowRate(ByVal rpm As Integer) As Single - - ''' <summary> - ''' Returns mechanical power at rpm when compressor is on - ''' </summary> - ''' <param name="rpm">compressor rotation speed</param> - ''' <returns></returns> - ''' <remarks>Single</remarks> - Function GetPowerCompressorOn(ByVal rpm As Integer) As Single - - ''' <summary> - ''' Returns mechanical power at rpm when compressor is off - ''' </summary> - ''' <param name="rpm">compressor rotation speed</param> - ''' <returns></returns> - ''' <remarks>Single</remarks> - Function GetPowerCompressorOff(ByVal rpm As Integer) As Single + Function GetFlowRate(ByVal rpm As Double) As Single + + ''' <summary> + ''' Returns mechanical power at rpm when compressor is on + ''' </summary> + ''' <param name="rpm">compressor rotation speed</param> + ''' <returns></returns> + ''' <remarks>Single</remarks> + Function GetPowerCompressorOn(ByVal rpm As Double) As Single + + ''' <summary> + ''' Returns mechanical power at rpm when compressor is off + ''' </summary> + ''' <param name="rpm">compressor rotation speed</param> + ''' <returns></returns> + ''' <remarks>Single</remarks> + Function GetPowerCompressorOff(ByVal rpm As Double) As Single 'Returns Average Power Demand Per Compressor Unit FlowRate Function GetAveragePowerDemandPerCompressorUnitFlowRate() As Single diff --git a/VECTOAux/VectoAuxiliaries/Pneumatics/M4_AirCompressor.vb b/VECTOAux/VectoAuxiliaries/Pneumatics/M4_AirCompressor.vb index db87a9f6f987dca77d5daf3658f412257cd95f9b..450caa370b8fae389587adea39fd5a68dd8f1450 100644 --- a/VECTOAux/VectoAuxiliaries/Pneumatics/M4_AirCompressor.vb +++ b/VECTOAux/VectoAuxiliaries/Pneumatics/M4_AirCompressor.vb @@ -10,168 +10,164 @@ ' See the LICENSE.txt for the specific language governing permissions and limitations. Namespace Pneumatics - - - Public Class M4_AirCompressor - - Implements IM4_AirCompressor - - Private Const MinRatio As Single = 1 - Private Const MaxRatio As Single = 10 - Private Const MinEff As Single = 0 - Private Const MaxEff As Single = 1 - - Private _pulleyGearRatio As Single - Private _pulleyGearEfficiency As Single - Private _map As ICompressorMap - Private _signals As ISignals - - - ''' <summary> - ''' Ratio of Gear or Pulley used to drive the compressor - ''' </summary> - ''' <value></value> - ''' <returns></returns> - ''' <remarks></remarks> - Public Property PulleyGearRatio() As Single Implements IM4_AirCompressor.PulleyGearRatio - Get - Return _pulleyGearRatio - End Get - Set(value As Single) - If (value < MinRatio OrElse value > MaxRatio) Then - Throw New ArgumentOutOfRangeException(String.Format("Invalid value, should be in the range {0} to {1}", MinRatio, MaxRatio), value) - Else - _pulleyGearRatio = value - End If - End Set - End Property - - ''' <summary> - ''' Efficiency of the Pulley or Gear used to drive the compressor - ''' </summary> - ''' <value></value> - ''' <returns></returns> - ''' <remarks></remarks> - Public Property PulleyGearEfficiency() As Single Implements IM4_AirCompressor.PulleyGearEfficiency - Get - Return _pulleyGearEfficiency - End Get - Set(value As Single) - If (value < MinEff OrElse value > MaxEff) Then - Throw New ArgumentOutOfRangeException(String.Format("Invalid value, should be in the range {0} to {1}", MinEff, MaxEff), value) - Else - _pulleyGearEfficiency = value - End If - End Set - End Property - - - '''<summary> - ''' Creates a new instance of the AirCompressor Class - ''' </summary> - ''' <param name="map">map of compressor values against compressor rpm</param> - ''' <param name="pulleyGearRatio">Ratio of Pulley/Gear</param> - ''' <param name="pulleyGearEfficiency">Efficiency of Pulley/Gear</param> - ''' <remarks></remarks> - Public Sub New(ByVal map As ICompressorMap, byref pulleyGearRatio As Single, byref pulleyGearEfficiency As Single, signals As ISignals) - - _map = map - _pulleyGearRatio = pulleyGearRatio - _pulleyGearEfficiency = pulleyGearEfficiency - _signals = signals - - End Sub - - ''' <summary> - ''' Initialises the AirCompressor Class - ''' </summary> - ''' <returns></returns> - ''' <remarks></remarks> - Public Function Initialise() As Boolean Implements IM4_AirCompressor.Initialise - Return _map.Initialise() - End Function - - 'Queryable Compressor Methods - ' - 'Compressor ( Speed ) Flow Rate - 'Power @ Crank From Pnumatics compressor off ( A ) - 'Power @ Crank From Pnumatics compressor On ( B ) - 'Power Delta ( A ) vs ( B ) - - - 'Return Average Power Demand Per Compressor Unit Flow Rate - - - ''' <summary> - ''' Returns the flow rate [litres/second] of compressor for the given engine rpm - ''' </summary> - ''' <returns></returns> - ''' <remarks></remarks> - Public Function GetFlowRate() As Single Implements IM4_AirCompressor.GetFlowRate - Dim compressorRpm As Single = _signals.EngineSpeed * PulleyGearRatio - - ''Flow Rate in the map is Litres/min so divide by 60 to get Units per second. - Return _map.GetFlowRate(compressorRpm) / 60 - - End Function - - ''' <summary> - ''' Returns the power consumed for the given engine rpm when compressor is off - ''' </summary> - ''' <returns></returns> - ''' <remarks></remarks> - Public Function GetPowerCompressorOff() As Single Implements IM4_AirCompressor.GetPowerCompressorOff - Return GetCompressorPower(False) - End Function - - ''' <summary> - ''' Returns the power consumed for the given engine rpm when compressor is on - ''' </summary> - ''' <returns></returns> - ''' <remarks></remarks> - Public Function GetPowerCompressorOn() As Single Implements IM4_AirCompressor.GetPowerCompressorOn - Return GetCompressorPower( True) - End Function - - ''' <summary> - ''' Returns the difference in power between compressonr on and compressor off operation at the given engine rpm - ''' </summary> - ''' <returns></returns> - ''' <remarks></remarks> - Public Function GetPowerDifference() As Single Implements IM4_AirCompressor.GetPowerDifference - Dim powerOn As Single = GetPowerCompressorOn() - Dim powerOff As Single = GetPowerCompressorOff() - Return powerOn - powerOff - End Function - - ''' <summary> - ''' Looks up the compressor power from the map at given engine speed - ''' </summary> - ''' <param name="compressorOn">Is compressor on</param> - ''' <returns></returns> - ''' <remarks></remarks> - Private Function GetCompressorPower( ByVal compressorOn As Boolean) As Single - Dim compressorRpm As Single = _signals.EngineSpeed * PulleyGearRatio - If compressorOn Then - Return _map.GetPowerCompressorOn(compressorRpm) - Else - Return _map.GetPowerCompressorOff(compressorRpm) - End If - End Function - - ''' <summary> - ''' Aver - ''' </summary> - ''' <returns></returns> - ''' <remarks></remarks> - Public Function GetAveragePowerDemandPerCompressorUnitFlowRate() As Single Implements IM4_AirCompressor.GetAveragePowerDemandPerCompressorUnitFlowRate - - Return _map.GetAveragePowerDemandPerCompressorUnitFlowRate() - - End Function - - - - End Class - + Public Class M4_AirCompressor + Implements IM4_AirCompressor + + Private Const MinRatio As Single = 1 + Private Const MaxRatio As Single = 10 + Private Const MinEff As Single = 0 + Private Const MaxEff As Single = 1 + + Private _pulleyGearRatio As Single + Private _pulleyGearEfficiency As Single + Private _map As ICompressorMap + Private _signals As ISignals + + + ''' <summary> + ''' Ratio of Gear or Pulley used to drive the compressor + ''' </summary> + ''' <value></value> + ''' <returns></returns> + ''' <remarks></remarks> + Public Property PulleyGearRatio() As Single Implements IM4_AirCompressor.PulleyGearRatio + Get + Return _pulleyGearRatio + End Get + Set(value As Single) + If (value < MinRatio OrElse value > MaxRatio) Then + Throw _ + New ArgumentOutOfRangeException( + String.Format("Invalid value, should be in the range {0} to {1}", MinRatio, MaxRatio), value) + Else + _pulleyGearRatio = value + End If + End Set + End Property + + ''' <summary> + ''' Efficiency of the Pulley or Gear used to drive the compressor + ''' </summary> + ''' <value></value> + ''' <returns></returns> + ''' <remarks></remarks> + Public Property PulleyGearEfficiency() As Single Implements IM4_AirCompressor.PulleyGearEfficiency + Get + Return _pulleyGearEfficiency + End Get + Set(value As Single) + If (value < MinEff OrElse value > MaxEff) Then + Throw _ + New ArgumentOutOfRangeException(String.Format("Invalid value, should be in the range {0} to {1}", MinEff, MaxEff), + value) + Else + _pulleyGearEfficiency = value + End If + End Set + End Property + + + '''<summary> + ''' Creates a new instance of the AirCompressor Class + ''' </summary> + ''' <param name="map">map of compressor values against compressor rpm</param> + ''' <param name="pulleyGearRatio">Ratio of Pulley/Gear</param> + ''' <param name="pulleyGearEfficiency">Efficiency of Pulley/Gear</param> + ''' <remarks></remarks> + Public Sub New(ByVal map As ICompressorMap, ByRef pulleyGearRatio As Single, ByRef pulleyGearEfficiency As Single, + signals As ISignals) + + _map = map + _pulleyGearRatio = pulleyGearRatio + _pulleyGearEfficiency = pulleyGearEfficiency + _signals = signals + End Sub + + ''' <summary> + ''' Initialises the AirCompressor Class + ''' </summary> + ''' <returns></returns> + ''' <remarks></remarks> + Public Function Initialise() As Boolean Implements IM4_AirCompressor.Initialise + Return _map.Initialise() + End Function + + 'Queryable Compressor Methods + ' + 'Compressor ( Speed ) Flow Rate + 'Power @ Crank From Pnumatics compressor off ( A ) + 'Power @ Crank From Pnumatics compressor On ( B ) + 'Power Delta ( A ) vs ( B ) + + + 'Return Average Power Demand Per Compressor Unit Flow Rate + + + ''' <summary> + ''' Returns the flow rate [litres/second] of compressor for the given engine rpm + ''' </summary> + ''' <returns></returns> + ''' <remarks></remarks> + Public Function GetFlowRate() As Single Implements IM4_AirCompressor.GetFlowRate + Dim compressorRpm As Single = _signals.EngineSpeed * PulleyGearRatio + + ''Flow Rate in the map is Litres/min so divide by 60 to get Units per second. + Return _map.GetFlowRate(compressorRpm) / 60 + End Function + + ''' <summary> + ''' Returns the power consumed for the given engine rpm when compressor is off + ''' </summary> + ''' <returns></returns> + ''' <remarks></remarks> + Public Function GetPowerCompressorOff() As Single Implements IM4_AirCompressor.GetPowerCompressorOff + Return GetCompressorPower(False) + End Function + + ''' <summary> + ''' Returns the power consumed for the given engine rpm when compressor is on + ''' </summary> + ''' <returns></returns> + ''' <remarks></remarks> + Public Function GetPowerCompressorOn() As Single Implements IM4_AirCompressor.GetPowerCompressorOn + Return GetCompressorPower(True) + End Function + + ''' <summary> + ''' Returns the difference in power between compressonr on and compressor off operation at the given engine rpm + ''' </summary> + ''' <returns></returns> + ''' <remarks></remarks> + Public Function GetPowerDifference() As Single Implements IM4_AirCompressor.GetPowerDifference + Dim powerOn As Single = GetPowerCompressorOn() + Dim powerOff As Single = GetPowerCompressorOff() + Return powerOn - powerOff + End Function + + ''' <summary> + ''' Looks up the compressor power from the map at given engine speed + ''' </summary> + ''' <param name="compressorOn">Is compressor on</param> + ''' <returns></returns> + ''' <remarks></remarks> + Private Function GetCompressorPower(ByVal compressorOn As Boolean) As Single + Dim compressorRpm As Single = _signals.EngineSpeed * PulleyGearRatio + If compressorOn Then + Return _map.GetPowerCompressorOn(compressorRpm) + Else + Return _map.GetPowerCompressorOff(compressorRpm) + End If + End Function + + ''' <summary> + ''' Aver + ''' </summary> + ''' <returns></returns> + ''' <remarks></remarks> + Public Function GetAveragePowerDemandPerCompressorUnitFlowRate() As Single _ + Implements IM4_AirCompressor.GetAveragePowerDemandPerCompressorUnitFlowRate + + Return _map.GetAveragePowerDemandPerCompressorUnitFlowRate() + End Function + End Class End Namespace \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/Mocks/CompressorMapMock.vb b/VECTOAux/VectoAuxiliariesTests/Mocks/CompressorMapMock.vb index 9fe1764afd2b83b4b8df6ea893c8333308eb6393..f726848898c80af4d0d48d2b373103182d4d0bce 100644 --- a/VECTOAux/VectoAuxiliariesTests/Mocks/CompressorMapMock.vb +++ b/VECTOAux/VectoAuxiliariesTests/Mocks/CompressorMapMock.vb @@ -19,15 +19,15 @@ Namespace Mocks End If End Function - Public Function GetFlowRate(ByVal rpm As Integer) As Single Implements ICompressorMap.GetFlowRate + Public Function GetFlowRate(ByVal rpm As Double) As Single Implements ICompressorMap.GetFlowRate Return 2.0 End Function - Public Function GetPowerCompressorOn(ByVal rpm As Integer) As Single Implements ICompressorMap.GetPowerCompressorOn + Public Function GetPowerCompressorOn(ByVal rpm As Double) As Single Implements ICompressorMap.GetPowerCompressorOn Return 8.0 End Function - Public Function GetPowerCompressorOff(ByVal rpm As Integer) As Single Implements ICompressorMap.GetPowerCompressorOff + Public Function GetPowerCompressorOff(ByVal rpm As Double) As Single Implements ICompressorMap.GetPowerCompressorOff Return 5.0 End Function diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/AveragePneumaticLoadDemandTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/AveragePneumaticLoadDemandTests.vb index 0de2727300ea74e1a1a75ac3e755dd38dae1ef68..4d3c8681a669155a3e47395c53940ebc475a2f5d 100644 --- a/VECTOAux/VectoAuxiliariesTests/UnitTests/AveragePneumaticLoadDemandTests.vb +++ b/VECTOAux/VectoAuxiliariesTests/UnitTests/AveragePneumaticLoadDemandTests.vb @@ -6,314 +6,320 @@ Imports VectoAuxiliaries Namespace UnitTests + <TestFixture> + Public Class M3_AveragePneumaticLoadDemandTests + Private _pneumaticUserInputsConfig As IPneumaticUserInputsConfig + Private _pneumaticAuxillariesConfig As IPneumaticsAuxilliariesConfig + Private _pneumaticsActuationsMap As IPneumaticActuationsMAP + Private _pneumaticsCompressorFlowRateMap As ICompressorMap + Private _vehicleMassKG As Single = 16500 + Private _cycleName As String = "Urban" + Private _cycleDurationMinutes As Single = 51.9 + Private _totalAirDemand As Single - <TestFixture> - Public Class M3_AveragePneumaticLoadDemandTests + Private _actuationsMapPath As String = "Testfiles\testPneumaticActuationsMap_GOODMAP.apac" + Private _compressorMapPath As String = "Testfiles\testCompressorMap.acmp" + Private _defaultInputConfig As IPneumaticUserInputsConfig + Private _Signals As ISignals = New Signals - Private _pneumaticUserInputsConfig As IPneumaticUserInputsConfig - Private _pneumaticAuxillariesConfig As IPneumaticsAuxilliariesConfig - Private _pneumaticsActuationsMap As IPneumaticActuationsMAP - Private _pneumaticsCompressorFlowRateMap As ICompressorMap - Private _vehicleMassKG As Single = 16500 - Private _cycleName As String = "Urban" - Private _cycleDurationMinutes As Single = 51.9 - Private _totalAirDemand As Single + 'Constructors + Public Sub New() - Private _actuationsMapPath As String = "Testfiles\testPneumaticActuationsMap_GOODMAP.apac" - Private _compressorMapPath As String = "Testfiles\testCompressorMap.acmp" + initialise() + End Sub - Private _defaultInputConfig As IPneumaticUserInputsConfig - Private _Signals As ISignals = New Signals + Private Sub initialise() + _defaultInputConfig = New PneumaticUserInputsConfig() + _defaultInputConfig.CompressorGearRatio = 1.3 + _defaultInputConfig.CompressorGearEfficiency = 0.8 + _defaultInputConfig.SmartRegeneration = True + _defaultInputConfig.RetarderBrake = True + _defaultInputConfig.KneelingHeightMillimeters = 80 + _defaultInputConfig.AirSuspensionControl = "Electrically" + _defaultInputConfig.AdBlueDosing = "Pneumatic" + _defaultInputConfig.Doors = "Pneumatic" + _defaultInputConfig.SmartAirCompression = True - 'Constructors - Public Sub New() + _Signals.TotalCycleTimeSeconds = 3114 - initialise() + _Signals.EngineSpeed = 3000 + End Sub - End Sub - Private Sub initialise() + <Test> + Public Sub CreateNewtest() - _defaultInputConfig = New PneumaticUserInputsConfig() + Dim psUserInputsConfig = CType(New PneumaticUserInputsConfig(), IPneumaticUserInputsConfig) + psUserInputsConfig.AirSuspensionControl = "Mechanically" + psUserInputsConfig.Doors = "Pneumatic" + psUserInputsConfig.AdBlueDosing = "Pneumatic" - _defaultInputConfig.CompressorGearRatio=1.3 - _defaultInputConfig.CompressorGearEfficiency = 0.8 - _defaultInputConfig.SmartRegeneration = True - _defaultInputConfig.RetarderBrake = True - _defaultInputConfig.KneelingHeightMillimeters = 80 - _defaultInputConfig.AirSuspensionControl = "Electrically" - _defaultInputConfig.AdBlueDosing = "Pneumatic" - _defaultInputConfig.Doors = "Pneumatic" - _defaultInputConfig.SmartAirCompression = True - _Signals.TotalCycleTimeSeconds=3114 + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - _Signals.EngineSpeed=3000 + psCompressorMap.Initialise() + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(psUserInputsConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, + "Urban", _signals) - End Sub + Assert.IsNotNull(target) + End Sub - <Test> - Public Sub CreateNewtest() + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValuesTest() - Dim psUserInputsConfig = CType(New PneumaticUserInputsConfig(), IPneumaticUserInputsConfig) - psUserInputsConfig.AirSuspensionControl = "Mechanically" - psUserInputsConfig.Doors = "Pneumatic" - psUserInputsConfig.AdBlueDosing = "Pneumatic" + initialise() + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) + psCompressorMap.Initialise() + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _signals) - psCompressorMap.Initialise() - Dim target As New M3_AveragePneumaticLoadDemand(psUserInputsConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) + Dim expected As Single = 7947.684 + Dim actual As Single = target.TotalAirDemand() + Assert.AreEqual(expected, actual) + End Sub + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValues_AveragePowerAtTheCrankTest() - Assert.IsNotNull(target) + initialise() - End Sub + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValuesTest() + psCompressorMap.Initialise() - initialise() + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _signals) - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) + Dim expected As Single = 5832.091 + Dim actual As Single = target.GetAveragePowerDemandAtCrankFromPneumatics() - psCompressorMap.Initialise() + Assert.AreEqual(expected, actual, 0.001) + End Sub - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) - Dim expected As Single = 7947.684 - Dim actual As Single = target.TotalAirDemand() + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValues_AveragePowerAtTheCrank_0_80EFTest() - Assert.AreEqual(expected, actual) + initialise() + _defaultInputConfig.CompressorGearEfficiency = 0.8 - End Sub + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValues_AveragePowerAtTheCrankTest() + psCompressorMap.Initialise() - initialise() + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _signals) - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) + Dim expected As Single = 5832.091 + Dim actual As Single = target.GetAveragePowerDemandAtCrankFromPneumatics() - psCompressorMap.Initialise() + Assert.AreEqual(expected, actual, 0.001) + End Sub - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRateTest() - Dim expected As Single = 5832.091 - Dim actual As Single = target.GetAveragePowerDemandAtCrankFromPneumatics() + initialise() - Assert.AreEqual(expected, actual) + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - End Sub + psCompressorMap.Initialise() + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _signals) - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValues_AveragePowerAtTheCrank_0_80EFTest() + Dim expected As Single = Math.Round(7947.55127 / _Signals.TotalCycleTimeSeconds, 4) + Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 4) - initialise() + Assert.AreEqual(expected, actual) + End Sub - _defaultInputConfig.CompressorGearEfficiency = 0.8 + 'SmartRegeneration = False + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_SmartRegenOffTest() - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) + initialise() - psCompressorMap.Initialise() + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) + psCompressorMap.Initialise() - Dim expected As Single = 5832.091 - Dim actual As Single = target.GetAveragePowerDemandAtCrankFromPneumatics() + _defaultInputConfig.SmartRegeneration = False - Assert.AreEqual(expected, actual) + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _Signals) - End Sub + Dim expected As Single = Math.Round(8863.378 / _Signals.TotalCycleTimeSeconds, 4) + Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 4) - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRateTest() + Assert.AreEqual(expected, actual) + End Sub - initialise() + 'RetarderBrake = False + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_RetarderBrakeOffTest() - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) + initialise() - psCompressorMap.Initialise() + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) + psCompressorMap.Initialise() - Dim expected As Single = Math.Round(7947.55127 / _Signals.TotalCycleTimeSeconds, 4) - Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(),4) + _defaultInputConfig.RetarderBrake = False - Assert.AreEqual(expected, actual) + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _Signals) - End Sub + Dim expected As Single = Math.Round(8541.45 / _Signals.TotalCycleTimeSeconds, 4) - 'SmartRegeneration = False - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_SmartRegenOffTest() + Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 4) - initialise() + Assert.AreEqual(expected, actual) + End Sub - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) + 'KneelingHeightMilimeters = 100 + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_Kneeling100mmTest() - psCompressorMap.Initialise() + initialise() - _defaultInputConfig.SmartRegeneration = False + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) + psCompressorMap.Initialise() - Dim expected As Single = Math.Round(8863.378 / _Signals.TotalCycleTimeSeconds, 4) - Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(),4) + _defaultInputConfig.KneelingHeightMillimeters = 100 - Assert.AreEqual(expected, actual) + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _Signals) - End Sub + Dim expected As Single = 8557.524 / _Signals.TotalCycleTimeSeconds - 'RetarderBrake = False - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_RetarderBrakeOffTest() + Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 8) - initialise() + Assert.AreEqual(expected, actual) + End Sub - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) + 'AirSuspensionControl = "mechanically" + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_AirSuspension_mechanicallyTest() - psCompressorMap.Initialise() + initialise() - _defaultInputConfig.RetarderBrake = False + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) + psCompressorMap.Initialise() - Dim expected As Single = Math.round(8541.45 / _Signals.TotalCycleTimeSeconds,4) + _defaultInputConfig.AirSuspensionControl = "Mechanically" - Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 4) + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _Signals) - Assert.AreEqual(expected, actual) + Dim expected As Single = 7947.68457 / _Signals.TotalCycleTimeSeconds - End Sub + Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 6) - 'KneelingHeightMilimeters = 100 - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_Kneeling100mmTest() + Assert.AreEqual(expected, actual) + End Sub - initialise() + 'AdBlueDosing = "electric" + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_AdBlueDosing_electric_Test() - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) + initialise() - psCompressorMap.Initialise() + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - _defaultInputConfig.KneelingHeightMillimeters = 100 + psCompressorMap.Initialise() - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) + _defaultInputConfig.AdBlueDosing = "Pneumatic" - Dim expected As Single = 8557.524 / _Signals.TotalCycleTimeSeconds + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _Signals) - Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 8) + Dim expected As Single = 7947.68457 / _Signals.TotalCycleTimeSeconds - Assert.AreEqual(expected, actual) + Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 6) - End Sub + Assert.AreEqual(expected, actual) + End Sub - 'AirSuspensionControl = "mechanically" - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_AirSuspension_mechanicallyTest() + 'Doors = "Electric" + <Test()> + Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_Doors_electric_Test() - initialise() + initialise() - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) + Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) + Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) + Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - psCompressorMap.Initialise() + psCompressorMap.Initialise() - _defaultInputConfig.AirSuspensionControl = "Mechanically" + _defaultInputConfig.Doors = "Electric" - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) - - Dim expected As Single = 7947.68457 / _Signals.TotalCycleTimeSeconds - - Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 6) - - Assert.AreEqual(expected, actual) - - End Sub - - 'AdBlueDosing = "electric" - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_AdBlueDosing_electric_Test() - - initialise() - - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - - psCompressorMap.Initialise() - - _defaultInputConfig.AdBlueDosing = "Pneumatic" - - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) - - Dim expected As Single = 7947.68457 / _Signals.TotalCycleTimeSeconds - - Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 6) - - Assert.AreEqual(expected, actual) - - End Sub - - 'Doors = "Electric" - <Test()> - Public Sub AverageLoadValueUsingDefaultAuxValues_TotalRequiredAirDeliveryRate_Doors_electric_Test() - - initialise() - - Dim psAuxConfig = CType(New PneumaticsAuxilliariesConfig(True), IPneumaticsAuxilliariesConfig) - Dim psActuationsMap = CType(New PneumaticActuationsMAP(_actuationsMapPath), IPneumaticActuationsMAP) - Dim psCompressorMap = CType(New CompressorMap(_compressorMapPath), ICompressorMap) - - psCompressorMap.Initialise() - - _defaultInputConfig.Doors = "Electric" - - Dim target As New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, _vehicleMassKG, "Urban", _signals) - - Dim expected As Single = 6880.88428 / _Signals.TotalCycleTimeSeconds - - Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 6) - - Assert.AreEqual(expected, actual) - - End Sub - - - - End Class + Dim _ + target As _ + New M3_AveragePneumaticLoadDemand(_defaultInputConfig, psAuxConfig, psActuationsMap, psCompressorMap, + _vehicleMassKG, "Urban", _Signals) + Dim expected As Single = 6880.88428 / _Signals.TotalCycleTimeSeconds + Dim actual As Single = Math.Round(target.AverageAirConsumedPerSecondLitre(), 6) + Assert.AreEqual(expected, actual) + End Sub + End Class End Namespace diff --git a/VectoCommon/AdvancedAuxiliaryInterfaces/ISignals.vb b/VectoCommon/AdvancedAuxiliaryInterfaces/ISignals.vb index 39ad35d01546bc298107ac5b5322ade3ca6ccb03..76e513745b5afacaa25fef44889a0f4feeb1eaea 100644 --- a/VectoCommon/AdvancedAuxiliaryInterfaces/ISignals.vb +++ b/VectoCommon/AdvancedAuxiliaryInterfaces/ISignals.vb @@ -56,7 +56,7 @@ Public Interface ISignals ''' <value></value> ''' <returns></returns> ''' <remarks>RPM in old money - Vecto Input</remarks> - Property EngineSpeed As Integer + Property EngineSpeed As Double ''' <summary> ''' Smart Pneumatics diff --git a/VectoCommon/AdvancedAuxiliaryInterfaces/Signals.vb b/VectoCommon/AdvancedAuxiliaryInterfaces/Signals.vb index 5e034fb3cdb1659b9f3db674c56cd1a2584601e6..0cada55b0331cbddbb0da75ab9ef30fbe058c778 100644 --- a/VectoCommon/AdvancedAuxiliaryInterfaces/Signals.vb +++ b/VectoCommon/AdvancedAuxiliaryInterfaces/Signals.vb @@ -21,7 +21,7 @@ Public Class Signals Public Property EngineDrivelinePower As Single Implements ISignals.EngineDrivelinePower Public Property EngineDrivelineTorque As Single Implements ISignals.EngineDrivelineTorque Public Property EngineMotoringPower As Single Implements ISignals.EngineMotoringPower - Public Property EngineSpeed As Integer Implements ISignals.EngineSpeed + Public Property EngineSpeed As Double Implements ISignals.EngineSpeed Public Property SmartElectrics As Boolean Implements ISignals.SmartElectrics Get diff --git a/VectoCommon/VectoCommon/Exceptions/VectoSimulationException.cs b/VectoCommon/VectoCommon/Exceptions/VectoSimulationException.cs index 53c5a6bbaeacef588d6c085eee7578ed6c53921a..4ad924d871fe2b310a9875f51dee79b841d114b2 100644 --- a/VectoCommon/VectoCommon/Exceptions/VectoSimulationException.cs +++ b/VectoCommon/VectoCommon/Exceptions/VectoSimulationException.cs @@ -71,4 +71,9 @@ namespace TUGraz.VectoCommon.Exceptions { public VectoSearchFailedException(string message, params object[] args) : base(message, args) {} } + + public class VectoSearchAbortedException : VectoException + { + public VectoSearchAbortedException(string message, params object[] args) : base(message, args) { } + } } \ No newline at end of file diff --git a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs index 2e65ca2d4fa89b8ca53384b96a69635e1f3ed2a6..e5f0174b317a77ee4cc8801119ab07aece0a1ffa 100644 --- a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs +++ b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs @@ -92,13 +92,6 @@ namespace TUGraz.VectoCommon.InputData /// cf. VECTO Input Parameters.xlsx /// </summary> DataTable CrosswindCorrectionMap { get; } - - // Advanced Auxiliaries - AuxiliaryModel AuxiliaryAssembly { get; } - - string AuxiliaryVersion { get; } - - string AdvancedAuxiliaryFilePath { get; } } @@ -196,6 +189,13 @@ namespace TUGraz.VectoCommon.InputData public interface IAuxiliariesEngineeringInputData : IAuxiliariesDeclarationInputData { new IList<IAuxiliaryEngineeringInputData> Auxiliaries { get; } + + // Advanced Auxiliaries + AuxiliaryModel AuxiliaryAssembly { get; } + + string AuxiliaryVersion { get; } + + string AdvancedAuxiliaryFilePath { get; } } diff --git a/VectoCommon/VectoCommon/Models/IResponse.cs b/VectoCommon/VectoCommon/Models/IResponse.cs index fffb0b55fb891671f5582714c9a5fc0a0baaaf32..30a1afe1c4a6225db97a3d7cddbffe13149c4b52 100644 --- a/VectoCommon/VectoCommon/Models/IResponse.cs +++ b/VectoCommon/VectoCommon/Models/IResponse.cs @@ -30,6 +30,7 @@ */ using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; namespace TUGraz.VectoCommon.Models { @@ -63,5 +64,7 @@ namespace TUGraz.VectoCommon.Models PerSecond EngineSpeed { get; set; } Second AbsTime { get; set; } + + Driver.OperatingPoint OperatingPoint { get; set; } } } \ No newline at end of file diff --git a/VectoCommon/VectoCommon/Models/LoggingObject.cs b/VectoCommon/VectoCommon/Models/LoggingObject.cs index ba9f983d88fa0d97e49aa02efbc71b5579c776cc..168fb8da61e2ae045f9b5b8cbbc970202ae24113 100644 --- a/VectoCommon/VectoCommon/Models/LoggingObject.cs +++ b/VectoCommon/VectoCommon/Models/LoggingObject.cs @@ -76,6 +76,21 @@ namespace TUGraz.VectoCommon.Models private readonly Logger _log; + public LoggingObject() + { + _log = NLog.LogManager.GetLogger(GetType().FullName); + } + + public LoggingObject(string fullName) + { + _log = NLog.LogManager.GetLogger(fullName); + } + + public static LoggingObject Logger<T>() + { + return new LoggingObject(typeof(T).ToString()); + } + /// <summary> /// Fatal > Error > Warn > Info > Debug > Trace /// </summary> @@ -182,20 +197,5 @@ namespace TUGraz.VectoCommon.Models { get { return this; } } - - public LoggingObject() - { - _log = NLog.LogManager.GetLogger(GetType().FullName); - } - - public LoggingObject(string fullName) - { - _log = NLog.LogManager.GetLogger(fullName); - } - - public static LoggingObject Logger<T>() - { - return new LoggingObject(typeof(T).ToString()); - } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index d68276a31785d23b36f4b3a05d79f04e17cadbc9..257a90f3a6dc798d52947c54edb87fbfa2ea9ba0 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -520,5 +520,32 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } return retVal; } + + #region AdvancedAuxiliaries + + public AuxiliaryModel AuxiliaryAssembly + { + get + { + return AuxiliaryModelHelper.Parse(Body["AuxiliaryAssembly"] == null ? "" : Body["AuxiliaryAssembly"].ToString()); + } + } + + public string AuxiliaryVersion + { + get { return Body["AuxiliaryVersion"] != null ? Body["AuxiliaryVersion"].Value<string>() : "<CLASSIC>"; } + } + + public string AdvancedAuxiliaryFilePath + { + get + { + return Body["AdvancedAuxiliaryFilePath"] != null + ? Path.Combine(Path.GetFullPath(BasePath), Body["AdvancedAuxiliaryFilePath"].Value<string>()) + : ""; + } + } + + #endregion } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs index 8b2ad398858eae50aa6fa048e2f56d8870cd8a26..827910db8f650d7f961fc3e8fb247dab10d42637 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs @@ -174,25 +174,6 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON #endregion - #region AdvancedAuxiliaries - - public AuxiliaryModel AuxiliaryAssembly - { - get { return AuxiliaryModelHelper.Parse(Body["AuxiliaryAssembly"] == null ? "" : Body["AuxiliaryAssembly"].ToString()); } - } - - public string AuxiliaryVersion - { - get { return Body["AuxiliaryVersion"] != null ? Body["AuxiliaryVersion"].Value<string>() : "<CLASSIC>"; } - } - - public string AdvancedAuxiliaryFilePath - { - get { return Body["AdvancedAuxiliaryFilePath"] != null ? Body["AdvancedAuxiliaryFilePath"].Value<string>() : ""; } - } - - #endregion - public string Vendor { get { return "N/A"; } diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs index 2915ab4095e162c509848a3d88a66c6b025bedf6..a0460d71682da51e88b6f6c875553976729d44b2 100644 --- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs +++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs @@ -36,6 +36,7 @@ using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.Models; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation.Data; @@ -224,12 +225,12 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdaper return SetCommonRetarderData(retarder, vehicle); } - public AdvancedAuxData CreateAdvancedAuxData(IVehicleEngineeringInputData vehicleInputData) + public AdvancedAuxData CreateAdvancedAuxData(IAuxiliariesEngineeringInputData auxInputData) { return new AdvancedAuxData() { - AdvancedAuxiliaryFilePath = vehicleInputData.AdvancedAuxiliaryFilePath, - AuxiliaryAssembly = vehicleInputData.AuxiliaryAssembly, - AuxiliaryVersion = vehicleInputData.AuxiliaryVersion + AdvancedAuxiliaryFilePath = auxInputData.AdvancedAuxiliaryFilePath, + AuxiliaryAssembly = auxInputData.AuxiliaryAssembly, + AuxiliaryVersion = auxInputData.AuxiliaryVersion }; } } diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs index 4b36932370ff9c705bbaacf9b12f4be81b0195f3..7f561b8801956529a438383424c246bfafd87195 100644 --- a/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs +++ b/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs @@ -79,7 +79,7 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl VehicleData = dao.CreateVehicleData(vehicleInputData), DriverData = driver, Aux = dao.CreateAuxiliaryData(InputDataProvider.AuxiliaryInputData()), - AdvancedAux = dao.CreateAdvancedAuxData(InputDataProvider.VehicleInputData), + AdvancedAux = dao.CreateAdvancedAuxData(InputDataProvider.AuxiliaryInputData()), Retarder = dao.CreateRetarderData(InputDataProvider.RetarderInputData, InputDataProvider.VehicleInputData), Cycle = DrivingCycleDataReader.ReadFromDataTable(cycle.CycleData, cycle.Name, crossWindRequired), ExecutionMode = ExecutionMode.Engineering diff --git a/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs b/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs index f594056130543d10d0d76a222d8178ec09806b29..9555b7c5f3d6e6c4590bc9eb662d511206deb79f 100644 --- a/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs +++ b/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs @@ -32,6 +32,7 @@ using System.Linq; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; namespace TUGraz.VectoCore.Models.Connector.Ports.Impl { @@ -61,6 +62,8 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl public Second AbsTime { get; set; } + public Driver.OperatingPoint OperatingPoint { get; set; } + public PerSecond EngineSpeed { get; set; } public object Source { get; set; } diff --git a/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs b/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs index f612b7a1404fee7f593f2838627cc5da8b739423..8b93a251faf9ef221165ea76b27ad8af00511e4a 100644 --- a/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs +++ b/VectoCore/VectoCore/Models/Simulation/DataBus/IDriverInfo.cs @@ -42,8 +42,6 @@ namespace TUGraz.VectoCore.Models.Simulation.DataBus public interface IDriverInfo { - bool VehicleStopped { get; } - - DrivingBehavior DrivingBehavior { get; } + DrivingBehavior DriverBehavior { get; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Simulation/DataBus/IVehicleInfo.cs b/VectoCore/VectoCore/Models/Simulation/DataBus/IVehicleInfo.cs index cfdd48336529c7deb26898ad895533b188846c09..64b5ae61f2f5a6b180854ca2b8ae4a05548a55b2 100644 --- a/VectoCore/VectoCore/Models/Simulation/DataBus/IVehicleInfo.cs +++ b/VectoCore/VectoCore/Models/Simulation/DataBus/IVehicleInfo.cs @@ -44,6 +44,8 @@ namespace TUGraz.VectoCore.Models.Simulation.DataBus /// <value></value> MeterPerSecond VehicleSpeed { get; } + bool VehicleStopped { get; } + Kilogram VehicleMass { get; } Kilogram VehicleLoading { get; } diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs index e89b0e0e0475198beee79d3691ff8cab20a0602a..b257ec726395c64761bd9f773001ff0305696c22 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs @@ -290,11 +290,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl AddComponent(tmp, engine); // connect aux --> engine - if (data.Aux != null) { - engine.Connect(CreateAuxiliaries(data, container).Port()); + if (data.AdvancedAux != null && data.AdvancedAux.AuxiliaryAssembly == AuxiliaryModel.Advanced) { + engine.Connect(CreateBusAuxiliaries(data, container).Port()); } else { - if (data.AdvancedAux.AuxiliaryAssembly == AuxiliaryModel.Advanced) { - engine.Connect(CreateBusAuxiliaries(data, container).Port()); + if (data.Aux != null) { + engine.Connect(CreateAuxiliaries(data, container).Port()); } } diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index abd715d74c61f81ea7f67dc17cdcdbddcc93c3dc..08b903660c87d6b9b439227fc57d4a9dcadef229 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -210,7 +210,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public void CommitSimulationStep(Second time, Second simulationInterval) { - Log.Info("VehicleContainer committing simulation. time: {0}, dist: {1}, speed: {2}", time, ExecutionMode==ExecutionMode.EngineOnly ? null : Distance, VehicleSpeed); + Log.Info("VehicleContainer committing simulation. time: {0}, dist: {1}, speed: {2}", time, + ExecutionMode == ExecutionMode.EngineOnly ? null : Distance, VehicleSpeed); foreach (var component in Components) { component.CommitSimulationStep(ModData); } @@ -278,12 +279,12 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public bool VehicleStopped { - get { return Driver.VehicleStopped; } + get { return Vehicle.VehicleStopped; } } - public DrivingBehavior DrivingBehavior + public DrivingBehavior DriverBehavior { - get { return Driver.DrivingBehavior; } + get { return Driver.DriverBehavior; } } public Meter CycleStartDistance diff --git a/VectoCore/VectoCore/Models/SimulationComponent/IDriverActions.cs b/VectoCore/VectoCore/Models/SimulationComponent/IDriverActions.cs index 1d4c0734d89de5595c18c35bb89f3caa4fde9430..26e019bc62cb7e24a641066e990c099bcf1242e3 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/IDriverActions.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/IDriverActions.cs @@ -126,5 +126,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent IDataBus DataBus { get; } DriverData DriverData { get; } + + DrivingBehavior DriverBehavior { set; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/IDriverStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/IDriverStrategy.cs index a63bc222943ec39e08291c4fde033cca294c0f29..d4354a0d056ae3a117f5e7c9fdd4c57394b2b227 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/IDriverStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/IDriverStrategy.cs @@ -39,8 +39,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent { IDriverActions Driver { get; set; } - DrivingBehavior DriverBehavior { get; } - IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient); IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs index 86abffd1bf8a62fdc04237b39371153ce7f8c86a..aa2fb87f4f781b696dabec69ae6ce051a84bec71 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs @@ -77,7 +77,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl // but this could lead to extrapolation of loss maps (in axlegear and gear). // solution: we check here if the angularVelocity is 0 the first time and brake away all the torque if it is. // afterwards the vehicle is standing and other mechanisms take over (Driver.DriveTimeInterval) - if (DataBus.DrivingBehavior == DrivingBehavior.Braking && !PreviousState.OutAngularVelocity.IsEqual(0) && + if (DataBus.DriverBehavior == DrivingBehavior.Braking && !PreviousState.OutAngularVelocity.IsEqual(0) && angularVelocity.IsEqual(0)) { brakeTorque = -torque; if (!dryRun) { @@ -100,7 +100,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { BrakePower = 0.SI<Watt>(); PreviousState.SetState(torque, angularVelocity, torque, angularVelocity); - return DataBus.VehicleStopped + return DataBus.DriverBehavior == DrivingBehavior.Halted && DataBus.VehicleStopped ? NextComponent.Initialize(0.SI<NewtonMeter>(), 0.SI<PerSecond>()) : NextComponent.Initialize(torque, angularVelocity); } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs index 0d9e86a4a3a7f758e983233ae2349d997a37fcd2..ad363ca1dfa9ea0898f40e399bb434972ff1ddf5 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Windows.Forms.VisualStyles; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Simulation; @@ -29,57 +30,50 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var tmpAux = new AdvancedAuxiliaries(); // 'Set Statics - tmpAux.VectoInputs.Cycle = DetermineCycle(cycleName); + tmpAux.VectoInputs.Cycle = DetermineCycle(cycleName, tmpAux.Signals); tmpAux.VectoInputs.VehicleWeightKG = (float)vehicleWeight.Value(); _fcMapAdapter = new FuelConsumptionAdapter() { FcMap = fcMap }; tmpAux.VectoInputs.FuelMap = _fcMapAdapter; tmpAux.VectoInputs.FuelDensity = Physics.FuelDensity.Value(); //'Set Signals - tmpAux.Signals.TotalCycleTimeSeconds = 15000; // TODO MQ: get cycle time somehow! tmpAux.Signals.EngineIdleSpeed = (float)(engineIdleSpeed.Value() / Constants.RPMToRad); tmpAux.Initialise(Path.GetFileName(aauxFile), Path.GetDirectoryName(Path.GetFullPath(aauxFile)) + @"\"); Auxiliaries = tmpAux; } - private static string DetermineCycle(string cycleName) + private static string DetermineCycle(string cycleName, ISignals aauxsignals) { - return "Coach"; - // Public Function DetermineCycleNameFromCurrentFile() As String + var cycle = cycleName.ToLower(); - // 'Get DriveFile without path and without extension - // Dim driveFile As String = fFILE(CurrentCycleFile, False) - - // Select Case (True) - - // 'DJN - update to make contains test case insensitive - // Case driveFile.ToLower().Contains("heavy_urban") AndAlso driveFile.ToLower().Contains("bus") - // Return "Heavy urban" - - // Case driveFile.ToLower().Contains("suburban") AndAlso driveFile.ToLower().Contains("bus") - // Return "Suburban" - - // Case driveFile.ToLower().Contains("urban") AndAlso driveFile.ToLower().Contains("bus") - // Return "Urban" - - // Case driveFile.ToLower().Contains("interurban") AndAlso driveFile.ToLower().Contains("bus") - // Return "Interurban" - - // Case driveFile.ToLower().Contains("coach") - // Return "Coach" - - // Case Else - // WorkerMsg(tMsgID.Warn, - // String.Format("UnServiced Cycle Name '{0}' in Pneumatics Actuations Map 0 Actuations returned", driveFile), - // "Advanced Auxiliaries") - // Return "UnknownCycleName" - - // End Select - - - // Return "Urban" - //End Function + // cycle time is hard coded based on previous simulations + if (cycle.Contains("bus")) { + if (cycle.Contains("heavy_urban")) { + aauxsignals.TotalCycleTimeSeconds = 8912; + return "Heavy urban"; + } + if (cycle.Contains("suburban")) { + aauxsignals.TotalCycleTimeSeconds = 3283; + return "Suburban"; + } + if (cycle.Contains("urban")) { + aauxsignals.TotalCycleTimeSeconds = 8149; + return "Urban"; + } + if (cycle.Contains("interurban")) { + aauxsignals.TotalCycleTimeSeconds = 12962; + return "Interurban"; + } + } + if (cycle.Contains("coach")) { + aauxsignals.TotalCycleTimeSeconds = 15086; + return "Coach"; + } + Logger<BusAuxiliariesAdapter>() + .Warn("UnServiced Cycle Name '{0}' in Pneumatics Actuations Map 0 Actuations returned", cycleName); + aauxsignals.TotalCycleTimeSeconds = 1; + return "UnknownCycleName"; } public IEngineAuxPort Port() @@ -184,7 +178,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Auxiliaries.Signals.EngineDrivelineTorque = (float)torquePowerTrain.Value(); Auxiliaries.Signals.Internal_Engine_Power = (float)((torqueEngine * angularSpeed - DataBus.BrakePower) / 1000).Value(); - if (DataBus.DrivingBehavior == DrivingBehavior.Coasting) { + if (DataBus.DriverBehavior == DrivingBehavior.Coasting) { // make sure smart aux are _not_ enabled for now // set internal_engine_power a little bit lower so there is no excessive power for smart aux Auxiliaries.Signals.Internal_Engine_Power = @@ -193,15 +187,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl // set internal_engine_power to a large value (*10) so that there's excessive power for smart aux (alreadin during search operating point) //(float)DataBus.EngineDragPower(angularSpeed).Value() / 100; } else { - if (DataBus.DrivingBehavior != DrivingBehavior.Braking) { + if (DataBus.DriverBehavior != DrivingBehavior.Braking) { Auxiliaries.Signals.Internal_Engine_Power = 0; //(float)((0.9 * torqueEngine * angularSpeed - DataBus.BrakePower) / 1000).Value(); } else { // smart aux should be on during braking } } - Auxiliaries.Signals.EngineMotoringPower = -(float)DataBus.EngineDragPower(angularSpeed).Value() / 1000; - Auxiliaries.Signals.EngineSpeed = (int)(angularSpeed.Value() / Constants.RPMToRad); + Auxiliaries.Signals.EngineMotoringPower = (float)(-DataBus.EngineDragPower(angularSpeed).Value() / 1000); + Auxiliaries.Signals.EngineSpeed = angularSpeed.Value() / Constants.RPMToRad; Auxiliaries.Signals.PreExistingAuxPower = 0; //mAAUX_Global.PreExistingAuxPower; Auxiliaries.Signals.Idle = DataBus.VehicleStopped; Auxiliaries.Signals.InNeutral = DataBus.Gear == 0; diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs index b51e121a362c8ccaa10d2d30dd93d6d83a2c6bbb..dfbd942b4e2753b4132679f427790b5cbb3e53d8 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs @@ -35,6 +35,7 @@ using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.Simulation.DataBus; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.Utils; @@ -158,7 +159,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl torqueIn = torque; angularVelocityIn = angularVelocity; - if (DataBus.VehicleStopped) { + if (DataBus.DriverBehavior == DrivingBehavior.Halted /*DataBus.VehicleStopped*/) { _clutchState = ClutchState.ClutchOpened; angularVelocityIn = _idleSpeed; torqueIn = 0.SI<NewtonMeter>(); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index 2a265f4044196ecc5cc23034d54c16145336f3b7..390323360e52a6f5c1f9b5b4eaa5d0e2e4e22898 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -174,7 +174,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var auxTorqueDemand = EngineAux == null ? 0.SI<NewtonMeter>() - : EngineAux.PowerDemand(absTime, dt, CurrentState.EngineTorqueOut, CurrentState.EngineTorqueOut + CurrentState.InertiaTorqueLoss, angularVelocity, dryRun); + : EngineAux.PowerDemand(absTime, dt, CurrentState.EngineTorqueOut, + CurrentState.EngineTorqueOut + CurrentState.InertiaTorqueLoss, angularVelocity, dryRun); // compute the torque the engine has to provide. powertrain + aux + its own inertia var totalTorqueDemand = torqueOut + auxTorqueDemand + CurrentState.InertiaTorqueLoss; @@ -212,7 +213,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if ( (deltaFull * avgEngineSpeed).IsGreater(0.SI<Watt>(), Constants.SimulationSettings.LineSearchTolerance) && (deltaDrag * avgEngineSpeed).IsSmaller(0.SI<Watt>(), Constants.SimulationSettings.LineSearchTolerance)) { - throw new VectoSimulationException( + //throw new VectoSimulationException( + Log.Error( "Unexpected condition: requested torque_out is above gearbox full-load and engine is below drag load! deltaFull: {0}, deltaDrag: {1}", deltaFull, deltaDrag); } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs index b0bb6295c769008172a5fe6d140803ecaf27eead..e4534f04f7db7a650c76fc607f55924263785774 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs @@ -56,6 +56,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } protected internal DrivingMode CurrentDrivingMode; + protected Dictionary<DrivingMode, IDriverMode> DrivingModes = new Dictionary<DrivingMode, IDriverMode>(); public DefaultDriverStrategy() @@ -112,15 +113,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { - DriverBehavior = DrivingBehavior.Halted; + Driver.DriverBehavior = DrivingBehavior.Halted; CurrentDrivingMode = DrivingMode.DrivingModeDrive; return Driver.DrivingActionHalt(absTime, dt, targetVelocity, gradient); } - public DrivingBehavior DriverBehavior { get; internal set; } - - private void UpdateDrivingAction(Meter currentDistance, Meter ds) { var nextAction = GetNextDrivingAction(currentDistance, ds); @@ -341,7 +339,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { IResponse response = null; - DriverStrategy.DriverBehavior = DrivingBehavior.Driving; + Driver.DriverBehavior = DrivingBehavior.Driving; var velocity = targetVelocity; if (DriverStrategy.OverspeedAllowed(gradient, targetVelocity)) { velocity += DriverData.OverSpeedEcoRoll.OverSpeed; @@ -520,7 +518,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } switch (Phase) { case BrakingPhase.Coast: - DriverStrategy.DriverBehavior = DrivingBehavior.Coasting; + Driver.DriverBehavior = DrivingBehavior.Coasting; response = DataBus.ClutchClosed(absTime) ? Driver.DrivingActionCoast(absTime, ds, VectoMath.Max(targetVelocity, DataBus.VehicleSpeed), gradient) : Driver.DrivingActionRoll(absTime, ds, VectoMath.Max(targetVelocity, DataBus.VehicleSpeed), gradient); @@ -540,6 +538,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } //Phase = BrakingPhase.Brake; }). + Case<ResponseDrivingCycleDistanceExceeded>(r => { + if (!ds.IsEqual(r.MaxDistance)) { + // distance has been reduced due to vehicle stop in coast/roll action => use brake action to get exactly to the stop-distance + // TODO: what if no gear is enaged (and we need driveline power to get to the stop-distance? + response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient); + } + }). Case<ResponseGearShift>(r => { response = Driver.DrivingActionRoll(absTime, ds, targetVelocity, gradient); }); // handle the SpeedLimitExceeded Response separately in case it occurs in one of the requests in the second try response.Switch(). @@ -566,7 +571,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (targetDistance == null && DriverStrategy.BrakeTrigger.NextTargetSpeed.IsEqual(0.SI<MeterPerSecond>())) { targetDistance = DriverStrategy.BrakeTrigger.TriggerDistance - DefaultDriverStrategy.BrakingSafetyMargin; } - DriverStrategy.DriverBehavior = DrivingBehavior.Braking; + Driver.DriverBehavior = DrivingBehavior.Braking; response = Driver.DrivingActionBrake(absTime, ds, DriverStrategy.BrakeTrigger.NextTargetSpeed, gradient, targetDistance: targetDistance); response.Switch(). diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 6aca5126b25f98939ae94959c074603f326102ce..217433ddcf9ae140f2a8619dab782911a54989f4 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -86,13 +86,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl "LookAhead Coasting Deceleration is lower than Driver's min. Deceleration. Coasting may start too late. Lookahead dec.: {0}, Driver min. deceleration: {1}", DriverData.LookAheadCoasting.Deceleration, DriverData.AccelerationCurve.MinDeceleration()); } - VehicleStopped = vehicleSpeed.IsEqual(0); + DriverBehavior = vehicleSpeed.IsEqual(0) ? DrivingBehavior.Halted : DrivingBehavior.Driving; return NextComponent.Initialize(vehicleSpeed, roadGradient); } public IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient, MeterPerSquareSecond startAcceleration) { - VehicleStopped = vehicleSpeed.IsEqual(0); + DriverBehavior = vehicleSpeed.IsEqual(0) ? DrivingBehavior.Halted : DrivingBehavior.Driving; var retVal = NextComponent.Initialize(vehicleSpeed, roadGradient, startAcceleration); return retVal; @@ -101,11 +101,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) { - VehicleStopped = false; Log.Debug("==== DRIVER Request (distance) ===="); Log.Debug( "Request: absTime: {0}, ds: {1}, targetVelocity: {2}, gradient: {3} | distance: {4}, velocity: {5}, vehicle stopped: {6}", - absTime, ds, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed, VehicleStopped); + absTime, ds, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed, DataBus.VehicleStopped); var retVal = DriverStrategy.Request(absTime, ds, targetVelocity, gradient); //DoHandleRequest(absTime, ds, targetVelocity, gradient); @@ -120,11 +119,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { - VehicleStopped = true; + //VehicleStopped = true; Log.Debug("==== DRIVER Request (time) ===="); Log.Debug( "Request: absTime: {0}, dt: {1}, targetVelocity: {2}, gradient: {3} | distance: {4}, velocity: {5} gear: {6}: vehicle stopped: {7}", - absTime, dt, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed, DataBus.Gear, VehicleStopped); + absTime, dt, targetVelocity, gradient, DataBus.Distance, DataBus.VehicleSpeed, DataBus.Gear, DataBus.VehicleStopped); var retVal = DriverStrategy.Request(absTime, dt, targetVelocity, gradient); @@ -358,7 +357,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var nextAcceleration = DriverData.AccelerationCurve.Lookup(v2).Deceleration; var tmp = ComputeTimeInterval(VectoMath.Min(operatingPoint.Acceleration, nextAcceleration), operatingPoint.SimulationDistance); - if (!operatingPoint.Acceleration.IsEqual(nextAcceleration) && operatingPoint.SimulationDistance.IsEqual(tmp.SimulationDistance)) { + if (!operatingPoint.Acceleration.IsEqual(nextAcceleration) && + operatingPoint.SimulationDistance.IsEqual(tmp.SimulationDistance)) { // only adjust operating point if the acceleration is different but the simulation distance is not modified // i.e., braking to the next sample point (but a little bit slower) Log.Debug("adjusting acceleration from {0} to {1}", operatingPoint.Acceleration, tmp.Acceleration); @@ -570,7 +570,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl retVal.SimulationInterval = tmp.SimulationInterval; retVal.SimulationDistance = tmp.SimulationDistance; } - return NextComponent.Request(absTime, retVal.SimulationInterval, acc, gradient, true); + var response = NextComponent.Request(absTime, retVal.SimulationInterval, acc, gradient, true); + response.OperatingPoint = retVal; + return response; }, criterion: response => { if (response is ResponseEngineSpeedTooLow) { @@ -583,19 +585,29 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var r = (ResponseDryRun)response; delta = actionRoll ? r.GearboxPowerRequest : (coasting ? r.DeltaDragLoad : r.DeltaFullLoad); return delta.Value(); - }); - - if ( - !retVal.Acceleration.IsBetween(DriverData.AccelerationCurve.MaxDeceleration(), - DriverData.AccelerationCurve.MaxAcceleration())) { - Log.Info("Operating Point outside driver acceleration limits: a: {0}", retVal.Acceleration); - } + }, + abortCriterion: + (response, cnt) => { + var r = (ResponseDryRun)response; + if (r == null) { + return false; + } - return ComputeTimeInterval(retVal.Acceleration, retVal.SimulationDistance); + return coasting && !ds.IsEqual(r.OperatingPoint.SimulationDistance); + }); + } catch (VectoSearchAbortedException) { + // search aborted, try to go ahead with the last acceleration } catch (Exception) { Log.Error("Failed to find operating point! absTime: {0}", absTime); throw; } + + if (!retVal.Acceleration.IsBetween(DriverData.AccelerationCurve.MaxDeceleration(), + DriverData.AccelerationCurve.MaxAcceleration())) { + Log.Info("Operating Point outside driver acceleration limits: a: {0}", retVal.Acceleration); + } + + return ComputeTimeInterval(retVal.Acceleration, retVal.SimulationDistance); } /// <summary> @@ -734,8 +746,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse DrivingActionHalt(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { if (!targetVelocity.IsEqual(0) || !DataBus.VehicleSpeed.IsEqual(0, 1e-3)) { - Log.Error("TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!", targetVelocity, DataBus.VehicleSpeed); - throw new VectoSimulationException("TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!", targetVelocity, DataBus.VehicleSpeed); + Log.Error("TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!", targetVelocity, + DataBus.VehicleSpeed); + throw new VectoSimulationException( + "TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!", targetVelocity, + DataBus.VehicleSpeed); } var retVal = NextComponent.Request(absTime, dt, 0.SI<MeterPerSquareSecond>(), gradient); @@ -798,16 +813,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl LimitDecelerationLookahead = 0x4 } - public DrivingBehavior DriverBehavior - { - get { return DriverStrategy.DriverBehavior; } - } + public DrivingBehavior DriverBehavior { get; set; } - public bool VehicleStopped { get; protected set; } + //public bool VehicleStopped { get; protected set; } - public DrivingBehavior DrivingBehavior - { - get { return DriverStrategy.DriverBehavior; } - } + //public DrivingBehavior DrivingBehavior + //{ + // get { return DriverStrategy.DriverBehavior; } + //} } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index dd8b26b9579fb6d8fab77155c588f2c641e105f6..4e329695d5c183b8c56ad3d83e76a3a5df47ea06 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -325,7 +325,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var inAngularVelocity = outAngularVelocity * ModelData.Gears[Gear].Ratio; if (dryRun) { - if ((DataBus.DrivingBehavior == DrivingBehavior.Braking || DataBus.DrivingBehavior == DrivingBehavior.Coasting) && + if ((DataBus.DriverBehavior == DrivingBehavior.Braking || DataBus.DriverBehavior == DrivingBehavior.Coasting) && inAngularVelocity < DataBus.EngineIdleSpeed && DataBus.VehicleSpeed < Constants.SimulationSettings.VehicleStopClutchDisengageSpeed) { Disengaged = true; _engageTime = absTime + dt; diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs index 56da631a8643bd136d1fac23e56144bc67990812..0dd0e1f6247dd2078c87ca06833fac65bc77b93c 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs @@ -279,7 +279,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <summary> /// Always Driving. /// </summary> - public DrivingBehavior DrivingBehavior + public DrivingBehavior DriverBehavior { get { return DrivingBehavior.Driving; } } @@ -529,7 +529,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl get { return !_isInitializing && LeftSample.Current.VehicleTargetSpeed.IsEqual(0); } } - public DrivingBehavior DrivingBehavior + public DrivingBehavior DriverBehavior { get { return DrivingBehavior.Driving; } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index 0e9887378cf840f5c2c8bc7536138ab4d4b70afa..1b691725ab1b27ffdeccd2dc117ba5931db8948c 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -132,6 +132,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl get { return PreviousState.Velocity; } } + public bool VehicleStopped + { + get { return PreviousState.Velocity.IsEqual(0.SI<MeterPerSecond>(), 0.01.SI<MeterPerSecond>()); } + } + public Kilogram VehicleMass { get { return ModelData.TotalCurbWeight(); } diff --git a/VectoCore/VectoCore/Utils/DebugData.cs b/VectoCore/VectoCore/Utils/DebugData.cs index 0fbb2162c37d201a20bdf9ed8c4883ea8cd7c2b6..3f2d5a9602aba4d675a5d651488828752727c23a 100644 --- a/VectoCore/VectoCore/Utils/DebugData.cs +++ b/VectoCore/VectoCore/Utils/DebugData.cs @@ -5,26 +5,26 @@ namespace TUGraz.VectoCore.Utils { public class DebugData { - private readonly List<dynamic> _data; + internal readonly List<dynamic> Data; public DebugData() { - #if DEBUG - _data = new List<dynamic>(); - #endif +#if DEBUG + Data = new List<dynamic>(); +#endif } [Conditional("DEBUG")] public void Add(dynamic value) { - _data.Add(value); + Data.Add(value); } public override string ToString() { - #if DEBUG - return string.Join("\n", _data); - #else +#if DEBUG + return string.Join("\n", Data); +#else return "-"; #endif } diff --git a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs index cfedec50649e510bfaf5782f843bd37f3b390930..84d53f136d5bb61a44db72f3916be2eec5e637b7 100644 --- a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs +++ b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs @@ -30,10 +30,13 @@ */ using System; +using System.Data; +using System.Linq; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Connector.Ports.Impl; namespace TUGraz.VectoCore.Utils { @@ -52,7 +55,7 @@ namespace TUGraz.VectoCore.Utils Func<object, double> criterion) where T : SIBase<T> { var iterationCount = 0; - return Search(x, y, interval, getYValue, evaluateFunction, criterion, ref iterationCount); + return Search(x, y, interval, getYValue, evaluateFunction, criterion, null, ref iterationCount); } /// <summary> @@ -62,18 +65,38 @@ namespace TUGraz.VectoCore.Utils /// getYValue: result => ((ResponseDryRun)result).Delta, /// evaluateFunction: x => NextComponent.Request(absTime, dt, x, gradient, true), /// criterion: result => ((ResponseDryRun)result).Delta); + /// abortCriterion: result => true/false + /// </code> + /// </summary> + public static T Search<T>(T x, SI y, T interval, Func<object, SI> getYValue, Func<T, object> evaluateFunction, + Func<object, double> criterion, Func<object, int, bool> abortCriterion) where T : SIBase<T> + { + var iterationCount = 0; + return Search(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, ref iterationCount); + } + + /// <summary> + /// Applies a numerical search over the evaluateFunction until the criterion reaches approximately 0. + /// <code> + /// SearchAlgorithm.Search(firstAcceleration, firstDelta, secondAccelerationInterval, + /// getYValue: result => ((ResponseDryRun)result).Delta, + /// evaluateFunction: x => NextComponent.Request(absTime, dt, x, gradient, true), + /// criterion: result => ((ResponseDryRun)result).Delta); + /// abortCriterion: result => true/false /// </code> /// </summary> public static T Search<T>(T x, SI y, T interval, Func<object, SI> getYValue, - Func<T, object> evaluateFunction, Func<object, double> criterion, ref int iterationCount) where T : SIBase<T> + Func<T, object> evaluateFunction, Func<object, double> criterion, Func<object, int, bool> abortCriterion, + ref int iterationCount) where T : SIBase<T> { T result; try { - result = InterpolateLinear(x, y, interval, getYValue, evaluateFunction, criterion, ref iterationCount); + result = InterpolateLinear(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, + ref iterationCount); } catch (VectoException ex) { var log = LogManager.GetLogger(typeof(SearchAlgorithm).FullName); log.Debug("Falling back to LineSearch. InterpolationSearch failed: " + ex.Message); - result = LineSearch(x, y, interval, getYValue, evaluateFunction, criterion, ref iterationCount); + result = LineSearch(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, ref iterationCount); } return result; } @@ -84,8 +107,8 @@ namespace TUGraz.VectoCore.Utils /// Phase 1: Linear Bracketing: Search iterative for the area of interest (with fixed step size). /// Phase 2: Binary Sectioning: Binary search in the area of interest. /// </summary> - private static T LineSearch<T>(T x, SI y, T interval, Func<object, SI> getYValue, - Func<T, object> evaluateFunction, Func<object, double> criterion, ref int iterationCount) where T : SIBase<T> + private static T LineSearch<T>(T x, SI y, T interval, Func<object, SI> getYValue, Func<T, object> evaluateFunction, + Func<object, double> criterion, Func<object, int, bool> abortCriterion, ref int iterationCount) where T : SIBase<T> { var log = LogManager.GetLogger(typeof(SearchAlgorithm).FullName); @@ -96,9 +119,7 @@ namespace TUGraz.VectoCore.Utils log.Debug("Log Disabled during Search LineSearch."); LogManager.DisableLogging(); try { - for (var count = 1; count < 100; count++) { - debug.Add(new { x, y }); - + for (var count = 1; count < 100; count++, iterationCount++) { if (origY.Sign() != y.Sign()) { intervalFactor = 0.5; } @@ -107,23 +128,32 @@ namespace TUGraz.VectoCore.Utils x += interval * -y.Sign(); var result = evaluateFunction(x); + debug.Add(new { x, y, delta = criterion(result), result }); if (criterion(result).IsEqual(0, Constants.SimulationSettings.LineSearchTolerance)) { LogManager.EnableLogging(); log.Debug("LineSearch found an operating point after {0} function calls.", count); - iterationCount += count; + //iterationCount += count; LogManager.DisableLogging(); return x; } + if (abortCriterion != null && abortCriterion(result, iterationCount)) { + LogManager.EnableLogging(); + log.Debug("LineSearch aborted due to abortCriterion: {0}", result); + LogManager.DisableLogging(); + throw new VectoSearchAbortedException("LineSearch"); + } y = getYValue(result); } } finally { LogManager.EnableLogging(); } - iterationCount += 100; + //iterationCount += 100; log.Debug("LineSearch could not find an operating point."); log.Error("Exceeded max iterations when searching for operating point!"); log.Error("debug: {0}", debug); + + //WriteSerach(debug, "LineSearch.csv"); throw new VectoSearchFailedException("Failed to find operating point! points: {0}", debug); } @@ -132,11 +162,12 @@ namespace TUGraz.VectoCore.Utils /// Calculates linear equation of 2 points and jumps directly to root-point. /// </summary> private static T InterpolateLinear<T>(T x1, SI y1, T interval, Func<object, SI> getYValue, - Func<T, object> evaluateFunction, Func<object, double> criterion, ref int iterationCount) where T : SIBase<T> + Func<T, object> evaluateFunction, Func<object, double> criterion, Func<object, int, bool> abortCriterion, + ref int iterationCount) where T : SIBase<T> { var log = LogManager.GetLogger(typeof(SearchAlgorithm).FullName); - var debug = new DebugData(); - debug.Add(new { x = x1, y = y1 } ); + var debug = new DebugData(); + debug.Add(new { x = x1, y = y1 }); log.Debug("Log Disabled during Search InterpolateLinear."); LogManager.DisableLogging(); try { @@ -150,9 +181,9 @@ namespace TUGraz.VectoCore.Utils return x2; } - for (var count = 2; count < 30; count++) { + for (var count = 2; count < 30; count++, iterationCount++) { var y2 = getYValue(result); - debug.Add(new { x = x2, y = y2 }); + debug.Add(new { x = x2, y = y2, delta = criterion(result), result }); try { var k = (y2 - y1) / (x2 - x1); @@ -163,35 +194,70 @@ namespace TUGraz.VectoCore.Utils if (!(ex.InnerException is DivideByZeroException)) { throw; } - debug.Add(new { x = x2, y = getYValue(result) }); + debug.Add(new { x = x2, y = getYValue(result), delta = criterion(result), result }); LogManager.EnableLogging(); log.Debug("InterpolateLinear could not get more exact. Aborting after {0} function calls.", count); LogManager.DisableLogging(); - iterationCount += count; + //iterationCount += count; return x2; } result = evaluateFunction(x2); if (criterion(result).IsEqual(0, Constants.SimulationSettings.InterpolateSearchTolerance)) { - debug.Add(new { x = x2, y = getYValue(result) }); + debug.Add(new { x = x2, y = getYValue(result), delta = criterion(result), result }); LogManager.EnableLogging(); log.Debug("InterpolateLinear found an operating point after {0} function calls.", count); LogManager.DisableLogging(); - iterationCount += count; + //iterationCount += count; return x2; } - + if (abortCriterion != null && abortCriterion(result, iterationCount)) { + LogManager.EnableLogging(); + log.Debug("LineSearch aborted due to abortCriterion: {0}", result); + LogManager.DisableLogging(); + throw new VectoSearchAbortedException("InterpolateLinearSearch"); + } y1 = y2; } } finally { LogManager.EnableLogging(); } - iterationCount += 30; + //iterationCount += 30; log.Debug("InterpolateLinear could not find an operating point."); log.Error("Exceeded max iterations when searching for operating point!"); log.Error("debug: {0}", debug); + + //WriteSerach(debug, "InterpolateSearch.csv"); throw new VectoSearchFailedException("Failed to find operating point! points: {0}", debug); } + + private static void WriteSerach(DebugData debug, string filename) + { + var table = new DataTable(); + table.Columns.Add("x", typeof(double)); + table.Columns.Add("y", typeof(double)); + table.Columns.Add("delta", typeof(double)); + table.Columns.Add("AuxPower", typeof(double)); + table.Columns.Add("engineSpeed", typeof(double)); + table.Columns.Add("enginePower", typeof(double)); + + foreach (var entry in debug.Data.Skip(1)) { + var response = entry.result as ResponseDryRun; + if (response == null) { + continue; + } + var row = table.NewRow(); + row["x"] = entry.x.Value(); + row["y"] = entry.y.Value(); + row["delta"] = entry.delta; + row["AuxPower"] = response.AuxiliariesPowerDemand == null ? -1 : response.AuxiliariesPowerDemand.Value(); + row["engineSpeed"] = response.EngineSpeed == null ? -1 : response.EngineSpeed.Value(); + row["enginePower"] = response.EnginePowerRequest == null ? -1 : response.EnginePowerRequest.Value(); + + table.Rows.Add(row); + } + VectoCSVFile.Write(filename, table); + } } } \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/AuxDemandTest.cs b/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/AuxDemandTest.cs index 382d54ab8b22242674010f102aff01384d71769a..909a95383bf8e196c757a388c5984dbb0c2211ce 100644 --- a/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/AuxDemandTest.cs +++ b/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/AuxDemandTest.cs @@ -16,9 +16,9 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries public class AuxDemandTest { [Test] - [TestCase(12000, 1256, 148, 148, 6087.0317)] - [TestCase(12000, 1256, -15, -50, 8954.1435)] - [TestCase(15700, 1319, -35.79263, -144.0441, 9093.9511)] + [TestCase(12000, 1256, 148, 148, 6086.9321)] + [TestCase(12000, 1256, -15, -50, 8954.1396)] + [TestCase(15700, 1319, -35.79263, -144.0441, 9093.9473)] public void AuxDemandtest(double vehicleWeight, double engineSpeedRpm, double driveLinePower, double internalPower, double expectedPowerDemand) { @@ -54,7 +54,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries for (int i = 0; i < 10; i++) { var torque = busAux.PowerDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); - Assert.AreEqual(6087.0317, (torque * engineSpeed).Value(), 1e-3); + Assert.AreEqual(6086.9321, (torque * engineSpeed).Value(), 1e-3); busAux.CommitSimulationStep(modalData); } @@ -66,7 +66,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries for (int i = 0; i < 10; i++) { var torque = busAux.PowerDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); - Assert.AreEqual(8954.1435, (torque * engineSpeed).Value(), 1e-3); + Assert.AreEqual(8954.1396, (torque * engineSpeed).Value(), 1e-3); busAux.CommitSimulationStep(modalData); } @@ -78,11 +78,11 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries for (int i = 0; i < 10; i++) { var torque = busAux.PowerDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); - Assert.AreEqual(6087.0317, (torque * engineSpeed).Value(), 1e-3); + Assert.AreEqual(6086.9321, (torque * engineSpeed).Value(), 1e-3); busAux.CommitSimulationStep(modalData); } - Assert.AreEqual(162.4655, ((SI)modalData[ModalResultField.AA_TotalCycleFC_Grams]).Value(), 0.0001); + Assert.AreEqual(162.4654, ((SI)modalData[ModalResultField.AA_TotalCycleFC_Grams]).Value(), 0.0001); } public static BusAuxiliariesAdapter CreateBusAuxAdapterForTesting(double vehicleWeight, out MockDriver driver) @@ -102,9 +102,10 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries var engine = new CombustionEngine(vehicle, modelData); //new Vehicle(vehicle, new VehicleData()); - driver = new MockDriver(vehicle) { VehicleStopped = false, DrivingBehavior = DrivingBehavior.Braking }; + driver = new MockDriver(vehicle) { VehicleStopped = false, DriverBehavior = DrivingBehavior.Braking }; var gbx = new MockGearbox(vehicle) { Gear = 1 }; var brakes = new MockBrakes(vehicle); + var veh = new MockVehicle(vehicle) { MyVehicleSpeed = 50.KMPHtoMeterPerSecond() }; var busAux = new BusAuxiliariesAdapter(vehicle, auxFilePath, "Coach", vehicleWeight.SI<Kilogram>(), fcMap, modelData.IdleSpeed); return busAux; diff --git a/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/BusAdapterTest.cs b/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/BusAdapterTest.cs index e9a82a572079d7203f54421ef24c0e86ebca6836..ded48f6a37a6c0078fab724efa636ddf68755787 100644 --- a/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/BusAdapterTest.cs +++ b/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/BusAdapterTest.cs @@ -1,7 +1,11 @@ -using NUnit.Framework; +using System.Data; +using NUnit.Framework; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Simulation.DataBus; +using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Tests.Utils; +using TUGraz.VectoCore.Utils; using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries @@ -10,19 +14,19 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries public class BusAdapterTest { [Test] - [TestCase(12000, 1256, 148, 148, 6087.0317)] - [TestCase(12000, 1256, -48, -148, 6087.0317)] - [TestCase(12000, 1256, 48, -148, 6087.0317)] - [TestCase(12000, 800, 148, 148, 6377.2026)] - [TestCase(12000, 800, -48, -148, 6377.2026)] - [TestCase(12000, 800, 48, -148, 6377.2026)] + [TestCase(12000, 1256, 148, 148, 6086.9321)] + [TestCase(12000, 1256, -48, -148, 6086.9321)] + [TestCase(12000, 1256, 48, -148, 6086.9321)] + [TestCase(12000, 800, 148, 148, 6377.0923)] + [TestCase(12000, 800, -48, -148, 6377.0923)] + [TestCase(12000, 800, 48, -148, 6377.0923)] public void TestNoSmartAuxDuringDrive(double vehicleWeight, double engineSpeedRpm, double driveLinePower, double internalPower, double expectedPowerDemand) { MockDriver driver; var busAux = AuxDemandTest.CreateBusAuxAdapterForTesting(vehicleWeight, out driver); - driver.DrivingBehavior = DrivingBehavior.Driving; + driver.DriverBehavior = DrivingBehavior.Driving; var engineDrivelinePower = (driveLinePower * 1000).SI<Watt>(); var engineSpeed = engineSpeedRpm.RPMtoRad(); @@ -35,16 +39,16 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries } [Test] - [TestCase(12000, 1256, 148, 148, 6087.0317)] - [TestCase(12000, 1256, -28, -27, 6087.0317)] - [TestCase(12000, 1256, -28, -29, 6087.0317)] - [TestCase(12000, 1256, -128, -28, 6087.0317)] - [TestCase(12000, 1256, 28, -28, 6087.0317)] - [TestCase(12000, 800, 148, 148, 6377.2026)] - [TestCase(12000, 800, -14, -13, 6377.2026)] - [TestCase(12000, 800, -14, -15, 6377.2026)] - [TestCase(12000, 800, -35, -14, 6377.2026)] - [TestCase(12000, 800, 35, -14, 6377.2026)] + [TestCase(12000, 1256, 148, 148, 6086.9321)] + [TestCase(12000, 1256, -28, -27, 6086.9321)] + [TestCase(12000, 1256, -28, -29, 6086.9321)] + [TestCase(12000, 1256, -128, -28, 6086.9321)] + [TestCase(12000, 1256, 28, -28, 6086.9321)] + [TestCase(12000, 800, 148, 148, 6377.0923)] + [TestCase(12000, 800, -14, -13, 6377.0923)] + [TestCase(12000, 800, -14, -15, 6377.0923)] + [TestCase(12000, 800, -35, -14, 6377.0923)] + [TestCase(12000, 800, 35, -14, 6377.0923)] public void TestNoSmartAuxDuringCoasting(double vehicleWeight, double engineSpeedRpm, double driveLinePower, double internalPower, double expectedPowerDemand) { @@ -54,7 +58,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries MockDriver driver; var busAux = AuxDemandTest.CreateBusAuxAdapterForTesting(vehicleWeight, out driver); - driver.DrivingBehavior = DrivingBehavior.Coasting; + driver.DriverBehavior = DrivingBehavior.Coasting; var engineDrivelinePower = (driveLinePower * 1000).SI<Watt>(); var engineSpeed = engineSpeedRpm.RPMtoRad(); @@ -67,17 +71,17 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries } [Test] - [TestCase(12000, 1256, -48, -148, 8954.14355)] - [TestCase(12000, 1256, 48, -148, 8954.14355)] - [TestCase(12000, 800, -48, -148, 8281.51367)] - [TestCase(12000, 800, 48, -148, 8281.51367)] + [TestCase(12000, 1256, -48, -148, 8954.1396)] + [TestCase(12000, 1256, 48, -148, 8954.1396)] + [TestCase(12000, 800, -48, -148, 8281.5088)] + [TestCase(12000, 800, 48, -148, 8281.5088)] public void TestSmartAuxDuringBrake(double vehicleWeight, double engineSpeedRpm, double driveLinePower, double internalPower, double expectedPowerDemand) { MockDriver driver; var busAux = AuxDemandTest.CreateBusAuxAdapterForTesting(vehicleWeight, out driver); - driver.DrivingBehavior = DrivingBehavior.Braking; + driver.DriverBehavior = DrivingBehavior.Braking; var engineDrivelinePower = (driveLinePower * 1000).SI<Watt>(); var engineSpeed = engineSpeedRpm.RPMtoRad(); @@ -88,5 +92,52 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries Assert.AreEqual(expectedPowerDemand, (torque * engineSpeed).Value(), 1e-3); } + + + [Test, + TestCase(19000)] + public void AuxDemandContinuityTest(double vehicleWeight) + { + MockDriver driver; + var busAux = AuxDemandTest.CreateBusAuxAdapterForTesting(vehicleWeight, out driver); + + driver.DriverBehavior = DrivingBehavior.Driving; + + //var engineSpeedRpm = 1375.1014; + + var table = new DataTable(); + table.Columns.Add("engineSpeed", typeof(double)); + table.Columns.Add("auxPowerDemand", typeof(double)); + + for (var engineSpeedRpm = 1370.0; engineSpeedRpm < 1380; engineSpeedRpm += 1e-3) { + var driveLinePower = 2200.0; + var internalPower = driveLinePower + 43; + + var engineDrivelinePower = driveLinePower.SI<Watt>(); + var engineSpeed = engineSpeedRpm.RPMtoRad(); + busAux.Initialize(engineDrivelinePower / engineSpeed, engineSpeed); + + var torque = busAux.PowerDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, + (internalPower).SI<Watt>() / engineSpeed, engineSpeed); + + var row = table.NewRow(); + row["engineSpeed"] = engineSpeed.Value() / Constants.RPMToRad; + row["auxPowerDemand"] = (torque * engineSpeed).Value(); + table.Rows.Add(row); + } + var pt1 = new Point((double)(table.Rows[0]["engineSpeed"]), (double)(table.Rows[0]["auxPowerDemand"])); + var pt2 = new Point((double)(table.Rows[table.Rows.Count - 1]["engineSpeed"]), + (double)(table.Rows[table.Rows.Count - 1]["auxPowerDemand"])); + var edge = new Edge(pt1, pt2); + var slope = edge.SlopeXY; + var offset = edge.OffsetXY; + foreach (DataRow row in table.Rows) { + var expected = (double)row["engineSpeed"] * slope + offset; + Assert.AreEqual(expected, (double)row["auxPowerDemand"], 0.1); + } + + //VectoCSVFile.Write("auxPowerDemand_EngineSpeed.csv", table); + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs index 70ebc9276adb5c79f05531c01dd9fcacd9a2bf2c..c9a45f3360a549bda202212f53784378bbb8f35d 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs @@ -32,6 +32,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Simulation.DataBus; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.Tests.Utils; @@ -73,14 +74,15 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(62.119969, outPort.AngularVelocity.Value(), 0.001); //Test - Clutch opened - driver.VehicleStopped = true; + driver.DriverBehavior = DrivingBehavior.Halted; // = 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 - driver.VehicleStopped = false; + driver.DriverBehavior = DrivingBehavior.Driving; // = false; clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), 100.SI<NewtonMeter>(), 80.SI<PerSecond>()); Assert.AreEqual(100.0, outPort.Torque.Value(), 0.001); diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs index 2e181de6cc9d058c1a2a950b4da98ef9d9e01a2c..b906316bae7319f70090af915b3ebe701a295d2b 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs @@ -137,6 +137,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var container = new VehicleContainer(ExecutionMode.Engineering); var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); var driver = new MockDriver(container); + var vehicle = new MockVehicle(container) { MyVehicleSpeed = 0.KMPHtoMeterPerSecond() }; + var port = new MockTnOutPort(); gearbox.InPort().Connect(port); container.Engine = port; @@ -174,6 +176,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var container = new VehicleContainer(ExecutionMode.Declaration); var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); var driver = new MockDriver(container); + var vehicle = new MockVehicle(container) { MyVehicleSpeed = 0.KMPHtoMeterPerSecond() }; + var port = new MockTnOutPort(); gearbox.InPort().Connect(port); container.Engine = port; @@ -211,6 +215,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var container = new VehicleContainer(executionMode: ExecutionMode.Engineering); var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); var driver = new MockDriver(container); + var vehicle = new MockVehicle(container) { MyVehicleSpeed = 0.KMPHtoMeterPerSecond() }; + var port = new MockTnOutPort(); gearbox.InPort().Connect(port); container.Engine = port; @@ -248,6 +254,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var container = new VehicleContainer(ExecutionMode.Engineering); var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); var driver = new MockDriver(container); + var vehicle = new MockVehicle(container) { MyVehicleSpeed = 0.KMPHtoMeterPerSecond() }; + var port = new MockTnOutPort(); gearbox.InPort().Connect(port); container.Engine = port; @@ -295,6 +303,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var container = new VehicleContainer(ExecutionMode.Engineering); var gearboxData = MockSimulationDataFactory.CreateGearboxDataFromFile(GearboxDataFile, EngineDataFile); var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); + var vehicle = new MockVehicle(container) { MyVehicleSpeed = 0.KMPHtoMeterPerSecond() }; var driver = new MockDriver(container); var port = new MockTnOutPort(); @@ -343,6 +352,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); var driver = new MockDriver(container); + var vehicle = new MockVehicle(container) { MyVehicleSpeed = 0.KMPHtoMeterPerSecond() }; var port = new MockTnOutPort(); gearbox.InPort().Connect(port); diff --git a/VectoCore/VectoCoreTest/Utils/MockDriver.cs b/VectoCore/VectoCoreTest/Utils/MockDriver.cs index 63fa1f11f57d95c673695648ed29d377581f0b8d..d0a0d1a76f8dc5a81fbc75b28fbb6467a78d9f9d 100644 --- a/VectoCore/VectoCoreTest/Utils/MockDriver.cs +++ b/VectoCore/VectoCoreTest/Utils/MockDriver.cs @@ -48,7 +48,7 @@ namespace TUGraz.VectoCore.Tests.Utils public MockDriver(IVehicleContainer container) : base(container) { - DrivingBehavior = DrivingBehavior.Accelerating; + DriverBehavior = DrivingBehavior.Accelerating; } protected override void DoWriteModalResults(IModalDataContainer container) {} @@ -116,6 +116,6 @@ namespace TUGraz.VectoCore.Tests.Utils public bool VehicleStopped { get; set; } - public DrivingBehavior DrivingBehavior { get; set; } + public DrivingBehavior DriverBehavior { get; set; } } } \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/Utils/MockVairVehicleContainer.cs b/VectoCore/VectoCoreTest/Utils/MockVairVehicleContainer.cs index 913b4b3a1f77e7f0706923114e66a00cc3088c6a..16563f53e148abd3aa093cd0d4cdbdaedf2b7a99 100644 --- a/VectoCore/VectoCoreTest/Utils/MockVairVehicleContainer.cs +++ b/VectoCore/VectoCoreTest/Utils/MockVairVehicleContainer.cs @@ -90,7 +90,7 @@ namespace TUGraz.VectoCore.Tests.Utils } public bool VehicleStopped { get; private set; } - public DrivingBehavior DrivingBehavior { get; private set; } + public DrivingBehavior DriverBehavior { get; private set; } public CycleData CycleData { get; set; } public ExecutionMode ExecutionMode { get; set; } public IModalDataContainer ModalData { get; private set; } diff --git a/VectoCore/VectoCoreTest/Utils/MockVehicle.cs b/VectoCore/VectoCoreTest/Utils/MockVehicle.cs index 10c1fe25b3d53eb12ed013e34d978de69c0be6e3..44081233f8abf1160c12284ef332c6e494008b8f 100644 --- a/VectoCore/VectoCoreTest/Utils/MockVehicle.cs +++ b/VectoCore/VectoCoreTest/Utils/MockVehicle.cs @@ -68,6 +68,11 @@ namespace TUGraz.VectoCore.Tests.Utils get { return MyVehicleSpeed; } } + public bool VehicleStopped + { + get { return MyVehicleSpeed.IsEqual(0.SI<MeterPerSecond>(), 0.01.SI<MeterPerSecond>()); } + } + public Kilogram VehicleMass { get { return 7500.SI<Kilogram>(); } @@ -96,7 +101,7 @@ namespace TUGraz.VectoCore.Tests.Utils acceleration = acceleration, gradient = gradient }; - return new ResponseSuccess() { Source = this}; + return new ResponseSuccess() { Source = this }; } public IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient)