Finished manual gearbox

This commit is contained in:
Ivan Grachyov
2021-11-11 22:16:33 +05:00
parent f55c30c4d3
commit d73f424d7f
15 changed files with 588 additions and 62 deletions

View File

@@ -1,4 +1,4 @@
-- @include ./base.txt
require("./base.txt")
require('./base.txt')
AutomaticGearbox = class("AutomaticGearbox")
AutomaticGearbox = class('AutomaticGearbox')

View File

@@ -1,4 +1,7 @@
Gearbox = class("Gearbox")
-- @include ../../libs/table.txt
require('../../libs/table.txt')
Gearbox = class('Gearbox')
function Gearbox:initialize(options)
options = options or {}
@@ -7,8 +10,13 @@ function Gearbox:initialize(options)
self.finalDrive = options.FinalDrive
self.reverse = options.Reverse
self.rpm = 0
self.gear = 0
self:recalcRatio()
self.torque = 0
self._linkedDiffs = {}
self._clutch = nil
end
@@ -18,12 +26,23 @@ function Gearbox:linkDiff(diff)
end
function Gearbox:shift(dir)
self:setGear(self.gear + dir)
end
function Gearbox:setGear(gear)
if gear >= -1 and gear <= #self.ratios then
self.gear = gear
self:recalcRatio()
end
end
function Gearbox:recalcRatio()
if self.gear == -1 then
self.ratio = -self.reverse
elseif self.gear == 0 then
self.ratio = 0
else
self.ratio = self.ratios[self.gear]
end
end
@@ -33,5 +52,15 @@ function Gearbox:linkClutch(clutch)
end
function Gearbox:update()
if self._clutch ~= nil then
self.torque = self._clutch.torque * self.ratio * self.finalDrive
end
local axlesRPM = table.map(self._linkedDiffs, function(diff)
return diff.avgRPM
end)
local maxAxlesRPM = math.max(unpack(axlesRPM))
self.rpm = maxAxlesRPM * self.finalDrive * self.ratio
end

View File

@@ -1,7 +1,7 @@
-- @include ./base.txt
require("./base.txt")
require('./base.txt')
CVT = class("CVT")
CVT = class('CVT')
function CVT:initialize(options)
options = options or {}

View File

@@ -1,17 +1,40 @@
-- @include ./base.txt
require("./base.txt")
require('./base.txt')
ManualGearbox = class("ManualGearbox")
ManualGearbox = class('ManualGearbox')
function ManualGearbox:initialize(options)
options = options or {}
-- might want to segregate construction options for base gearbox
self.base = Gearbox:new(options)
self.torque = 0
self.rpm = 0
self.gear = 0
self.ratio = 0
end
function ManualGearbox:linkClutch(clutch)
return self.base:linkClutch(clutch)
end
-- proxy the methods here
function ManualGearbox:linkDiff(diff)
return self.base:linkDiff(diff)
end
function ManualGearbox:shift(dir)
return self.base:shift(dir)
end
function ManualGearbox:setGear(gear)
return self.base:setGear(gear)
end
function ManualGearbox:update()
self.base:update()
self.rpm = self.base.rpm
self.torque = self.base.torque
self.gear = self.base.gear
self.ratio = self.base.ratio
end