71 lines
1.6 KiB
Plaintext
71 lines
1.6 KiB
Plaintext
--@include /koptilnya/libs/constants.txt
|
|
--@include ../wire_component.txt
|
|
|
|
local WireComponent = require('../wire_component.txt')
|
|
|
|
require('/koptilnya/libs/constants.txt')
|
|
|
|
local PowertrainComponent = class('PowertrainComponent', WireComponent)
|
|
|
|
function PowertrainComponent:initialize(vehicle, name, config)
|
|
config = config or {}
|
|
|
|
WireComponent.initialize(self)
|
|
|
|
self.vehicle = vehicle
|
|
self.name = name or 'PowertrainComponent'
|
|
self.CONFIG = config
|
|
self.input = nil
|
|
self.output = nil
|
|
|
|
self.inertia = 0.02
|
|
self.angularVelocity = 0
|
|
self.torque = 0
|
|
end
|
|
|
|
function PowertrainComponent:start()
|
|
end
|
|
|
|
function PowertrainComponent:linkComponent(component)
|
|
if not component:isInstanceOf(PowertrainComponent) then
|
|
return
|
|
end
|
|
|
|
if self.output == nil then
|
|
self.output = component
|
|
component.input = self
|
|
end
|
|
end
|
|
|
|
function PowertrainComponent:getRPM()
|
|
return self.angularVelocity * RAD_TO_RPM
|
|
end
|
|
|
|
function PowertrainComponent:queryInertia()
|
|
if self.output == nil then
|
|
return self.inertia
|
|
end
|
|
|
|
return self.inertia + self.output:queryInertia()
|
|
end
|
|
|
|
function PowertrainComponent:queryAngularVelocity(angularVelocity)
|
|
self.angularVelocity = angularVelocity
|
|
|
|
if self.output == nil then
|
|
return 0
|
|
end
|
|
|
|
return self.output:queryAngularVelocity(angularVelocity)
|
|
end
|
|
|
|
function PowertrainComponent:forwardStep(torque, inertia)
|
|
if self.output == nil then
|
|
return self.torque
|
|
end
|
|
|
|
return self.output:forwardStep(self.torque, self.inertia + inertia)
|
|
end
|
|
|
|
return PowertrainComponent
|