Finished stuff with manual gearbox

This commit is contained in:
Ivan Grachyov
2021-11-13 01:52:35 +05:00
parent b5fb04cce8
commit 54202989c1
9 changed files with 190 additions and 97 deletions

View File

@@ -1,4 +1,7 @@
Gearbox = class('Gearbox')
-- @include ../wire_component.txt
require('../wire_component.txt')
Gearbox = class('Gearbox', WireComponent)
function Gearbox:initialize(config, clutch, axles)
self.ratios = config.Ratios
@@ -11,9 +14,40 @@ function Gearbox:initialize(config, clutch, axles)
self.axles = axles or {}
self.clutch = clutch
self.type = config.Type
clutch:linkGearbox(self)
for _, axle in pairs(axles) do
axle:linkGearbox(self)
end
self:recalcRatio()
end
function Gearbox:getInputs()
return {
Upshift = 'number',
Downshift = 'number'
}
end
function Gearbox:getOutputs()
return {
Gearbox_RPM = 'number',
Gearbox_Torque = 'number',
Gearbox_Gear = 'number',
Gearbox_Ratio = 'number'
}
end
function Gearbox:updateOutputs()
wire.ports.Gearbox_RPM = self.rpm
wire.ports.Gearbox_Torque = self.torque
wire.ports.Gearbox_Gear = self.gear
wire.ports.Gearbox_Ratio = self.ratio
end
function Gearbox:setGear(gear)
if gear >= -1 and gear <= #self.ratios then
self.gear = gear
@@ -36,14 +70,13 @@ function Gearbox:update()
self.torque = self.clutch.torque * self.ratio
end
local axlesRPM = table.map(self.axles, function(diff)
return diff.avgRPM
end)
local maxAxlesRPM = 0
local maxAxlesRPM = math.max(unpack(axlesRPM))
if #self.axles > 0 then
maxAxlesRPM = math.max(unpack(table.map(self.axles, function(diff)
return diff.avgRPM
end)))
end
self.rpm = maxAxlesRPM * self.ratio
end
function Gearbox:shift()
end
end