69 lines
1.9 KiB
Lua
69 lines
1.9 KiB
Lua
-- @include /koptilnya/libs/wire_component.txt
|
|
-- @include /koptilnya/libs/constants.txt
|
|
-- @include /koptilnya/libs/entity.txt
|
|
-- @include ./slave.txt
|
|
require('/koptilnya/libs/wire_component.txt')
|
|
require('/koptilnya/libs/constants.txt')
|
|
require('/koptilnya/libs/entity.txt')
|
|
require('./slave.txt')
|
|
|
|
SteeringAxle = class('SteeringAxle', WireComponent)
|
|
|
|
function SteeringAxle:createSlave(options, isRight)
|
|
local config = {
|
|
Lock = options.Lock,
|
|
Camber = options.Camber,
|
|
Caster = options.Caster,
|
|
Ackermann = options.Ackermann,
|
|
Toe = options.Toe,
|
|
Direction = options.Direction,
|
|
IsRight = isRight,
|
|
Slave = wire.ports[self._prefix .. (isRight and '_RightSlave' or '_LeftSlave')],
|
|
Wheel = wire.ports[self._prefix .. (isRight and '_RightWheel' or '_LeftWheel')],
|
|
Offset = isRight and options.RightOffset or options.LeftOffset,
|
|
Prefix = self._prefix .. (isRight and '_RightWheel' or '_LeftWheel'),
|
|
Base = wire.ports.Base
|
|
}
|
|
|
|
return Slave:new(config)
|
|
end
|
|
|
|
function SteeringAxle:initialize(options)
|
|
options = options or {}
|
|
|
|
self.steer = 0
|
|
self._prefix = 'Axle' .. options.Order
|
|
|
|
self.leftSlave = self:createSlave(options, false)
|
|
self.rightSlave = self:createSlave(options, true)
|
|
end
|
|
|
|
function SteeringAxle:getInputs()
|
|
local inputs = {}
|
|
|
|
inputs[self._prefix .. '_LeftSlave'] = 'entity'
|
|
inputs[self._prefix .. '_RightSlave'] = 'entity'
|
|
inputs[self._prefix .. '_LeftWheel'] = 'entity'
|
|
inputs[self._prefix .. '_RightWheel'] = 'entity'
|
|
|
|
return inputs
|
|
end
|
|
|
|
function SteeringAxle:getOutputs()
|
|
local outputs = {}
|
|
|
|
table.merge(outputs, self.leftSlave:getOutputs())
|
|
table.merge(outputs, self.rightSlave:getOutputs())
|
|
|
|
return outputs
|
|
end
|
|
|
|
function SteeringAxle:updateOutputs()
|
|
self.leftSlave:updateOutputs()
|
|
self.rightSlave:updateOutputs()
|
|
end
|
|
|
|
function SteeringAxle:update()
|
|
self.leftSlave:update()
|
|
self.rightSlave:update()
|
|
end |