Finished manual gearbox
This commit is contained in:
@@ -13,53 +13,100 @@
|
||||
-- @include ./differential.txt
|
||||
--
|
||||
-- @include ./configs/audi_tt.txt
|
||||
require("./engine.txt")
|
||||
-- @include ../libs/watcher.txt
|
||||
require('./engine.txt')
|
||||
--
|
||||
require("./clutch.txt")
|
||||
require('./clutch.txt')
|
||||
--
|
||||
require("./gearboxes/manual.txt")
|
||||
require("./gearboxes/cvt.txt")
|
||||
require("./gearboxes/auto.txt")
|
||||
require('./gearboxes/manual.txt')
|
||||
require('./gearboxes/cvt.txt')
|
||||
require('./gearboxes/auto.txt')
|
||||
--
|
||||
require("./differential.txt")
|
||||
require('./differential.txt')
|
||||
--
|
||||
require("./configs/audi_tt.txt")
|
||||
require('./configs/audi_tt.txt')
|
||||
require('../libs/watcher.txt')
|
||||
|
||||
ECU = class("ECU")
|
||||
ECU = class('ECU')
|
||||
|
||||
function ECU:initialize(options)
|
||||
options = options or {}
|
||||
|
||||
self:adjustPorts()
|
||||
|
||||
self.engine = options.Engine
|
||||
self.clutch = options.Clutch
|
||||
self.gearbox = options.Gearbox
|
||||
self.differentials = options.Differentials
|
||||
self.input = {}
|
||||
|
||||
self:adjustPorts()
|
||||
self.input = wire.ports.Input or nil
|
||||
|
||||
hook.add('tick', 'ecu_update', function()
|
||||
self:update()
|
||||
end)
|
||||
|
||||
self.shifterWatcher = watcher(function()
|
||||
return self.input.Shifter.Value
|
||||
end, function(val)
|
||||
if self.gearbox == nil or val == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
self.gearbox:shift(val)
|
||||
end)
|
||||
end
|
||||
|
||||
function ECU:adjustPorts()
|
||||
wire.adjustPorts({
|
||||
Input = "table"
|
||||
Input = 'table',
|
||||
FL = 'entity',
|
||||
FR = 'entity',
|
||||
RL = 'entity',
|
||||
RR = 'entity'
|
||||
}, {
|
||||
RPM = "number",
|
||||
Torque = "number"
|
||||
RPM = 'number',
|
||||
Torque = 'number',
|
||||
ClutchTorque = 'number',
|
||||
ClutchPress = 'number',
|
||||
AvgRPM = 'number',
|
||||
GearboxTorque = 'number',
|
||||
GearboxRPM = 'number',
|
||||
GearboxRatio = 'number',
|
||||
Gear = 'number',
|
||||
ClutchSlip = 'number'
|
||||
})
|
||||
end
|
||||
|
||||
function ECU:update()
|
||||
wire.ports.RPM = self.engine.rpm
|
||||
wire.ports.Torque = self.engine.torque
|
||||
wire.ports.ClutchPress = self.clutch.press
|
||||
wire.ports.ClutchTorque = self.clutch.torque
|
||||
wire.ports.ClutchSlip = self.clutch.slip
|
||||
wire.ports.GearboxTorque = self.gearbox.torque
|
||||
wire.ports.GearboxRPM = self.gearbox.rpm
|
||||
wire.ports.AvgRPM = self.differentials[1].avgRPM
|
||||
wire.ports.Gear = self.gearbox.gear
|
||||
wire.ports.GearboxRatio = self.gearbox.ratio
|
||||
|
||||
self.input = wire.ports.Input
|
||||
|
||||
self.engine:setThrottle(self.input.Throttle.Value)
|
||||
if self.input.Throttle then
|
||||
self.engine:setThrottle(self.input.Throttle.Value)
|
||||
end
|
||||
|
||||
if self.input.Clutch then
|
||||
self.clutch:setPress(self.input.Clutch.Value)
|
||||
end
|
||||
|
||||
self.engine:update()
|
||||
self.clutch:update()
|
||||
self.gearbox:update()
|
||||
|
||||
self.shifterWatcher()
|
||||
|
||||
for _, diff in ipairs(self.differentials) do
|
||||
diff:update()
|
||||
end
|
||||
end
|
||||
|
||||
local clutch = Clutch:new(config.Clutch)
|
||||
@@ -70,8 +117,19 @@ engine:linkClutch(clutch)
|
||||
local gearbox = ManualGearbox:new(config.Gearbox)
|
||||
gearbox:linkClutch(clutch)
|
||||
|
||||
local frontDifferential = Differential:new(config.FrontDiff)
|
||||
frontDifferential:linkWheels(wire.ports.FL, wire.ports.FR)
|
||||
frontDifferential:linkGearbox(gearbox)
|
||||
|
||||
local rearDifferential = Differential:new(config.RearDiff)
|
||||
rearDifferential:linkWheels(wire.ports.RL, wire.ports.RR)
|
||||
rearDifferential:linkGearbox(gearbox)
|
||||
|
||||
local differentials = {frontDifferential, rearDifferential}
|
||||
|
||||
local ecu = ECU:new({
|
||||
Engine = engine,
|
||||
Clutch = clutch
|
||||
-- Gearbox = gearbox
|
||||
Clutch = clutch,
|
||||
Differentials = differentials,
|
||||
Gearbox = gearbox
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user