Reworking vehicle controller
This commit is contained in:
49
koptilnya/engine_remastered/gearboxes/base.txt
Normal file
49
koptilnya/engine_remastered/gearboxes/base.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
Gearbox = class('Gearbox')
|
||||
|
||||
function Gearbox:initialize(config, clutch, axles)
|
||||
self.ratios = config.Ratios
|
||||
self.reverse = config.Reverse
|
||||
|
||||
self.rpm = 0
|
||||
self.gear = 0
|
||||
self.torque = 0
|
||||
|
||||
self.axles = axles or {}
|
||||
self.clutch = clutch
|
||||
|
||||
self:recalcRatio()
|
||||
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
|
||||
|
||||
function Gearbox:update()
|
||||
if self.clutch ~= nil then
|
||||
self.torque = self.clutch.torque * self.ratio
|
||||
end
|
||||
|
||||
local axlesRPM = table.map(self.axles, function(diff)
|
||||
return diff.avgRPM
|
||||
end)
|
||||
|
||||
local maxAxlesRPM = math.max(unpack(axlesRPM))
|
||||
|
||||
self.rpm = maxAxlesRPM * self.ratio
|
||||
end
|
||||
|
||||
function Gearbox:shift()
|
||||
end
|
||||
@@ -1,29 +1,76 @@
|
||||
ManualGearbox = class('ManualGearbox')
|
||||
-- @include /koptilnya/libs/watcher.txt
|
||||
-- @include ./base.txt
|
||||
require('/koptilnya/libs/watcher.txt')
|
||||
require('./base.txt')
|
||||
|
||||
function ManualGearbox:initialize(config)
|
||||
self.ratios = config.Ratios
|
||||
self.reverse = config.Reverse
|
||||
ManualGearbox = class('ManualGearbox', Gearbox)
|
||||
|
||||
self.rpm = 0
|
||||
self.torque = 0
|
||||
self.gear = 0
|
||||
function ManualGearbox:initialize(config, clutch)
|
||||
Gearbox.initialize(self, config, clutch)
|
||||
|
||||
self:recalcRatio()
|
||||
-- self.ratios = config.Ratios
|
||||
-- self.reverse = config.Reverse
|
||||
|
||||
-- self.rpm = 0
|
||||
-- self.torque = 0
|
||||
-- self.gear = 0
|
||||
|
||||
-- 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)
|
||||
end
|
||||
|
||||
function ManualGearbox: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
|
||||
|
||||
function ManualGearbox:getInputs()
|
||||
return {
|
||||
Upshift = 'number',
|
||||
Downshift = 'number'
|
||||
}
|
||||
end
|
||||
|
||||
function ManualGearbox:getOutputs()
|
||||
return {
|
||||
Gearbox_RPM = 'number',
|
||||
Gearbox_Torque = 'number'
|
||||
}
|
||||
end
|
||||
|
||||
function ManualGearbox:updateOutputs()
|
||||
|
||||
self.axles = {}
|
||||
self.clutch = {}
|
||||
end
|
||||
|
||||
function ManualGearbox:update()
|
||||
if self.clutch ~= nil then
|
||||
self.torque = self.clutch.torque * self.ratio
|
||||
end
|
||||
-- if self.clutch ~= nil then
|
||||
-- self.torque = self.clutch.torque * self.ratio
|
||||
-- end
|
||||
|
||||
local axlesRPM = table.map(self.axles, function(diff)
|
||||
return diff.avgRPM
|
||||
end)
|
||||
-- local axlesRPM = table.map(self.axles, function(diff)
|
||||
-- return diff.avgRPM
|
||||
-- end)
|
||||
|
||||
local maxAxlesRPM = math.max(unpack(axlesRPM))
|
||||
-- local maxAxlesRPM = math.max(unpack(axlesRPM))
|
||||
|
||||
self.rpm = maxAxlesRPM * self.ratio
|
||||
-- self.rpm = maxAxlesRPM * self.ratio
|
||||
|
||||
-- self.shiftWatcher()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user