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 = {
|
Thrusters = {} -- Table of thruster tables; see docs.md####Thrusters for the details of the thruster table structure
|
||||||
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
|
|
||||||
|
|
||||||
ThrustDirections = {
|
ThrustDirections = {
|
||||||
Angular = {
|
Angular = {
|
||||||
@@ -288,18 +255,30 @@ function PropellerInit()
|
|||||||
type = "rotator",
|
type = "rotator",
|
||||||
thruster = pv,
|
thruster = pv,
|
||||||
transmission = tv,
|
transmission = tv,
|
||||||
-- NOTE:
|
--[[
|
||||||
-- affectVectors will have values depending on how the thruster's
|
NOTE:
|
||||||
-- thrust vector interacts with the vessel's attitude
|
affectVectors will have values depending on how the thruster's
|
||||||
-- possible directions for yaw: "port"|"star"
|
thrust vector interacts with the vessel's attitude
|
||||||
-- possible directions for roll: "port"|"star"
|
angular:
|
||||||
-- possible directions for pitch: "up"|"down"
|
possible directions for angular.yaw: "port"|"star"
|
||||||
-- possible directions for lateral: "port"|"star"|"fore"|"aft"|"up"|"down"
|
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 = {
|
affectVectors = {
|
||||||
yaw = nil,
|
angular = {
|
||||||
pitch = nil,
|
yaw = nil,
|
||||||
roll = nil,
|
pitch = nil,
|
||||||
lateral = nil
|
roll = nil
|
||||||
|
},
|
||||||
|
lateral = {
|
||||||
|
x = nil,
|
||||||
|
y = nil,
|
||||||
|
z = nil
|
||||||
|
}
|
||||||
},
|
},
|
||||||
power = (tv.getSignal())/15
|
power = (tv.getSignal())/15
|
||||||
}
|
}
|
||||||
@@ -333,18 +312,30 @@ function ThrusterInit()
|
|||||||
thruster = tv,
|
thruster = tv,
|
||||||
transmission = nil,
|
transmission = nil,
|
||||||
type = "thruster",
|
type = "thruster",
|
||||||
-- NOTE:
|
--[[
|
||||||
-- affectVectors will have values depending on how the thruster's
|
NOTE:
|
||||||
-- thrust vector interacts with the vessel's attitude
|
affectVectors will have values depending on how the thruster's
|
||||||
-- possible directions for yaw: "port"|"star"
|
thrust vector interacts with the vessel's attitude
|
||||||
-- possible directions for roll: "port"|"star"
|
angular:
|
||||||
-- possible directions for pitch: "up"|"down"
|
possible directions for angular.yaw: "port"|"star"
|
||||||
-- possible directions for lateral: "port"|"star"|"fore"|"aft"|"up"|"down"
|
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 = {
|
affectVectors = {
|
||||||
yaw = nil,
|
angular = {
|
||||||
pitch = nil,
|
yaw = nil,
|
||||||
roll = nil,
|
pitch = nil,
|
||||||
lateral = nil
|
roll = nil
|
||||||
|
},
|
||||||
|
lateral = {
|
||||||
|
x = nil,
|
||||||
|
y = nil,
|
||||||
|
z = nil
|
||||||
|
}
|
||||||
},
|
},
|
||||||
power = tv.getPower()
|
power = tv.getPower()
|
||||||
}
|
}
|
||||||
@@ -422,10 +413,16 @@ local function partiallyUpdateThrusters(thrusterList)
|
|||||||
transmission = nil,
|
transmission = nil,
|
||||||
type = "thruster",
|
type = "thruster",
|
||||||
affectVectors = {
|
affectVectors = {
|
||||||
yaw = nil,
|
angular = {
|
||||||
roll = nil,
|
yaw = nil,
|
||||||
pitch = nil,
|
roll = nil,
|
||||||
lateral = nil
|
pitch = nil
|
||||||
|
},
|
||||||
|
lateral = {
|
||||||
|
x = nil,
|
||||||
|
y = nil,
|
||||||
|
z = nil
|
||||||
|
}
|
||||||
},
|
},
|
||||||
power = tv.getPower()
|
power = tv.getPower()
|
||||||
}
|
}
|
||||||
@@ -439,10 +436,16 @@ local function partiallyUpdateThrusters(thrusterList)
|
|||||||
transmission = nil,
|
transmission = nil,
|
||||||
type = "rotator",
|
type = "rotator",
|
||||||
affectVectors = {
|
affectVectors = {
|
||||||
yaw = nil,
|
angular = {
|
||||||
roll = nil,
|
yaw = nil,
|
||||||
pitch = nil,
|
roll = nil,
|
||||||
lateral = nil
|
pitch = nil
|
||||||
|
},
|
||||||
|
lateral = {
|
||||||
|
x = nil,
|
||||||
|
y = nil,
|
||||||
|
z = nil
|
||||||
|
}
|
||||||
},
|
},
|
||||||
power = tv.getPower()
|
power = tv.getPower()
|
||||||
}
|
}
|
||||||
@@ -462,14 +465,6 @@ local function partiallyUpdateThrusters(thrusterList)
|
|||||||
end
|
end
|
||||||
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()
|
function PollThrottle()
|
||||||
for _, v in pairs(Config.Throttles) do
|
for _, v in pairs(Config.Throttles) do
|
||||||
if v.name and v.side then
|
if v.name and v.side then
|
||||||
@@ -724,17 +719,25 @@ function UpdateGlobalLateralThrust()
|
|||||||
-- verify that SensorData.Velocity.Raw is not nil
|
-- verify that SensorData.Velocity.Raw is not nil
|
||||||
if SensorData.Velocity == nil or SensorData.Velocity.Raw == nil then
|
if SensorData.Velocity == nil or SensorData.Velocity.Raw == nil then
|
||||||
if Config.Debug 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
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: Refactor this
|
||||||
|
|
||||||
local desiredLateralThrustVectors = {}
|
local desiredLateralThrustVectors = {}
|
||||||
|
|
||||||
for f, v in pairs(SensorData.Velocity.Raw) do
|
for f, v in pairs(SensorData.Velocity.Raw) do
|
||||||
desiredLateralThrustVectors[f] = CustomSigmoid(v)
|
desiredLateralThrustVectors[f] = CustomSigmoid(v)
|
||||||
end
|
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 = {}
|
local thrustDirections = {}
|
||||||
for f, v in pairs(desiredLateralThrustVectors) do
|
for f, v in pairs(desiredLateralThrustVectors) do
|
||||||
if f == "x" then
|
if f == "x" then
|
||||||
@@ -746,16 +749,20 @@ function UpdateGlobalLateralThrust()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, d in pairs(thrustDirections) do
|
--[[
|
||||||
for _, t in pairs(Thrusters) do
|
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
|
||||||
if t.affectVectors.lateral == d then
|
like so:
|
||||||
local correctedPower = GetThrusterPower(t) + d
|
thrustDirections = {
|
||||||
if correctedPower > 1 then correctedPower = 1 end
|
{ port = 0.5 },
|
||||||
if correctedPower < 0 then correctedPower = 0 end
|
{ down = 0.1 },
|
||||||
SetThrusterPower(t, correctedPower)
|
{ aft = 0.6 }
|
||||||
end
|
}
|
||||||
end
|
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
|
||||||
end
|
(angular thrust is the same, but with different keys for the tables, like pitchup/pitchdown, yawport/yawstar, rollport/rollstar)
|
||||||
|
|
||||||
|
]]
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function UpdateGlobalAngularThrust()
|
function UpdateGlobalAngularThrust()
|
||||||
@@ -763,38 +770,12 @@ function UpdateGlobalAngularThrust()
|
|||||||
-- verify that SensorData.Gimbal.AngularRates is not nil
|
-- verify that SensorData.Gimbal.AngularRates is not nil
|
||||||
if SensorData.Gimbal == nil or SensorData.Gimbal.AngularRates == nil then
|
if SensorData.Gimbal == nil or SensorData.Gimbal.AngularRates == nil then
|
||||||
if Config.Debug 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
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local desiredAngularThrustVectors = {}
|
-- TODO: Implement this
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
|
|||||||
Reference in New Issue
Block a user