Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 9df913fc authored by Terry Burns's avatar Terry Burns Committed by Kostis ANAGNOSTOPOULOS
Browse files
parent 9ba8e11f
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,11 @@ Public Class Alternator
'TODO: Calculate Efficiency
'Calculate ( Interpolate ) Efficiency
Dim range as List(Of AltUserInput) = RangeTable.Select( Function(s) New AltUserInput(s.RPM,s.Efficiency)).ToList()
Dim v As Single = Alternator.Iterpolate( range, SpindleSpeed)
Return v
End Get
......@@ -87,18 +92,18 @@ Public Class Alternator
CreateRangeTable()
InitialiseRangeTable()
'InitialiseRangeTable()
End Sub
Private Function Iterpolate( values As List(Of AltUserInput), x As single) As Single
Public shared Function Iterpolate( values As List(Of AltUserInput), x As single) As Single
Dim lowestX As single = values.Min( Function(m) m.Amps)
Dim highestX As Single = values.Max( Function(m) m.Amps)
Dim lastX, nextX ,lastEff,NextEff As single
Dim deltaX As single
Dim slope As single
Dim preKey, postKey ,preEff,postEff, EffSlope As single
Dim deltaX , deltaEff As single
'Out of range, returns efficiency for lowest
If x< lowestX then Return values.First( Function(f) f.Amps= lowestX).Eff
......@@ -111,26 +116,96 @@ Public Class Alternator
'OK, we need to interpolate.
lastX = values.Last( Function(l) l.Amps < x).Amps
nextX = values.First( Function(l) l.Amps > x).Amps
lastEff = values.First( Function(f) f.Amps=lastX).Eff
nextEff = values.First( Function(f) f.Amps=nextX).Eff
preKey = values.Last( Function(l) l.Amps < x).Amps
postKey = values.First( Function(l) l.Amps > x).Amps
preEff = values.First( Function(f) f.Amps=preKey).Eff
postEff = values.First( Function(f) f.Amps=postKey).Eff
deltaX = nextX-lastX
slope = NextEff/lastEff
deltaX = postKey-preKey
deltaEff = postEff-preEff
Return lastEff + ( NextEff * slope)
'slopes
effSlope = deltaEff/deltaX
Dim retVal As Single = ((x - preKey) * effSlope) + preEff
Return retVal
End Function
Private Sub CalculateRangeTable()
'TODO: CALCULATE RANGE TABLE
'M10=Row0-Rpm - N10=Row0-Eff
'M11=Row1-Rpm - N11=Row1-Eff
'M12=Row2-Rpm - N12=Row2-Eff - 2000
'M13=Row3-Rpm - N13=Row3-Eff - 4000
'M14=Row4-Rpm - N14=Row4-Eff - 6000
'M15=Row5-Rpm - N15=Row5-Eff
'M16=Row6-Rpm - N16=Row6-Eff
Dim N10,N11,N12,N13,N14,N15,N16 As single
Dim M10,M11,M12,M13,M14,M15,M16 As single
'EFFICIENCY
'2000
N12= Alternator.Iterpolate(InputTable2000,signals.CurrentDemandAmps)
RangeTable(2).Efficiency= N12
'4000
N13 = Alternator.Iterpolate(InputTable4000,signals.CurrentDemandAmps)
RangeTable(3).Efficiency= N13
'6000
N14 =Alternator.Iterpolate(InputTable6000,signals.CurrentDemandAmps)
RangeTable(4).Efficiency= N14
'Row0 & Row1 Efficiency =IF(N13>N12,0,MAX(N12:N14)) - Example Alt 1 N13=
N11=IF(N13>N12,0,Math.Max(Math.MAX(N12,N13),N14))
RangeTable(1).Efficiency = N11
N10=N11
RangeTable(0).Efficiency = N10
'Row 5 Efficiency
N15 =IF(N13>N14,0,Math.Max(Math.MAX(N12,N13),N14))
RangeTable(5).Efficiency = N15
'Row 6 - Efficiency
N16 = N15
RangeTable(6).Efficiency = N16
'RPM
'2000 Row 2 - RPM
M12 = 2000
RangeTable(2).RPM = M12
'4000 Row 3 - RPM
M13 = 4000
RangeTable(3).RPM = M13
'6000 Row 4 - RPM
M14 = 6000
RangeTable(4).RPM = M14
'Row 1 - RPM
M11 = IF(M12=IF(N12>N13,M12-((M12-M13)/(N12-N13))*(N12-N11),M12-((M12-M13)/(N12-N13))*(N12-N11)), M12-0.01, IF(N12>N13,M12-((M12-M13)/(N12-N13))*(N12-N11),M12-((M12-M13)/(N12-N13))*(N12-N11)))
RangeTable(1).RPM =M11
'Row 0 - RPM
M10 = IF(M11<1500,M11-1,1500)
RangeTable(0).RPM = M10
'Row 5 - RPM
M15 = IF(M14=IF((N14=0 OrElse N14=N13),M14+1,IF(N13>N14,((((M14-M13)/(N13-N14))*N14)+M14),((((M14-M13)/(N13-N14))*(N14-N15))+M14))),M14+0.01,IF((N14=0 OrElse N14=N13),M14+1,IF(N13>N14,((((M14-M13)/(N13-N14))*N14)+M14),((((M14-M13)/(N13-N14))*(N14-N15))+M14))))
RangeTable(5).RPM = M15
'Row 6 - RPM
M16 = IF(M15>10000,M15+1,10000)
RangeTable(6).RPM = M16
End Sub
......
......@@ -29,7 +29,16 @@ Public Class CombinedAlternator
Public Function GetEfficiency( CrankRPM As Single , AmpsDemand As Single ) As Single
altSignals.CrankRPM = CrankRPM
altSignals.CurrentDemandAmps = AmpsDemand
altSignals.CurrentDemandAmps = AmpsDemand / Alternators.Count
Dim Alt0Eff As Single = Alternators(0).Efficiency
Dim Alt1Eff As Single = Alternators(1).Efficiency
Dim Alt2Eff As Single = Alternators(2).Efficiency
Dim Alt3Eff As Single = Alternators(3).Efficiency
Return Alternators.Average( Function(a) a.Efficiency)
......@@ -47,7 +56,7 @@ Public Class CombinedAlternator
End If
Me.altSignals= altSignals
Me.altSignals= New CombinedAlternatorSignals()
'IF file exists then read it otherwise create a default.
......
......@@ -125,7 +125,6 @@
<Compile Include="Electrics\IM2_AverageElectricalLoadDemand.vb" />
<Compile Include="Electrics\IM5_SmartAlternatorSetGeneration.vb" />
<Compile Include="Electrics\IncDecValuePair.vb" />
<Compile Include="Electrics\InterpAltUserInputs.vb" />
<Compile Include="Electrics\IResultCard.vb" />
<Compile Include="Electrics\M0_5_SmartAlternatorSetEfficiency.vb" />
<Compile Include="Electrics\M0_NonSmart_AlternatorsSetEfficiency.vb" />
......
......@@ -168,11 +168,11 @@ Namespace UnitTests
Select Case rpmK
Case 2
interpValue= InterpAltUserInputs.Iterpolate( Alt1ExpectedTable2000,42.5)
interpValue= Alternator.Iterpolate( Alt1ExpectedTable2000,42.5)
Case 4
interpValue= InterpAltUserInputs.Iterpolate( Alt1ExpectedTable4000,42.5)
interpValue= Alternator.Iterpolate( Alt1ExpectedTable4000,42.5)
Case 6
interpValue= InterpAltUserInputs.Iterpolate( Alt1ExpectedTable6000,42.5)
interpValue= Alternator.Iterpolate( Alt1ExpectedTable6000,42.5)
End Select
......@@ -182,11 +182,11 @@ Namespace UnitTests
Select Case rpmK
Case 2
interpValue= InterpAltUserInputs.Iterpolate( Alt2ExpectedTable2000,42.5)
interpValue= Alternator.Iterpolate( Alt2ExpectedTable2000,42.5)
Case 4
interpValue= InterpAltUserInputs.Iterpolate( Alt2ExpectedTable4000,42.5)
interpValue= Alternator.Iterpolate( Alt2ExpectedTable4000,42.5)
Case 6
interpValue= InterpAltUserInputs.Iterpolate( Alt2ExpectedTable6000,42.5)
interpValue= Alternator.Iterpolate( Alt2ExpectedTable6000,42.5)
End Select
......@@ -195,11 +195,11 @@ Namespace UnitTests
Select Case rpmK
Case 2
interpValue= InterpAltUserInputs.Iterpolate( Alt3ExpectedTable2000,42.5)
interpValue= Alternator.Iterpolate( Alt3ExpectedTable2000,42.5)
Case 4
interpValue= InterpAltUserInputs.Iterpolate( Alt3ExpectedTable4000,42.5)
interpValue= Alternator.Iterpolate( Alt3ExpectedTable4000,42.5)
Case 6
interpValue= InterpAltUserInputs.Iterpolate( Alt3ExpectedTable6000,42.5)
interpValue= Alternator.Iterpolate( Alt3ExpectedTable6000,42.5)
End Select
......@@ -208,11 +208,11 @@ Namespace UnitTests
Select Case rpmK
Case 2
interpValue= InterpAltUserInputs.Iterpolate( Alt4ExpectedTable2000,42.5)
interpValue= Alternator.Iterpolate( Alt4ExpectedTable2000,42.5)
Case 4
interpValue= InterpAltUserInputs.Iterpolate( Alt4ExpectedTable4000,42.5)
interpValue= Alternator.Iterpolate( Alt4ExpectedTable4000,42.5)
Case 6
interpValue= InterpAltUserInputs.Iterpolate( Alt4ExpectedTable6000,42.5)
interpValue= Alternator.Iterpolate( Alt4ExpectedTable6000,42.5)
End Select
......@@ -385,6 +385,21 @@ Namespace UnitTests
End Sub
<Test()>
Public Sub AveragedEfficiency( )
' Dim signals As ICombinedAlternatorSignals = New CombinedAlternatorSignals() With {.CrankRPM=1750, .CurrentDemandAmps=170}
Dim ca As new CombinedAlternator("abc.aalt", New CombinedAlternatorSignals() )
Dim actual As Single = ca.GetEfficiency(1750,170)
Assert.AreEqual(56.015625,actual)
End Sub
End Class
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment