pushing some shit
This commit is contained in:
parent
0b71940310
commit
e2de173e25
5
koptilnya/.idea/.gitignore
generated
vendored
Normal file
5
koptilnya/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
12
koptilnya/.idea/koptilnya.iml
generated
Normal file
12
koptilnya/.idea/koptilnya.iml
generated
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
8
koptilnya/.idea/modules.xml
generated
Normal file
8
koptilnya/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/koptilnya.iml" filepath="$PROJECT_DIR$/.idea/koptilnya.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
koptilnya/.idea/vcs.xml
generated
Normal file
6
koptilnya/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@ -6,37 +6,23 @@ require('/koptilnya/better_steering/steering.txt')
|
|||||||
|
|
||||||
Steering:new({
|
Steering:new({
|
||||||
Sensitivity = 0.04,
|
Sensitivity = 0.04,
|
||||||
Slaves = {{
|
PowerSteer = 0.5,
|
||||||
|
Axles = {{
|
||||||
Lock = 30,
|
Lock = 30,
|
||||||
Camber = -2,
|
Camber = -2,
|
||||||
Caster = 5,
|
Caster = 8,
|
||||||
Ackermann = 15.43,
|
Ackermann = 15.43,
|
||||||
Toe = 0,
|
Toe = 0,
|
||||||
Offset = 180
|
LeftOffset = 180,
|
||||||
|
RightOffset = 180
|
||||||
}, {
|
}, {
|
||||||
Lock = 30,
|
Lock = 0,
|
||||||
Camber = -2,
|
|
||||||
Caster = 5,
|
|
||||||
Ackermann = 15.43,
|
|
||||||
Toe = 0,
|
|
||||||
Offset = 180,
|
|
||||||
IsRight = true
|
|
||||||
}, {
|
|
||||||
Lock = 1,
|
|
||||||
Camber = -2,
|
Camber = -2,
|
||||||
Caster = 0,
|
Caster = 0,
|
||||||
Ackermann = 0,
|
Ackermann = 0,
|
||||||
Toe = 0,
|
Toe = 0,
|
||||||
Offset = 180,
|
LeftOffset = 180,
|
||||||
Direction = -1
|
RightOffset = 180,
|
||||||
}, {
|
|
||||||
Lock = 1,
|
|
||||||
Camber = -2,
|
|
||||||
Caster = 0,
|
|
||||||
Ackermann = 0,
|
|
||||||
Toe = 0,
|
|
||||||
Offset = 180,
|
|
||||||
IsRight = true,
|
|
||||||
Direction = -1
|
Direction = -1
|
||||||
}}
|
}}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
-- @include /koptilnya/libs/wire_component.txt
|
-- @include /koptilnya/libs/wire_component.txt
|
||||||
-- @include /koptilnya/libs/constants.txt
|
-- @include /koptilnya/libs/constants.txt
|
||||||
|
-- @include /koptilnya/libs/entity.txt
|
||||||
require('/koptilnya/libs/wire_component.txt')
|
require('/koptilnya/libs/wire_component.txt')
|
||||||
require('/koptilnya/libs/constants.txt')
|
require('/koptilnya/libs/constants.txt')
|
||||||
|
require('/koptilnya/libs/entity.txt')
|
||||||
|
|
||||||
Slave = class('Slave', WireComponent)
|
Slave = class('Slave', WireComponent)
|
||||||
|
|
||||||
@ -19,26 +21,19 @@ function Slave:initialize(options)
|
|||||||
|
|
||||||
self.order = options.Order or 0
|
self.order = options.Order or 0
|
||||||
|
|
||||||
self.entity = nil
|
self.entity = options.Slave
|
||||||
self.wheel = nil
|
self.wheel = options.Wheel
|
||||||
self.base = options.Base or nil
|
self.base = options.Base or nil
|
||||||
|
|
||||||
self.steer = 0
|
self.steer = 0
|
||||||
self.steeringAngle = 0
|
self.steeringAngle = 0
|
||||||
self.lateralVel = 0
|
self.lateralVel = 0
|
||||||
|
self.baseLngVel = 0
|
||||||
self.lateralForce = 0
|
self.lateralForce = 0
|
||||||
self.selfAligningTorque = 0
|
self.selfAligningTorque = 0
|
||||||
self.correctingAngle = 0
|
self.correctingAngle = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function Slave:getInputs()
|
|
||||||
local inputs = {}
|
|
||||||
inputs['SL_' .. self.order] = 'entity'
|
|
||||||
inputs['W_' .. self.order] = 'entity'
|
|
||||||
|
|
||||||
return inputs
|
|
||||||
end
|
|
||||||
|
|
||||||
function Slave:getOutputs()
|
function Slave:getOutputs()
|
||||||
local outputs = {}
|
local outputs = {}
|
||||||
|
|
||||||
@ -46,6 +41,8 @@ function Slave:getOutputs()
|
|||||||
outputs['SL_' .. self.order .. '_SelfAligningTq'] = 'number'
|
outputs['SL_' .. self.order .. '_SelfAligningTq'] = 'number'
|
||||||
outputs['SL_' .. self.order .. '_CorrectingAngle'] = 'number'
|
outputs['SL_' .. self.order .. '_CorrectingAngle'] = 'number'
|
||||||
outputs['W_' .. self.order .. '_LateralVel'] = 'number'
|
outputs['W_' .. self.order .. '_LateralVel'] = 'number'
|
||||||
|
outputs['SL_' .. self.order .. '_SteeringAngle'] = 'number'
|
||||||
|
outputs['SL_' .. self.order .. '_BaseLngVel'] = 'number'
|
||||||
|
|
||||||
return outputs
|
return outputs
|
||||||
end
|
end
|
||||||
@ -55,42 +52,24 @@ function Slave:updateOutputs()
|
|||||||
wire.ports['SL_' .. self.order .. '_SelfAligningTq'] = self.selfAligningTorque
|
wire.ports['SL_' .. self.order .. '_SelfAligningTq'] = self.selfAligningTorque
|
||||||
wire.ports['SL_' .. self.order .. '_CorrectingAngle'] = self.correctingAngle
|
wire.ports['SL_' .. self.order .. '_CorrectingAngle'] = self.correctingAngle
|
||||||
wire.ports['W_' .. self.order .. '_LateralVel'] = self.lateralVel
|
wire.ports['W_' .. self.order .. '_LateralVel'] = self.lateralVel
|
||||||
|
wire.ports['SL_' .. self.order .. '_SteeringAngle'] = self.steeringAngle
|
||||||
|
wire.ports['SL_' .. self.order .. '_BaseLngVel'] = self.baseLngVel
|
||||||
end
|
end
|
||||||
|
|
||||||
function Slave:update()
|
function Slave:update()
|
||||||
self.entity = wire.ports['SL_' .. self.order]
|
|
||||||
self.wheel = wire.ports['W_' .. self.order]
|
|
||||||
|
|
||||||
if isValid(self.entity) and isValid(self.base) and isValid(self.wheel) then
|
if isValid(self.entity) and isValid(self.base) and isValid(self.wheel) then
|
||||||
local wheelMass = self.wheel:getMass()
|
|
||||||
local wheelInertia = self.wheel:getInertia():getLength()
|
|
||||||
local wheelRadius = self.wheel:getModelRadius() / UNITS_PER_METER
|
|
||||||
local wheelFriction = self.wheel:getFriction()
|
|
||||||
local lateralVel = self.wheel:worldToLocal(self.wheel:getVelocity() + self.wheel:getPos())[2]
|
|
||||||
|
|
||||||
self.lateralVel = lateralVel
|
|
||||||
|
|
||||||
if math.abs(self.steer) > 0 then
|
|
||||||
self.correctingAngle = 0
|
|
||||||
else
|
|
||||||
self.lateralForce = wheelFriction * wheelMass * lateralVel / TICK_INTERVAL /
|
|
||||||
UNITS_PER_METER
|
|
||||||
self.selfAligningTorque = self.lateralForce * wheelRadius * 2
|
|
||||||
self.correctingAngle = self.selfAligningTorque / wheelInertia * TICK_INTERVAL
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.isRight then
|
|
||||||
self.correctingAngle = self.correctingAngle * -1
|
|
||||||
end
|
|
||||||
|
|
||||||
self.correctingAngle = 0
|
|
||||||
|
|
||||||
if not self.entity:isFrozen() and not self.entity:isPlayerHolding() then
|
if not self.entity:isFrozen() and not self.entity:isPlayerHolding() then
|
||||||
self.entity:setFrozen(1)
|
self.entity:setFrozen(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local inc = self.steer * self.lock * self.direction
|
local wheelMass = self.wheel:getMass()
|
||||||
self.steeringAngle = math.clamp(self.steeringAngle + inc + self.correctingAngle, -self.lock, self.lock)
|
local wheelInertia = self.wheel:getInertia():getLength()
|
||||||
|
local wheelRadius = self.wheel:getModelRadius() / UNITS_PER_METER
|
||||||
|
local wheelFriction = self.wheel:getFriction()
|
||||||
|
local wheelLocalVel = getLocalVelocity(self.wheel)
|
||||||
|
local baseLocalVel = getLocalVelocity(self.base)
|
||||||
|
local lateralVel = wheelLocalVel[2]
|
||||||
|
local baseLngVel = baseLocalVel[1]
|
||||||
|
|
||||||
local camber = self.isRight and -self.camber or self.camber
|
local camber = self.isRight and -self.camber or self.camber
|
||||||
local steerRatio = self.lock ~= 0 and self.steeringAngle / self.lock or 0
|
local steerRatio = self.lock ~= 0 and self.steeringAngle / self.lock or 0
|
||||||
@ -104,11 +83,23 @@ function Slave:update()
|
|||||||
ackermann = self.isRight and steerRatio * self.ackermann or -steerRatio * self.ackermann
|
ackermann = self.isRight and steerRatio * self.ackermann or -steerRatio * self.ackermann
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.lateralForce = wheelFriction * wheelMass * lateralVel / UNITS_PER_METER
|
||||||
|
self.selfAligningTorque = self.lateralForce * wheelRadius
|
||||||
|
|
||||||
|
self.correctingAngle = self.selfAligningTorque / wheelInertia * math.sin(math.rad(math.abs(self.caster * 2))) *
|
||||||
|
math.sign(baseLngVel) * (self.isRight and -1 or 1)
|
||||||
|
|
||||||
|
local inc = self.steer * self.lock * self.direction * math.cos(math.rad(math.abs(self.caster * 2)))
|
||||||
|
self.steeringAngle = math.clamp(self.steeringAngle + inc + self.correctingAngle, -self.lock, self.lock)
|
||||||
|
|
||||||
-- Dividing ackermann by 2 because ackermann angle is difference between wheels angle
|
-- Dividing ackermann by 2 because ackermann angle is difference between wheels angle
|
||||||
-- So if we don't divide it by 2, the result angle will be 2 times more than expected
|
-- So if we don't divide it by 2, the result angle will be 2 times more than expected
|
||||||
local angle = Angle(0, self.offset + self.steeringAngle + toe + ackermann / 2, camber - caster)
|
local angle = Angle(0, self.offset + self.steeringAngle + toe + ackermann / 2, camber + caster)
|
||||||
local localizedAngle = self.base:localToWorldAngles(angle)
|
local localizedAngle = self.base:localToWorldAngles(angle)
|
||||||
|
|
||||||
self.entity:setAngles(localizedAngle)
|
self.entity:setAngles(localizedAngle)
|
||||||
|
|
||||||
|
self.lateralVel = lateralVel
|
||||||
|
self.baseLngVel = baseLngVel
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,22 +1,22 @@
|
|||||||
-- @include /koptilnya/libs/wire_component.txt
|
-- @include /koptilnya/libs/wire_component.txt
|
||||||
-- @include ./slave.txt
|
-- @include ./steering_axle.txt
|
||||||
-- @include /koptilnya/libs/table.txt
|
-- @include /koptilnya/libs/table.txt
|
||||||
require('/koptilnya/libs/wire_component.txt')
|
require('/koptilnya/libs/wire_component.txt')
|
||||||
require('./slave.txt')
|
require('./steering_axle.txt')
|
||||||
require('/koptilnya/libs/table.txt')
|
require('/koptilnya/libs/table.txt')
|
||||||
|
|
||||||
Steering = class('Steering', WireComponent)
|
Steering = class('Steering', WireComponent)
|
||||||
|
|
||||||
function Steering:initialize(options)
|
function Steering:initialize(options)
|
||||||
options = options or {}
|
options = options or {}
|
||||||
self.slaves = {}
|
self.axles = {}
|
||||||
self.steer = 0
|
self.steer = 0
|
||||||
self.sensitivity = options.Sensitivity or 1
|
self.sensitivity = options.Sensitivity or 1
|
||||||
|
|
||||||
for key, slave in ipairs(options.Slaves) do
|
for key, axle in ipairs(options.Axles) do
|
||||||
slave.Order = key
|
axle.Order = key
|
||||||
slave.Base = wire.ports.Base
|
axle.Base = wire.ports.Base
|
||||||
table.insert(self.slaves, Slave:new(slave))
|
table.insert(self.axles, SteeringAxle:new(axle))
|
||||||
end
|
end
|
||||||
|
|
||||||
self:_adjustPorts()
|
self:_adjustPorts()
|
||||||
@ -33,9 +33,9 @@ function Steering:_adjustPorts()
|
|||||||
inputs = table.merge(inputs, self:getInputs())
|
inputs = table.merge(inputs, self:getInputs())
|
||||||
outputs = table.merge(outputs, self:getOutputs())
|
outputs = table.merge(outputs, self:getOutputs())
|
||||||
|
|
||||||
for _, slave in ipairs(self.slaves) do
|
for _, axle in ipairs(self.axles) do
|
||||||
inputs = table.merge(inputs, slave:getInputs())
|
inputs = table.merge(inputs, axle:getInputs())
|
||||||
outputs = table.merge(outputs, slave:getOutputs())
|
outputs = table.merge(outputs, axle:getOutputs())
|
||||||
end
|
end
|
||||||
|
|
||||||
wire.adjustPorts(inputs, outputs)
|
wire.adjustPorts(inputs, outputs)
|
||||||
@ -55,15 +55,15 @@ function Steering:getOutputs()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Steering:updateOutputs()
|
function Steering:updateOutputs()
|
||||||
local totalSteeringAngle = table.reduce(self.slaves, function(steer, slave)
|
-- local totalSteeringAngle = table.reduce(self.slaves, function(steer, slave)
|
||||||
return steer + slave.direction * slave.steeringAngle / (slave.lock ~= 0 and slave.lock or 1)
|
-- return steer + slave.direction * slave.steeringAngle / (slave.lock ~= 0 and slave.lock or 1)
|
||||||
end, 0)
|
-- end, 0)
|
||||||
|
|
||||||
local steerableSlaves = table.filter(self.slaves, function(slave)
|
-- local steerableSlaves = table.filter(self.slaves, function(slave)
|
||||||
return slave.lock ~= 0
|
-- return slave.lock ~= 0
|
||||||
end)
|
-- end)
|
||||||
|
|
||||||
wire.ports.Steer = totalSteeringAngle / #steerableSlaves
|
-- wire.ports.Steer = totalSteeringAngle / #steerableSlaves
|
||||||
end
|
end
|
||||||
|
|
||||||
function Steering:update()
|
function Steering:update()
|
||||||
@ -71,9 +71,9 @@ function Steering:update()
|
|||||||
|
|
||||||
self:updateOutputs()
|
self:updateOutputs()
|
||||||
|
|
||||||
for _, slave in ipairs(self.slaves) do
|
for _, axle in ipairs(self.axles) do
|
||||||
slave.steer = self.steer
|
axle.steer = self.steer
|
||||||
slave:update()
|
axle:update()
|
||||||
slave:updateOutputs()
|
axle:updateOutputs()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
69
koptilnya/better_steering/steering_axle.txt
Normal file
69
koptilnya/better_steering/steering_axle.txt
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
-- @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
|
||||||
@ -26,7 +26,8 @@ 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.321, 1.902, 1.308, 1, 0.838}, Reverse = 3.382},
|
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 = 1, FinalDrive = 3.9}
|
{Power = 0.96, Coast = 0.96, Preload = 10, UsePowerBias = 10, ViscousCoeff = 0.96, Axle = Vector(1, 0, 0), DistributionCoeff = 0.8, FinalDrive = 3.9},
|
||||||
|
{Power = 0.96, Coast = 0.96, Preload = 10, UsePowerBias = 10, ViscousCoeff = 0.96, Axle = Vector(1, 0, 0), DistributionCoeff = 1.2, FinalDrive = 3.9},
|
||||||
},
|
},
|
||||||
Systems = {{Type = 'LAUNCH', Limit = 3500}, {Type = 'TRACTION', Limit = 1.5}}
|
Systems = {{Type = 'LAUNCH', Limit = 3500}, {Type = 'TRACTION', Limit = 1.5}}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -15,6 +15,11 @@ Axles = {
|
|||||||
Gravity = 0.15,
|
Gravity = 0.15,
|
||||||
Sensitivity = 0.25
|
Sensitivity = 0.25
|
||||||
},
|
},
|
||||||
|
Brakes = {
|
||||||
|
Positive = KEY.S,
|
||||||
|
Gravity = 0.15,
|
||||||
|
Sensitivity = 0.25
|
||||||
|
},
|
||||||
Shifter = {
|
Shifter = {
|
||||||
Positive = MOUSE.LEFT,
|
Positive = MOUSE.LEFT,
|
||||||
Negative = MOUSE.RIGHT,
|
Negative = MOUSE.RIGHT,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user