change thrust nomalization
This commit is contained in:
43
main.lua
43
main.lua
@@ -893,6 +893,40 @@ PIDs = {
|
|||||||
ForeAftRatePID = CreatePID(0.1, 0.01, 0.05)
|
ForeAftRatePID = CreatePID(0.1, 0.01, 0.05)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- min and max thrust for thrust normalization
|
||||||
|
local minThrust = 0
|
||||||
|
local maxThrust = 0
|
||||||
|
|
||||||
|
local function createRollingAverage(window)
|
||||||
|
local buffer = {}
|
||||||
|
local index = 0
|
||||||
|
local count = 0
|
||||||
|
local sum = 0
|
||||||
|
|
||||||
|
return function(new_value)
|
||||||
|
index = (index % window) + 1
|
||||||
|
|
||||||
|
if buffer[index] then
|
||||||
|
sum = sum - buffer[index]
|
||||||
|
else
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
buffer[index] = new_value
|
||||||
|
sum = sum + new_value
|
||||||
|
|
||||||
|
return sum / count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
MinRollingAverage = createRollingAverage(10)
|
||||||
|
MaxRollingAverage = createRollingAverage(10)
|
||||||
|
|
||||||
|
local function normalize(val, min, max)
|
||||||
|
if min == max then return 0.0 end
|
||||||
|
return (val - min) / (max - min)
|
||||||
|
end
|
||||||
|
|
||||||
function UpdateGlobalThrust()
|
function UpdateGlobalThrust()
|
||||||
-- for each thruster, there is a table of affectVectors that determine in what directions the thruster can apply thrust
|
-- for each thruster, there is a table of affectVectors that determine in what directions the thruster can apply thrust
|
||||||
-- each thruster has a power value from 0 to 1, which is the amount of thrust the thruster is currently applying
|
-- each thruster has a power value from 0 to 1, which is the amount of thrust the thruster is currently applying
|
||||||
@@ -936,8 +970,15 @@ function UpdateGlobalThrust()
|
|||||||
desiredThrust = desiredThrust + throttleOutput
|
desiredThrust = desiredThrust + throttleOutput
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if desiredThrust > maxThrust then maxThrust = desiredThrust end
|
||||||
|
if desiredThrust < minThrust then minThrust = desiredThrust end
|
||||||
|
|
||||||
|
local maxAverage = MaxRollingAverage(maxThrust)
|
||||||
|
local minAverage = MinRollingAverage(minThrust)
|
||||||
|
|
||||||
-- Normalize the desired thrust to be between 0 and 1
|
-- Normalize the desired thrust to be between 0 and 1
|
||||||
local normalizedThrust = CustomSigmoid(desiredThrust)
|
local normalizedThrust = normalize(desiredThrust, minAverage, maxAverage)
|
||||||
|
|
||||||
if normalizedThrust < 0 then normalizedThrust = 0 end
|
if normalizedThrust < 0 then normalizedThrust = 0 end
|
||||||
|
|
||||||
if Config.Debug then print("DEBUG: "..thruster.name..": desiredThrust "..desiredThrust..", normalizedThrust "..normalizedThrust) end
|
if Config.Debug then print("DEBUG: "..thruster.name..": desiredThrust "..desiredThrust..", normalizedThrust "..normalizedThrust) end
|
||||||
|
|||||||
Reference in New Issue
Block a user