Add Engine Controller Component

This commit is contained in:
2022-06-30 23:18:54 +01:00
parent 3a4bf205cf
commit 6cc5ed68ef
5 changed files with 38 additions and 11 deletions

View File

@@ -4,7 +4,7 @@ local defaultTable = {
velocity_x_in = 0,
current_velocity_x_in = 0,
set_trm_target = 20,
set_trm_aggression = 600,
set_trm_aggression = 200,
set_mode = 1,
set_silent = 0,
acceleration = 0,
@@ -25,6 +25,10 @@ local signalReceived = function(signal, connection)
local signalNum = tonumber(signal.value) or defaultTable[connection.Name]
if mem[connection.Name] == signalNum then
return
end
if connection.Name == "current_velocity_x_in" then
mem.acceleration = (signalNum - mem.current_velocity_x_in)
mem.current_velocity_x_in = signalNum
@@ -32,11 +36,6 @@ local signalReceived = function(signal, connection)
mem[connection.Name] = signalNum
end
-- Skip signals for optimization
if connection.Name ~= "velocity_x_in" then
return
end
local main_force_out
local boost_force_out
@@ -50,8 +49,7 @@ local signalReceived = function(signal, connection)
elseif mem.set_mode == 0 then
local absolute_current_velocity = math.abs(mem.current_velocity_x_in)
if mem.set_trm_target -0.25 < absolute_current_velocity and mem.velocity_x_in * mem.current_velocity_x_in > 0 then
if mem.set_trm_target - 0.25 < absolute_current_velocity and mem.velocity_x_in * mem.current_velocity_x_in > 0 then
local target_acceleration = - (absolute_current_velocity * mem.set_trm_aggression) + (mem.set_trm_target * mem.set_trm_aggression)
if math.abs(mem.velocity_x_in) > math.abs(target_acceleration) then