Finished stuff with manual gearbox
This commit is contained in:
@@ -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
|
||||
@@ -5,30 +5,21 @@ require('./base.txt')
|
||||
|
||||
ManualGearbox = class('ManualGearbox', Gearbox)
|
||||
|
||||
function ManualGearbox:initialize(config, clutch)
|
||||
Gearbox.initialize(self, config, clutch)
|
||||
function ManualGearbox:initialize(...)
|
||||
Gearbox.initialize(self, ...)
|
||||
|
||||
-- self.ratios = config.Ratios
|
||||
-- self.reverse = config.Reverse
|
||||
function shiftFunc()
|
||||
local upshift = wire.ports.Upshift or 0
|
||||
local downshift = wire.ports.Downshift or 0
|
||||
|
||||
-- self.rpm = 0
|
||||
-- self.torque = 0
|
||||
-- self.gear = 0
|
||||
return upshift - downshift
|
||||
end
|
||||
|
||||
-- self:recalcRatio()
|
||||
|
||||
-- self.axles = {}
|
||||
-- self.clutch = nil
|
||||
|
||||
-- self.torque = 0
|
||||
|
||||
-- self.shiftWatcher = watcher(function()
|
||||
-- return wire.ports.Upshift - wire.ports.Downshift
|
||||
-- end, function(val)
|
||||
-- if val ~= 0 then
|
||||
-- self:shift(val)
|
||||
-- end
|
||||
-- end)
|
||||
self.shiftWatcher = watcher(shiftFunc, function(val)
|
||||
if val ~= 0 then
|
||||
self:shift(val)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function ManualGearbox:recalcRatio()
|
||||
@@ -41,36 +32,23 @@ function ManualGearbox:recalcRatio()
|
||||
end
|
||||
end
|
||||
|
||||
function ManualGearbox:getInputs()
|
||||
return {
|
||||
Upshift = 'number',
|
||||
Downshift = 'number'
|
||||
}
|
||||
function ManualGearbox:shift(dir)
|
||||
self:setGear(self.gear + dir)
|
||||
end
|
||||
|
||||
function ManualGearbox:getOutputs()
|
||||
return {
|
||||
Gearbox_RPM = 'number',
|
||||
Gearbox_Torque = 'number'
|
||||
}
|
||||
end
|
||||
-- function ManualGearbox:getOutputs()
|
||||
-- return {
|
||||
-- Gearbox_RPM = 'number',
|
||||
-- Gearbox_Torque = 'number'
|
||||
-- }
|
||||
-- end
|
||||
|
||||
function ManualGearbox:updateOutputs()
|
||||
-- function ManualGearbox:updateOutputs()
|
||||
|
||||
end
|
||||
-- end
|
||||
|
||||
function ManualGearbox:update()
|
||||
-- if self.clutch ~= nil then
|
||||
-- self.torque = self.clutch.torque * self.ratio
|
||||
-- end
|
||||
Gearbox.update(self)
|
||||
|
||||
-- local axlesRPM = table.map(self.axles, function(diff)
|
||||
-- return diff.avgRPM
|
||||
-- end)
|
||||
|
||||
-- local maxAxlesRPM = math.max(unpack(axlesRPM))
|
||||
|
||||
-- self.rpm = maxAxlesRPM * self.ratio
|
||||
|
||||
-- self.shiftWatcher()
|
||||
self.shiftWatcher()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user