fourth ai assist plus generalizing throttle identification code

This commit is contained in:
2026-06-25 11:07:08 -05:00
parent 1d690c6087
commit 3528c9628e

167
main.lua
View File

@@ -118,20 +118,22 @@ Config.Autopilot = {
} }
Throttles = { Throttles = {
ForeThrottle = { fore = {
name = nil, name = nil,
side = nil side = nil
}, },
AftThrottle = { aft = {
name = nil, name = nil,
side = nil side = nil
}, },
DownThrottle = { down = {
name = nil, name = nil,
side = nil side = nil
} }
} }
function ThrottleInit() function ThrottleInit()
local sides = { local sides = {
@@ -168,65 +170,31 @@ function ThrottleInit()
return states return states
end end
print("\nIdentifying fore throttle") local function identifyThrottle(throttleType)
print("\nPlease change the input signal for the throttle") print("Identifying "..throttleType.."throttle.")
print("\nPlease change the input signal for the throttle.")
local initialStates = getRelayStates() local initialStates = getRelayStates()
while true do while true do
local currentStates = getRelayStates() local currentStates = getRelayStates()
for pname, currentState in ipairs(currentStates) do for pname, currentState in ipairs(currentStates) do
local initialState = initialStates[pname] local initialState = initialStates[pname]
for k, v in ipairs(currentState) do for k, v in ipairs(currentState) do
if initialState[k] ~= v then if initialState[k] ~= v then
Throttles.ForeThrottle.name = pname Throttles[throttleType].name = pname
Throttles.ForeThrottle.side = k Throttles[throttleType].side = k
return return
end
end end
end end
end end
end end
print("\nIdentifying aft throttle") identifyThrottle("fore")
print("\nPlease change the input signal for the throttle") identifyThrottle("aft")
identifyThrottle("down")
local initialStates = getRelayStates()
while true do
local currentStates = getRelayStates()
for pname, currentState in ipairs(currentStates) do
local initialState = initialStates[pname]
for k, v in ipairs(currentState) do
if initialState[k] ~= v then
Throttles.AftThrottle.name = pname
Throttles.AftThrottle.side = k
return
end
end
end
end
print("\nIdentifying down throttle")
print("\nPlease change the input signal for the throttle")
local initialStates = getRelayStates()
while true do
local currentStates = getRelayStates()
for pname, currentState in ipairs(currentStates) do
local initialState = initialStates[pname]
for k, v in ipairs(currentState) do
if initialState[k] ~= v then
Throttles.DownThrottle.name = pname
Throttles.DownThrottle.side = k
return
end
end
end
end
end end
function PropellerInit() function PropellerInit()
@@ -785,5 +753,96 @@ function Main()
end end
end end
-- Display functions for monitors
function displayInstrumentPanel(monitor, sensorData)
if not monitor or not monitor.peripheral then return end
local m = monitor.peripheral
m.clear()
m.setCursorPos(1, 1)
-- Simple instrument panel display
m.write("Caero Attitude Control")
m.setCursorPos(1, 2)
m.write("----------------------")
if sensorData then
m.setCursorPos(1, 3)
m.write("Pitch: " .. string.format("%.2f", sensorData.gimbal.pitch or 0))
m.setCursorPos(1, 4)
m.write("Roll: " .. string.format("%.2f", sensorData.gimbal.roll or 0))
m.setCursorPos(1, 5)
m.write("Yaw: " .. string.format("%.2f", sensorData.navTable.heading or 0))
m.setCursorPos(1, 6)
m.write("Velocity: " .. string.format("%.2f", sensorData.velocity or 0))
m.setCursorPos(1, 7)
m.write("Altitude: " .. string.format("%.2f", sensorData.altitude or 0))
else
m.setCursorPos(1, 3)
m.write("Pitch: 0.00")
m.setCursorPos(1, 4)
m.write("Roll: 0.00")
m.setCursorPos(1, 5)
m.write("Yaw: 0.00")
m.setCursorPos(1, 6)
m.write("Velocity: 0.00")
m.setCursorPos(1, 7)
m.write("Altitude: 0.00")
end
-- Display autopilot status
local autopilotStatus = Config.Autopilot.AutopilotEngaged and "ON" or "OFF"
m.setCursorPos(1, 9)
m.write("Autopilot: " .. autopilotStatus)
end
function displayAutopilotControls(monitor, sensorData)
if not monitor or not monitor.peripheral then return end
local m = monitor.peripheral
m.clear()
m.setCursorPos(1, 1)
-- Simple autopilot control panel
m.write("Autopilot Controls")
m.setCursorPos(1, 2)
m.write("------------------")
m.setCursorPos(1, 3)
m.write("Engage: [ ]")
m.setCursorPos(1, 4)
m.write("Speed: [0.0]")
m.setCursorPos(1, 5)
m.write("Heading: [0.0]")
m.setCursorPos(1, 6)
m.setCursorPos(1, 7)
m.write("Manual: [ ]")
m.setCursorPos(1, 8)
m.write("Mode: Auto")
end
function collectSensorData()
local data = {}
-- Collect gimbal data
data.gimbal = {
pitch = 0,
roll = 0
}
-- Collect navigation table data
data.navTable = {
heading = 0,
hasTarget = false
}
-- Collect altitude data
data.altitude = 0
-- Collect velocity data
data.velocity = 0
return data
end
-- Run the main function when the script starts -- Run the main function when the script starts
Main() Main()