added type configuration for differential
This commit is contained in:
@@ -9,6 +9,10 @@ require('/koptilnya/libs/constants.txt')
|
||||
|
||||
local Differential = class('Differential', PowertrainComponent)
|
||||
|
||||
function Differential.getSplitStrategy(type)
|
||||
return SPLIT_STRATEGIES[type] or SPLIT_STRATEGIES[Differential.TYPES.Open]
|
||||
end
|
||||
|
||||
function Differential:initialize(vehicle, name, config)
|
||||
PowertrainComponent.initialize(self, vehicle, name, config)
|
||||
|
||||
@@ -24,6 +28,7 @@ function Differential:initialize(vehicle, name, config)
|
||||
self.preload = config.Preload or 10
|
||||
self.stiffness = config.Stiffness or 0.1
|
||||
self.slipTorque = config.SlipTorque or 1000
|
||||
self.splitStrategy = Differential.getSplitStrategy(config.Type or Differential.TYPES.Open)
|
||||
end
|
||||
|
||||
function Differential:linkComponent(component)
|
||||
@@ -85,7 +90,7 @@ function Differential:forwardStep(torque, inertia)
|
||||
|
||||
self.torque = torque * self.finalDrive
|
||||
|
||||
local tqA, tqB = self:_openDiffTorqueSplit(
|
||||
local tqA, tqB = self:splitStrategy(
|
||||
self.torque,
|
||||
aW,
|
||||
bW,
|
||||
@@ -156,4 +161,18 @@ function Differential:_HLSDTorqueSplit(tq, aW, bW, aI, bI, biasAB, preload, stif
|
||||
return tq * (1 - biasAB) - dTq, tq * biasAB + dTq
|
||||
end
|
||||
|
||||
Differential.TYPES = {
|
||||
Open = 'Open',
|
||||
Locking = 'Locking',
|
||||
VLSD = 'VLSD',
|
||||
HLSD = 'HLSD',
|
||||
}
|
||||
|
||||
SPLIT_STRATEGIES = {
|
||||
[Differential.TYPES.Open] = Differential._openDiffTorqueSplit,
|
||||
[Differential.TYPES.Locking] = Differential._lockingDiffTorqueSplit,
|
||||
[Differential.TYPES.VLSD] = Differential._VLSDTorqueSplit,
|
||||
[Differential.TYPES.HLSD] = Differential._HLSDTorqueSplit,
|
||||
}
|
||||
|
||||
return Differential
|
||||
|
||||
Reference in New Issue
Block a user