refactored thruster init to follow new thruster schema; removed redundant UpdateStabilization function; removed some implimentation from the UpdateGlobalThrust functions in preparation for refactor
This commit is contained in:
203
main.lua
203
main.lua
@@ -1,37 +1,4 @@
|
||||
Thrusters = {
|
||||
thruster0 = {
|
||||
type = "rotator",
|
||||
name = nil,
|
||||
thruster = nil,
|
||||
transmission = nil,
|
||||
-- NOTE:
|
||||
-- affectVectors will have values depending on how the thruster's
|
||||
-- thrust vector interacts with the vessel's attitude
|
||||
-- possible directions for yaw: "port"|"star"
|
||||
-- possible directions for roll: "port"|"star"
|
||||
-- possible directions for pitch: "up"|"down"
|
||||
-- possible directions for lateral: "port"|"star"|"fore"|"aft"|"up"|"down"
|
||||
affectVectors = {
|
||||
yaw = nil,
|
||||
pitch = nil,
|
||||
roll = nil,
|
||||
lateral = nil
|
||||
},
|
||||
power = 0
|
||||
},
|
||||
thruster1 = {
|
||||
type = "thruster",
|
||||
name = nil,
|
||||
thruster = nil,
|
||||
affectVectors = {
|
||||
yaw = nil,
|
||||
pitch = nil,
|
||||
roll = nil,
|
||||
lateral = nil
|
||||
},
|
||||
power = 0
|
||||
}
|
||||
} -- Table of thruster tables
|
||||
Thrusters = {} -- Table of thruster tables; see docs.md####Thrusters for the details of the thruster table structure
|
||||
|
||||
ThrustDirections = {
|
||||
Angular = {
|
||||
@@ -288,18 +255,30 @@ function PropellerInit()
|
||||
type = "rotator",
|
||||
thruster = pv,
|
||||
transmission = tv,
|
||||
-- NOTE:
|
||||
-- affectVectors will have values depending on how the thruster's
|
||||
-- thrust vector interacts with the vessel's attitude
|
||||
-- possible directions for yaw: "port"|"star"
|
||||
-- possible directions for roll: "port"|"star"
|
||||
-- possible directions for pitch: "up"|"down"
|
||||
-- possible directions for lateral: "port"|"star"|"fore"|"aft"|"up"|"down"
|
||||
--[[
|
||||
NOTE:
|
||||
affectVectors will have values depending on how the thruster's
|
||||
thrust vector interacts with the vessel's attitude
|
||||
angular:
|
||||
possible directions for angular.yaw: "port"|"star"
|
||||
possible directions for angular.roll: "port"|"star"
|
||||
possible directions for angular.pitch: "up"|"down"
|
||||
lateral:
|
||||
possible directions for lateral.x: "port"|"star"
|
||||
possible directions for lateral.y: "up"|"down"
|
||||
possible directions for lateral.z: "fore"|"aft"
|
||||
]]
|
||||
affectVectors = {
|
||||
yaw = nil,
|
||||
pitch = nil,
|
||||
roll = nil,
|
||||
lateral = nil
|
||||
angular = {
|
||||
yaw = nil,
|
||||
pitch = nil,
|
||||
roll = nil
|
||||
},
|
||||
lateral = {
|
||||
x = nil,
|
||||
y = nil,
|
||||
z = nil
|
||||
}
|
||||
},
|
||||
power = (tv.getSignal())/15
|
||||
}
|
||||
@@ -333,18 +312,30 @@ function ThrusterInit()
|
||||
thruster = tv,
|
||||
transmission = nil,
|
||||
type = "thruster",
|
||||
-- NOTE:
|
||||
-- affectVectors will have values depending on how the thruster's
|
||||
-- thrust vector interacts with the vessel's attitude
|
||||
-- possible directions for yaw: "port"|"star"
|
||||
-- possible directions for roll: "port"|"star"
|
||||
-- possible directions for pitch: "up"|"down"
|
||||
-- possible directions for lateral: "port"|"star"|"fore"|"aft"|"up"|"down"
|
||||
--[[
|
||||
NOTE:
|
||||
affectVectors will have values depending on how the thruster's
|
||||
thrust vector interacts with the vessel's attitude
|
||||
angular:
|
||||
possible directions for angular.yaw: "port"|"star"
|
||||
possible directions for angular.roll: "port"|"star"
|
||||
possible directions for angular.pitch: "up"|"down"
|
||||
lateral:
|
||||
possible directions for lateral.x: "port"|"star"
|
||||
possible directions for lateral.y: "up"|"down"
|
||||
possible directions for lateral.z: "fore"|"aft"
|
||||
]]
|
||||
affectVectors = {
|
||||
yaw = nil,
|
||||
pitch = nil,
|
||||
roll = nil,
|
||||
lateral = nil
|
||||
angular = {
|
||||
yaw = nil,
|
||||
pitch = nil,
|
||||
roll = nil
|
||||
},
|
||||
lateral = {
|
||||
x = nil,
|
||||
y = nil,
|
||||
z = nil
|
||||
}
|
||||
},
|
||||
power = tv.getPower()
|
||||
}
|
||||
@@ -422,10 +413,16 @@ local function partiallyUpdateThrusters(thrusterList)
|
||||
transmission = nil,
|
||||
type = "thruster",
|
||||
affectVectors = {
|
||||
yaw = nil,
|
||||
roll = nil,
|
||||
pitch = nil,
|
||||
lateral = nil
|
||||
angular = {
|
||||
yaw = nil,
|
||||
roll = nil,
|
||||
pitch = nil
|
||||
},
|
||||
lateral = {
|
||||
x = nil,
|
||||
y = nil,
|
||||
z = nil
|
||||
}
|
||||
},
|
||||
power = tv.getPower()
|
||||
}
|
||||
@@ -439,10 +436,16 @@ local function partiallyUpdateThrusters(thrusterList)
|
||||
transmission = nil,
|
||||
type = "rotator",
|
||||
affectVectors = {
|
||||
yaw = nil,
|
||||
roll = nil,
|
||||
pitch = nil,
|
||||
lateral = nil
|
||||
angular = {
|
||||
yaw = nil,
|
||||
roll = nil,
|
||||
pitch = nil
|
||||
},
|
||||
lateral = {
|
||||
x = nil,
|
||||
y = nil,
|
||||
z = nil
|
||||
}
|
||||
},
|
||||
power = tv.getPower()
|
||||
}
|
||||
@@ -462,14 +465,6 @@ local function partiallyUpdateThrusters(thrusterList)
|
||||
end
|
||||
end
|
||||
|
||||
function UpdateStabilization()
|
||||
-- This function needs full implementation according to requirements in docs.md
|
||||
-- It should adjust thrust based on sensor data to achieve target angles/velocities
|
||||
|
||||
-- For now, implement placeholder functionality that calls the existing thrust methods
|
||||
print("UpdateStabilization called")
|
||||
end
|
||||
|
||||
function PollThrottle()
|
||||
for _, v in pairs(Config.Throttles) do
|
||||
if v.name and v.side then
|
||||
@@ -724,17 +719,25 @@ function UpdateGlobalLateralThrust()
|
||||
-- verify that SensorData.Velocity.Raw is not nil
|
||||
if SensorData.Velocity == nil or SensorData.Velocity.Raw == nil then
|
||||
if Config.Debug then
|
||||
print("DEBUG: SensorData.Velocity.Raw is nil, skipping UpdateGlobalLateralThrust")
|
||||
print("DEBUG: SensorData.Velocity.Raw or SensorData.Velocity is nil, skipping UpdateGlobalLateralThrust")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- TODO: Refactor this
|
||||
|
||||
local desiredLateralThrustVectors = {}
|
||||
|
||||
for f, v in pairs(SensorData.Velocity.Raw) do
|
||||
desiredLateralThrustVectors[f] = CustomSigmoid(v)
|
||||
end
|
||||
|
||||
--[[
|
||||
desiredLateralThrustVectors is a table that is similar to SensorData.Velocity.Raw, but with values between -1 and 1.
|
||||
essentially, it reverses the velocity vector and then clamps the range between -1 and 1, so that the value can be used for thrust power
|
||||
|
||||
]]
|
||||
|
||||
local thrustDirections = {}
|
||||
for f, v in pairs(desiredLateralThrustVectors) do
|
||||
if f == "x" then
|
||||
@@ -746,16 +749,20 @@ function UpdateGlobalLateralThrust()
|
||||
end
|
||||
end
|
||||
|
||||
for _, d in pairs(thrustDirections) do
|
||||
for _, t in pairs(Thrusters) do
|
||||
if t.affectVectors.lateral == d then
|
||||
local correctedPower = GetThrusterPower(t) + d
|
||||
if correctedPower > 1 then correctedPower = 1 end
|
||||
if correctedPower < 0 then correctedPower = 0 end
|
||||
SetThrusterPower(t, correctedPower)
|
||||
end
|
||||
end
|
||||
end
|
||||
--[[
|
||||
thrustDirections is an array of tables, each table has a key that is the direction of the desired thrust, and a value that is the magnitude of the desired thrust
|
||||
like so:
|
||||
thrustDirections = {
|
||||
{ port = 0.5 },
|
||||
{ down = 0.1 },
|
||||
{ aft = 0.6 }
|
||||
}
|
||||
there will only ever be three tables in thrustDirections, as there are only three axes of movement, and each axis can only have one desired thrust direction at a time
|
||||
(angular thrust is the same, but with different keys for the tables, like pitchup/pitchdown, yawport/yawstar, rollport/rollstar)
|
||||
|
||||
]]
|
||||
|
||||
|
||||
end
|
||||
|
||||
function UpdateGlobalAngularThrust()
|
||||
@@ -763,38 +770,12 @@ function UpdateGlobalAngularThrust()
|
||||
-- verify that SensorData.Gimbal.AngularRates is not nil
|
||||
if SensorData.Gimbal == nil or SensorData.Gimbal.AngularRates == nil then
|
||||
if Config.Debug then
|
||||
print("DEBUG: SensorData.Gimbal.AngularRates is nil, skipping UpdateGlobalAngularThrust")
|
||||
print("DEBUG: SensorData.Gimbal.AngularRates or SensorData.Gimbal is nil, skipping UpdateGlobalAngularThrust")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local desiredAngularThrustVectors = {}
|
||||
|
||||
for f, v in pairs(SensorData.Gimbal.AngularRates) do
|
||||
desiredAngularThrustVectors[f] = CustomSigmoid(v)
|
||||
end
|
||||
|
||||
local thrustDirections = {}
|
||||
for f, v in pairs(desiredAngularThrustVectors) do
|
||||
if f == "wx" then
|
||||
if v > 0 then table.insert(thrustDirections, { pitchdown = v }) else table.insert(thrustDirections, { pitchup = math.abs(v) }) end
|
||||
elseif f == "wy" then
|
||||
if v > 0 then table.insert(thrustDirections, { yawport = v }) else table.insert(thrustDirections, { yawstar = math.abs(v) }) end
|
||||
elseif f == "wz" then
|
||||
if v > 0 then table.insert(thrustDirections, { rollport = v }) else table.insert(thrustDirections, { rollstar = math.abs(v) }) end
|
||||
end
|
||||
end
|
||||
|
||||
for _, d in pairs(thrustDirections) do
|
||||
for _, t in pairs(Thrusters) do
|
||||
if t.affectVectors.angular == d then
|
||||
local correctedPower = GetThrusterPower(t) + d
|
||||
if correctedPower > 1 then correctedPower = 1 end
|
||||
if correctedPower < 0 then correctedPower = 0 end
|
||||
SetThrusterPower(t, correctedPower)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- TODO: Implement this
|
||||
end
|
||||
|
||||
function Init()
|
||||
|
||||
Reference in New Issue
Block a user