Updated diff
This commit is contained in:
parent
1a2aea0fdb
commit
4f6d4a04df
@ -50,7 +50,6 @@ Vehicle:new({
|
|||||||
Power = 0.3,
|
Power = 0.3,
|
||||||
Coast = 0.15,
|
Coast = 0.15,
|
||||||
Preload = 10,
|
Preload = 10,
|
||||||
UsePowerBias = 10,
|
|
||||||
ViscousCoeff = 0.96,
|
ViscousCoeff = 0.96,
|
||||||
Axle = Vector(1, 0, 0),
|
Axle = Vector(1, 0, 0),
|
||||||
DistributionCoeff = 0.4,
|
DistributionCoeff = 0.4,
|
||||||
@ -59,7 +58,6 @@ Vehicle:new({
|
|||||||
Power = 0.4,
|
Power = 0.4,
|
||||||
Coast = 0.3,
|
Coast = 0.3,
|
||||||
Preload = 10,
|
Preload = 10,
|
||||||
UsePowerBias = 10,
|
|
||||||
ViscousCoeff = 0.96,
|
ViscousCoeff = 0.96,
|
||||||
Axle = Vector(1, 0, 0),
|
Axle = Vector(1, 0, 0),
|
||||||
DistributionCoeff = 0.6,
|
DistributionCoeff = 0.6,
|
||||||
|
|||||||
@ -24,9 +24,9 @@ Vehicle:new({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Clutch = {Stiffness = 20, Damping = 0.5, MaxTorque = 400},
|
Clutch = {Stiffness = 20, Damping = 0.5, MaxTorque = 400},
|
||||||
Gearbox = {Type = 'MANUAL', ShiftDuration = 0.2, ShiftSmoothness = 0.3, Ratios = {3.67, 2.1, 1.35, 1.1, 0.901}, Reverse = 3.818},
|
Gearbox = {Type = 'MANUAL', ShiftDuration = 0.2, ShiftSmoothness = 0.3, Ratios = {3.321, 1.902, 1.308, 1, 0.838}, Reverse = 3.382},
|
||||||
Axles = {
|
Axles = {
|
||||||
{Power = 0.96, Coast = 0.96, Preload = 10, UsePowerBias = 10, ViscousCoeff = 0.96, Axle = Vector(1, 0, 0), DistributionCoeff = 0.6, FinalDrive = 3.9}
|
{Power = 0.5, Coast = 0.3, Preload = 30, ViscousCoeff = 0.96, Axle = Vector(1, 0, 0), DistributionCoeff = 1, FinalDrive = 4.08}
|
||||||
},
|
},
|
||||||
Systems = {{Type = 'LAUNCH', Limit = 3500}, {Type = 'TRACTION', Limit = 1.5}}
|
Systems = {{Type = 'LAUNCH', Limit = 3500}, {Type = 'TRACTION', Limit = 1.5}}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -14,25 +14,35 @@ function Differential:initialize(config, order)
|
|||||||
self.order = order or 1
|
self.order = order or 1
|
||||||
|
|
||||||
self.viscousCoeff = config.ViscousCoeff or 0.9
|
self.viscousCoeff = config.ViscousCoeff or 0.9
|
||||||
self.usePowerBias = config.UsePowerBias or 10
|
|
||||||
|
|
||||||
self.distributionCoeff = config.DistributionCoeff or 1
|
self.distributionCoeff = config.DistributionCoeff or 1
|
||||||
self.maxCorrectingTorque = config.MaxCorrectingTorque or 200
|
self.maxCorrectingTorque = config.MaxCorrectingTorque or 200
|
||||||
|
|
||||||
self.avgRPM = 0
|
self.avgRPM = 0
|
||||||
|
|
||||||
self.leftWheelInput = 'Axle' .. self.order .. '_LeftWheel'
|
self.prefix = 'Axle' .. self.order .. '_'
|
||||||
self.rightWheelInput = 'Axle' .. self.order .. '_RightWheel'
|
|
||||||
|
|
||||||
self.leftWheel = wire.ports[self.leftWheelInput]
|
self.leftWheel = wire.ports[self.prefix .. 'LeftWheel']
|
||||||
self.rightWheel = wire.ports[self.rightWheelInput]
|
self.rightWheel = wire.ports[self.prefix .. 'RightWheel']
|
||||||
|
|
||||||
|
self.lwPowerCoeff = 0
|
||||||
|
self.rwPowerCoeff = 0
|
||||||
|
|
||||||
|
self.lwtq_div_rwtq = 0
|
||||||
|
self.rwtq_div_lwtq = 0
|
||||||
|
|
||||||
|
self.lwtq = 0
|
||||||
|
self.rwtq = 0
|
||||||
|
|
||||||
|
self.lwav = 0
|
||||||
|
self.rwav = 0
|
||||||
|
|
||||||
hook.add('input', 'wire_axle_update' .. self.order, function(key, val)
|
hook.add('input', 'wire_axle_update' .. self.order, function(key, val)
|
||||||
if key == self.leftWheelInput then
|
if key == self.prefix .. 'LeftWheel' then
|
||||||
self.leftWheel = val
|
self.leftWheel = val
|
||||||
end
|
end
|
||||||
|
|
||||||
if key == self.rightWheelInput then
|
if key == self.prefix .. 'RightWheel' then
|
||||||
self.rightWheel = val
|
self.rightWheel = val
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -41,67 +51,157 @@ end
|
|||||||
function Differential:getInputs()
|
function Differential:getInputs()
|
||||||
local inputs = {}
|
local inputs = {}
|
||||||
|
|
||||||
inputs[self.leftWheelInput] = 'entity'
|
inputs[self.prefix .. 'LeftWheel'] = 'entity'
|
||||||
inputs[self.rightWheelInput] = 'entity'
|
inputs[self.prefix .. 'RightWheel'] = 'entity'
|
||||||
|
|
||||||
return inputs
|
return inputs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Differential:getOutputs()
|
||||||
|
local outputs = {}
|
||||||
|
|
||||||
|
outputs[self.prefix .. 'LWPowerCoeff'] = 'number'
|
||||||
|
outputs[self.prefix .. 'RWPowerCoeff'] = 'number'
|
||||||
|
outputs[self.prefix .. 'LWTq'] = 'number'
|
||||||
|
outputs[self.prefix .. 'RWTq'] = 'number'
|
||||||
|
outputs[self.prefix .. 'LWAV'] = 'number'
|
||||||
|
outputs[self.prefix .. 'RWAV'] = 'number'
|
||||||
|
outputs[self.prefix .. 'AvgRPM'] = 'number'
|
||||||
|
outputs[self.prefix .. 'LW_div_RW'] = 'number'
|
||||||
|
outputs[self.prefix .. 'RW_div_LW'] = 'number'
|
||||||
|
-- outputs[self.prefix .. 'SGAV'] = 'number'
|
||||||
|
|
||||||
|
return outputs
|
||||||
|
end
|
||||||
|
|
||||||
|
function Differential:updateOutputs()
|
||||||
|
wire.ports[self.prefix .. 'LWPowerCoeff'] = self.lwPowerCoeff
|
||||||
|
wire.ports[self.prefix .. 'RWPowerCoeff'] = self.rwPowerCoeff
|
||||||
|
wire.ports[self.prefix .. 'LWTq'] = self.lwtq
|
||||||
|
wire.ports[self.prefix .. 'RWTq'] = self.rwtq
|
||||||
|
wire.ports[self.prefix .. 'RWTq'] = self.rwtq
|
||||||
|
wire.ports[self.prefix .. 'LWAV'] = self.lwav
|
||||||
|
wire.ports[self.prefix .. 'RWAV'] = self.rwav
|
||||||
|
wire.ports[self.prefix .. 'AvgRPM'] = self.avgRPM
|
||||||
|
wire.ports[self.prefix .. 'LW_div_RW'] = self.lwtq_div_rwtq
|
||||||
|
wire.ports[self.prefix .. 'RW_div_LW'] = self.rwtq_div_lwtq
|
||||||
|
-- wire.ports[self.prefix .. 'SGAV'] = self.sgav
|
||||||
|
end
|
||||||
|
|
||||||
function Differential:linkGearbox(gbox)
|
function Differential:linkGearbox(gbox)
|
||||||
self.gearbox = gbox
|
self.gearbox = gbox
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- this is a test function that can spin wheels in different directions
|
||||||
|
function Differential:testUpdate()
|
||||||
|
if isValid(self.leftWheel) and isValid(self.rightWheel) then
|
||||||
|
local lwav = math.rad(self.leftWheel:getAngleVelocity()[2])
|
||||||
|
local rwav = math.rad(self.rightWheel:getAngleVelocity()[2])
|
||||||
|
|
||||||
|
self.avgRPM = (lwav - rwav) / 2 * RAD_TO_RPM * self.finalDrive
|
||||||
|
|
||||||
|
self.lwav = lwav
|
||||||
|
self.rwav = rwav
|
||||||
|
|
||||||
|
-- spider gear angular velocity
|
||||||
|
local sgav = (lwav + rwav) / 2
|
||||||
|
|
||||||
|
self.sgav = sgav
|
||||||
|
|
||||||
|
-- RAV = relative angular velocity
|
||||||
|
local lwrav = lwav - sgav
|
||||||
|
local rwrav = rwav - sgav
|
||||||
|
|
||||||
|
local lwInertia = self.leftWheel:getInertia():getLength()
|
||||||
|
local rwInertia = self.rightWheel:getInertia():getLength()
|
||||||
|
|
||||||
|
local lwtq = lwrav * lwInertia * 2
|
||||||
|
local rwtq = rwrav * rwInertia * 2
|
||||||
|
|
||||||
|
self.lwtq = lwtq
|
||||||
|
self.rwtq = rwtq
|
||||||
|
|
||||||
|
local lwDampingTorque = self.viscousCoeff * lwtq
|
||||||
|
local rwDampingTorque = self.viscousCoeff * rwtq
|
||||||
|
|
||||||
|
local gboxTorque = self.gearbox and self.gearbox.torque / 10 or 0
|
||||||
|
|
||||||
|
local usedCoeff = gboxTorque > self.preload and self.power or self.coast
|
||||||
|
|
||||||
|
local lwCorrectingTorque = math.clamp(lwDampingTorque * usedCoeff, -self.maxCorrectingTorque,
|
||||||
|
self.maxCorrectingTorque)
|
||||||
|
local rwCorrectingTorque = math.clamp(rwDampingTorque * usedCoeff, -self.maxCorrectingTorque,
|
||||||
|
self.maxCorrectingTorque)
|
||||||
|
|
||||||
|
local driveTorque = gboxTorque * self.distributionCoeff * 52.49 * self.finalDrive
|
||||||
|
|
||||||
|
local lwCorrectedTorque = lwCorrectingTorque * 600 - driveTorque
|
||||||
|
local rwCorrectedTorque = rwCorrectingTorque * 600 + driveTorque
|
||||||
|
|
||||||
|
self.leftWheel:applyTorque(lwCorrectedTorque * self.leftWheel:getRight() * TICK_INTERVAL)
|
||||||
|
self.rightWheel:applyTorque(rwCorrectedTorque * self.rightWheel:getRight() * TICK_INTERVAL)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Differential:update()
|
function Differential:update()
|
||||||
if isValid(self.leftWheel) and isValid(self.rightWheel) then
|
if isValid(self.leftWheel) and isValid(self.rightWheel) then
|
||||||
local lwav = math.rad(self.leftWheel:getAngleVelocity()[2])
|
local lwav = math.rad(self.leftWheel:getAngleVelocity()[2])
|
||||||
local rwav = math.rad(self.rightWheel:getAngleVelocity()[2]) * -1
|
local rwav = math.rad(self.rightWheel:getAngleVelocity()[2]) * -1
|
||||||
|
|
||||||
self.avgRPM = (lwav + rwav) / 2 * RAD_TO_RPM * self.finalDrive
|
self.lwav = lwav
|
||||||
|
self.rwav = rwav
|
||||||
|
|
||||||
-- RAV = relative anglar velocity
|
-- RAV = relative anglar velocity
|
||||||
local lwrav = rwav - lwav
|
local lwrav = rwav - lwav
|
||||||
local rwrav = lwav - rwav
|
local rwrav = lwav - rwav
|
||||||
|
|
||||||
local lwInertia = self.leftWheel:getInertia():getLength()
|
local lwInertia = self.leftWheel:getInertia()[2]
|
||||||
local rwInertia = self.rightWheel:getInertia():getLength()
|
local rwInertia = self.rightWheel:getInertia()[2]
|
||||||
|
|
||||||
local lwtq = lwrav * lwInertia
|
local lwtq = lwrav * lwInertia
|
||||||
local rwtq = rwrav * rwInertia
|
local rwtq = rwrav * rwInertia
|
||||||
|
|
||||||
-- Calculating damping torque here
|
self.lwtq = lwtq
|
||||||
local lwDampingTorque = self.viscousCoeff * lwtq
|
self.rwtq = rwtq
|
||||||
local rwDampingTorque = self.viscousCoeff * rwtq
|
|
||||||
|
|
||||||
-- Whether use diff power or diff coast
|
-- Whether use diff power or diff coast
|
||||||
local usePower = self.gearbox and self.gearbox.torque > self.usePowerBias or false
|
local usePower = self.gearbox and self.gearbox.torque > self.preload and false
|
||||||
local usedCoeff = usePower and self.power or self.coast
|
local usedCoeff = usePower and self.power or self.coast
|
||||||
|
|
||||||
local lwPowerCoeff = usedCoeff
|
-- Calculating damping torque here
|
||||||
local rwPowerCoeff = usedCoeff
|
local lwDampingTorque = self.viscousCoeff * lwtq * usedCoeff
|
||||||
|
local rwDampingTorque = self.viscousCoeff * rwtq * usedCoeff
|
||||||
|
|
||||||
-- this could probably be shortened?
|
local lwav_abs = math.abs(lwav)
|
||||||
-- if lwtq - rwtq > self.preload then
|
local rwav_abs = math.abs(rwav)
|
||||||
-- lwPowerCoeff = usedCoeff
|
|
||||||
-- rwPowerCoeff = usedCoeff
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- if rwtq - lwtq > self.preload then
|
local avg_abs = lwav_abs + rwav_abs
|
||||||
-- lwPowerCoeff = usedCoeff
|
|
||||||
-- rwPowerCoeff = usedCoeff
|
|
||||||
-- end
|
|
||||||
|
|
||||||
local lwCorrectingTorque = math.clamp(lwDampingTorque * lwPowerCoeff, -self.maxCorrectingTorque,
|
local lwav_to_avg = avg_abs ~= 0 and 2 * lwav_abs / avg_abs or 0
|
||||||
self.maxCorrectingTorque)
|
local rwav_to_avg = avg_abs ~= 0 and 2 * rwav_abs / avg_abs or 0
|
||||||
local rwCorrectingTorque = math.clamp(rwDampingTorque * rwPowerCoeff, -self.maxCorrectingTorque,
|
|
||||||
self.maxCorrectingTorque)
|
self.lwtq_div_rwtq = lwav_to_avg
|
||||||
|
self.rwtq_div_lwtq = rwav_to_avg
|
||||||
|
|
||||||
|
local lwPowerCoeff = math.clamp(lwav_to_avg, usedCoeff, 1 + (1 - usedCoeff))
|
||||||
|
local rwPowerCoeff = math.clamp(rwav_to_avg, usedCoeff, 1 + (1 - usedCoeff))
|
||||||
|
|
||||||
|
self.lwPowerCoeff = lwPowerCoeff
|
||||||
|
self.rwPowerCoeff = rwPowerCoeff
|
||||||
|
|
||||||
|
local lwCorrectingTorque = math.clamp(lwDampingTorque, -self.maxCorrectingTorque, self.maxCorrectingTorque)
|
||||||
|
local rwCorrectingTorque = math.clamp(rwDampingTorque, -self.maxCorrectingTorque, self.maxCorrectingTorque)
|
||||||
|
|
||||||
local gboxTorque = self.gearbox and self.gearbox.torque or 0
|
local gboxTorque = self.gearbox and self.gearbox.torque or 0
|
||||||
|
|
||||||
local driveTorque = gboxTorque * self.distributionCoeff * 52.49 * self.finalDrive
|
local driveTorque = gboxTorque / 2 * self.distributionCoeff * self.finalDrive
|
||||||
local lwCorrectedTorque = lwCorrectingTorque * 600 + driveTorque
|
|
||||||
local rwCorrectedTorque = rwCorrectingTorque * 600 + driveTorque
|
|
||||||
|
|
||||||
self.leftWheel:applyTorque(lwCorrectedTorque * -self.leftWheel:getRight() * TICK_INTERVAL)
|
local lwCorrectedTorque = lwCorrectingTorque * 20 + driveTorque * lwPowerCoeff -- * lwPowerCoeff
|
||||||
self.rightWheel:applyTorque(rwCorrectedTorque * self.rightWheel:getRight() * TICK_INTERVAL)
|
local rwCorrectedTorque = rwCorrectingTorque * 20 + driveTorque * rwPowerCoeff -- * rwPowerCoeff
|
||||||
|
|
||||||
|
self.leftWheel:applyTorque(lwCorrectedTorque * -self.leftWheel:getRight())
|
||||||
|
self.rightWheel:applyTorque(rwCorrectedTorque * self.rightWheel:getRight())
|
||||||
|
|
||||||
|
self.avgRPM = (lwav + rwav) / 2 * RAD_TO_RPM * self.finalDrive
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -35,11 +35,9 @@ function Vehicle:initialize(config)
|
|||||||
|
|
||||||
-- self.systems = table.map(config.Systems, function(config)
|
-- self.systems = table.map(config.Systems, function(config)
|
||||||
-- return SystemsFactory.create(config)
|
-- return SystemsFactory.create(config)
|
||||||
-- end)
|
-- end)s
|
||||||
|
|
||||||
self.components = {self.clutch, self.engine, self.gearbox}
|
self.components = {self.clutch, self.engine, self.gearbox}
|
||||||
self.components = table.add(self.components, self.axles)
|
self.components = table.add(self.components, self.axles)
|
||||||
-- self.components = table.add(self.components, self.axles)
|
|
||||||
-- self.components = table.add(self.components, self.systems)
|
-- self.components = table.add(self.components, self.systems)
|
||||||
|
|
||||||
local inputs = {}
|
local inputs = {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user