diff --git a/main.lua b/main.lua index d4ff991..96f300d 100644 --- a/main.lua +++ b/main.lua @@ -118,20 +118,22 @@ Config.Autopilot = { } Throttles = { - ForeThrottle = { + fore = { name = nil, side = nil }, - AftThrottle = { + aft = { name = nil, side = nil }, - DownThrottle = { + down = { name = nil, side = nil } } + + function ThrottleInit() local sides = { @@ -168,65 +170,31 @@ function ThrottleInit() return states end - print("\nIdentifying fore throttle") - print("\nPlease change the input signal for the throttle") + local function identifyThrottle(throttleType) + print("Identifying "..throttleType.."throttle.") + print("\nPlease change the input signal for the throttle.") - local initialStates = getRelayStates() + local initialStates = getRelayStates() + + while true do + local currentStates = 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.ForeThrottle.name = pname - Throttles.ForeThrottle.side = k - return + for pname, currentState in ipairs(currentStates) do + local initialState = initialStates[pname] + for k, v in ipairs(currentState) do + if initialState[k] ~= v then + Throttles[throttleType].name = pname + Throttles[throttleType].side = k + return + end end end end end - print("\nIdentifying aft 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.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 + identifyThrottle("fore") + identifyThrottle("aft") + identifyThrottle("down") end function PropellerInit() @@ -785,5 +753,96 @@ function Main() 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 Main()