Continuing rewriting engine
This commit is contained in:
57
koptilnya/engine_remastered/clutch.txt
Normal file
57
koptilnya/engine_remastered/clutch.txt
Normal file
@@ -0,0 +1,57 @@
|
||||
-- @include ./wire_component.txt
|
||||
-- @include ./enums/gearbox.txt
|
||||
require('./wire_component.txt')
|
||||
local gearboxTypes = require('./enums/gearbox.txt')
|
||||
|
||||
Clutch = class('Clutch', WireComponent)
|
||||
|
||||
function Clutch:initialize(config)
|
||||
self.stiffness = config.Stiffness
|
||||
self.damping = config.Damping
|
||||
self.maxTorque = config.MaxTorque
|
||||
|
||||
self.press = 0
|
||||
self.slip = 0
|
||||
self.targetTorque = 0
|
||||
self.torque = 0
|
||||
|
||||
self._engine = nil
|
||||
self._gearbox = nil
|
||||
end
|
||||
|
||||
function Clutch:linkEngine(eng)
|
||||
self._engine = eng
|
||||
end
|
||||
|
||||
function Clutch:linkGearbox(gbox)
|
||||
self._gearbox = gbox
|
||||
end
|
||||
|
||||
function Clutch:getInputs()
|
||||
return {}
|
||||
end
|
||||
|
||||
function Clutch:getOutputs()
|
||||
return {
|
||||
ClutchTorque = 'number',
|
||||
ClutchSlip = 'number'
|
||||
}
|
||||
end
|
||||
|
||||
function Clutch:update()
|
||||
if self._gearbox.type == gearboxTypes.MANUAL then
|
||||
self.press = wire.ports.Clutch
|
||||
end
|
||||
|
||||
local someConversionCoeff = 0.10472
|
||||
|
||||
local engRPM = self._engine and self._engine.rpm or 0
|
||||
local gboxRPM = self._gearbox and self._gearbox.rpm or 0
|
||||
local gboxRatio = self._gearbox and self._gearbox.ratio or 0
|
||||
local gboxRatioNotZero = gboxRatio ~= 0 and 1 or 0
|
||||
|
||||
self.slip = ((engRPM - gboxRPM) * someConversionCoeff) * gboxRatioNotZero / 2
|
||||
self.targetTorque = math.clamp(self.slip * self.stiffness * (1 - self.press), -self.maxTorque, self.maxTorque)
|
||||
|
||||
self.torque = math.lerp(self.damping, self.torque, self.targetTorque)
|
||||
end
|
||||
Reference in New Issue
Block a user