50 lines
1.1 KiB
Plaintext
50 lines
1.1 KiB
Plaintext
--@include /koptilnya/libs/constants.txt
|
|
--@include ./wire_component.txt
|
|
|
|
require('/koptilnya/libs/constants.txt')
|
|
require('./wire_component.txt')
|
|
|
|
PowertrainComponent = class('PowertrainComponent', WireComponent)
|
|
|
|
function PowertrainComponent:initialize(name)
|
|
WireComponent.initialize(self)
|
|
|
|
self.name = name or 'PowertrainComponent'
|
|
self.input = nil
|
|
self.output = nil
|
|
|
|
self.inertia = 0.02
|
|
self.angularVelocity = 0
|
|
self.torque = 0
|
|
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
|