From eb708a54215e528b75175140df39dcf7e2803b7f Mon Sep 17 00:00:00 2001 From: templeofshadow Date: Thu, 25 Jun 2026 05:28:57 -0500 Subject: [PATCH] third ai assist --- main.lua | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 5 deletions(-) diff --git a/main.lua b/main.lua index a02ba79..b19286b 100644 --- a/main.lua +++ b/main.lua @@ -585,21 +585,177 @@ function Init() end end - -- Initialize monitors or return early if they're not configured + -- Initialize monitors - identify which monitor is for which type if Config.Monitors.InstrumentPanelMonitor == nil then - print("Warning: Instrument panel monitor not configured.") - end - if Config.Monitors.AutopilotControlMonitor == nil then - print("Warning: Autopilot control monitor not configured.") + print("Identifying instrument panel monitor...") + Config.Monitors.InstrumentPanelMonitor = identifyMonitor("instrument panel") end + if Config.Monitors.AutopilotControlMonitor == nil then + print("Identifying autopilot control monitor...") + Config.Monitors.AutopilotControlMonitor = identifyMonitor("autopilot control") + end + -- If we're here, the config loaded successfully and the initialization is done. 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.write("Manual: [ ]") + m.setCursorPos(1, 7) + m.setCursorPos(1, 8) + m.write("Mode: Auto") +end + +-- Sensor data collection - returns a table with all relevant sensor readings +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 + function Main() Init() while true do + local sensorData = collectSensorData() + + -- Update monitor displays + if Config.Monitors.InstrumentPanelMonitor then + displayInstrumentPanel(Config.Monitors.InstrumentPanelMonitor, sensorData) + end + + if Config.Monitors.AutopilotControlMonitor then + displayAutopilotControls(Config.Monitors.AutopilotControlMonitor, sensorData) + end + + local unindexedThrusters = checkIfThrusterIsIndexed() + if unindexedThrusters ~= nil then + partiallyUpdateThrusters(unindexedThrusters) + end + + PollSensors() + UpdateGlobalThrust() + UpdateStabilization() + + -- Add a small delay to avoid overloading the system + os.sleep(0.1) + end +end + +function displayAutopilotControls(monitor) + 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.write("Manual: [ ]") + m.setCursorPos(1, 7) + m.write("Mode: Auto") +end + +function Main() + Init() + + while true do + -- Update monitor displays + if Config.Monitors.InstrumentPanelMonitor then + displayInstrumentPanel(Config.Monitors.InstrumentPanelMonitor) + end + + if Config.Monitors.AutopilotControlMonitor then + displayAutopilotControls(Config.Monitors.AutopilotControlMonitor) + end + local unindexedThrusters = checkIfThrusterIsIndexed() if unindexedThrusters ~= nil then partiallyUpdateThrusters(unindexedThrusters)