From fa96b2f59f1c7ac09c7bb3bba3f58f4a5485b384 Mon Sep 17 00:00:00 2001 From: templeofshadow Date: Tue, 30 Jun 2026 00:03:07 -0500 Subject: [PATCH] add aformentioned simplified stabilization for vessels with thrusters with the field populated correctly --- main.lua | 73 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/main.lua b/main.lua index 0c74253..73e3347 100644 --- a/main.lua +++ b/main.lua @@ -961,39 +961,54 @@ function UpdateGlobalThrust() for _, thruster in pairs(Thrusters) do local desiredThrust = 0 - -- Calculate desired thrust based on affectVectors and PID outputs - if thruster.affectVectors.angular.pitch ~= nil and thruster.primary_pitch_thruster then - if thruster.affectVectors.angular.pitch == "up" then - desiredThrust = desiredThrust + pitchRateOutput - else - desiredThrust = desiredThrust - pitchRateOutput - end - end - - if thruster.affectVectors.angular.roll ~= nil and thruster.primary_roll_thruster then - if thruster.affectVectors.angular.roll == "port" then - desiredThrust = desiredThrust + rollRateOutput - else - desiredThrust = desiredThrust - rollRateOutput + if thruster.x_config_equivalent ~= nil then + + -- Calculate desired thrust based on affectVectors and PID outputs + if thruster.affectVectors.angular.pitch ~= nil and thruster.primary_pitch_thruster then + if thruster.affectVectors.angular.pitch == "up" then + desiredThrust = desiredThrust + pitchRateOutput + else + desiredThrust = desiredThrust - pitchRateOutput + end end - end - - if thruster.affectVectors.angular.yaw ~= nil and thruster.primary_yaw_thruster then - if thruster.affectVectors.angular.yaw == "port" then - desiredThrust = desiredThrust + yawRateOutput - else - desiredThrust = desiredThrust - yawRateOutput + if thruster.affectVectors.angular.roll ~= nil and thruster.primary_roll_thruster then + if thruster.affectVectors.angular.roll == "port" then + desiredThrust = desiredThrust + rollRateOutput + else + desiredThrust = desiredThrust - rollRateOutput + end + + end + + if thruster.affectVectors.angular.yaw ~= nil and thruster.primary_yaw_thruster then + if thruster.affectVectors.angular.yaw == "port" then + desiredThrust = desiredThrust + yawRateOutput + else + desiredThrust = desiredThrust - yawRateOutput + end + end + + if thruster.affectVectors.lateral.y == "up" then + desiredThrust = desiredThrust + throttleOutput + end + + --if Config.Debug then print("DEBUG: "..thruster.name..": desiredThrust "..desiredThrust.." (from UpdateGlobalThrust)") end + + SetThrusterPower(thruster, desiredThrust) + else + local prop1 = throttleOutput + pitchRateOutput + rollRateOutput -- front-left + local prop2 = throttleOutput + pitchRateOutput - rollRateOutput -- front-right + local prop3 = throttleOutput - pitchRateOutput - rollRateOutput -- back-right + local prop4 = throttleOutput - pitchRateOutput + rollRateOutput -- back-left + + if thruster.x_config_equivalent == "1" then SetThrusterPower(thruster, prop1) + elseif thruster.x_config_equivalent == "2" then SetThrusterPower(thruster, prop2) + elseif thruster.x_config_equivalent == "3" then SetThrusterPower(thruster, prop3) + elseif thruster.x_config_equivalent == "4" then SetThrusterPower(thruster, prop4) + else print("ERROR: Thruster "..thruster.name.." has invalid x_config_equivalent value") end end - - if thruster.affectVectors.lateral.y == "up" then - desiredThrust = desiredThrust + throttleOutput - end - - --if Config.Debug then print("DEBUG: "..thruster.name..": desiredThrust "..desiredThrust.." (from UpdateGlobalThrust)") end - - SetThrusterPower(thruster, desiredThrust) end end