begin properly implementing monitor display logic

This commit is contained in:
2026-06-25 17:37:42 -05:00
parent e44603336b
commit 5bdd71ecde

View File

@@ -33,6 +33,8 @@ Thrusters = {
} }
} -- Table of thruster tables } -- Table of thruster tables
SensorData = {}
ThrusterTypes = { ThrusterTypes = {
"thruster", "thruster",
"solid_fuel_thruster", "solid_fuel_thruster",
@@ -455,21 +457,38 @@ function PollVelocity()
-- Velocity Sensors -- Velocity Sensors
VelocityVectors = {} VelocityVectors = {}
local next = next
if next(velSensors) == nil then
SensorData.Velocity = {}
for vsindex, velsensor in pairs(velSensors) do for vsindex, velsensor in pairs(velSensors) do
local vsAxis = velsensor.getAxis() local vsAxis = velsensor.getAxis()
local vsVelocity = velsensor.getVelocity() local vsVelocity = velsensor.getVelocity()
VelocityVectors[vsAxis] = vsVelocity VelocityVectors[vsAxis] = vsVelocity
SensorData.Velocity.Raw = VelocityVectors
end end
end end
end
function PollAltitude() function PollAltitude()
local altSensor = peripheral.find("altitude_sensor") -- enforce one alt sensor local altSensor = peripheral.find("altitude_sensor") -- enforce one alt sensor
-- Altitude Sensor -- Altitude Sensor
if altSensor then if altSensor then
SensorData.Altitude = {}
Altitude = altSensor.getHeight() Altitude = altSensor.getHeight()
AirPressure = altSensor.getAirPressure() AirPressure = altSensor.getAirPressure()
VerticalSpeed = altSensor.getVerticalSpeed() VerticalSpeed = altSensor.getVerticalSpeed()
SensorData.Altitude.Altitude = Altitude
SensorData.Altitude.AirPressure = AirPressure
SensorData.Altitude.VerticalSpeed = VerticalSpeed
end end
end end
@@ -478,8 +497,14 @@ function PollNavTable()
-- Navigation Table -- Navigation Table
if navTable then if navTable then
SensorData.NavTable = {}
Heading = navTable.getHeading() Heading = navTable.getHeading()
NavTableHasTarget = navTable.hasTarget() NavTableHasTarget = navTable.hasTarget()
SensorData.NavTable.Heading = Heading
SensorData.NavTable.HasTarget = NavTableHasTarget
if NavTableHasTarget then if NavTableHasTarget then
BearingToTarget = navTable.getBearing() BearingToTarget = navTable.getBearing()
TargetClosureRate = navTable.getClosureRate() TargetClosureRate = navTable.getClosureRate()
@@ -492,13 +517,11 @@ function PollNavTable()
TargetVerticalOffset = 0 TargetVerticalOffset = 0
TargetRelativeAngle = 0 TargetRelativeAngle = 0
end end
else
Heading = 0 SensorData.NavTable.TargetBearing = BearingToTarget
NavTableHasTarget = false SensorData.NavTable.TargetClosureRate = TargetClosureRate
BearingToTarget = 0 SensorData.NavTable.TargetVerticalOffset = TargetVerticalOffset
TargetClosureRate = 0 SensorData.NavTable.TargetRelativeAngle = TargetRelativeAngle
TargetVerticalOffset = 0
TargetRelativeAngle = 0
end end
end end
@@ -507,13 +530,16 @@ function PollGimbal()
-- Gimbal Sensor -- Gimbal Sensor
if gimbalSensor then if gimbalSensor then
SensorData.Gimbal = {}
Angles = gimbalSensor.getAngles() Angles = gimbalSensor.getAngles()
AngularRates = gimbalSensor.getAngularRates() AngularRates = gimbalSensor.getAngularRates()
LinearAcceleration = gimbalSensor.getLinearAcceleration() LinearAcceleration = gimbalSensor.getLinearAcceleration()
else
Angles = {0, 0} SensorData.Gimbal.Angles = Angles
AngularRates = {0, 0, 0} SensorData.Gimbal.AngularRates = AngularRates
LinearAcceleration = {0, 0, 0} SensorData.Gimbal.LinearAcceleration = LinearAcceleration
end end
end end
@@ -668,17 +694,19 @@ function displayInstrumentPanel(monitor, sensorData)
m.setCursorPos(1, 2) m.setCursorPos(1, 2)
m.write("----------------------") m.write("----------------------")
local next = next
if next(sensorData) ~= nil then
if sensorData then if sensorData then
m.setCursorPos(1, 3) m.setCursorPos(1, 3)
m.write("Pitch: " .. string.format("%.2f", sensorData.gimbal.pitch or 0)) m.write("Pitch: " .. string.format("%.2f", SensorData.Gimbal.Angles.xAngle or 0))
m.setCursorPos(1, 4) m.setCursorPos(1, 4)
m.write("Roll: " .. string.format("%.2f", sensorData.gimbal.roll or 0)) m.write("Roll: " .. string.format("%.2f", SensorData.Gimbal.Angles.zAngle or 0))
m.setCursorPos(1, 5) m.setCursorPos(1, 5)
m.write("Yaw: " .. string.format("%.2f", sensorData.navTable.heading or 0)) m.write("Yaw: " .. string.format("%.2f", SensorData.NavTable.Heading or 0))
m.setCursorPos(1, 6) m.setCursorPos(1, 6)
m.write("Velocity: " .. string.format("%.2f", sensorData.velocity or 0)) m.write("Velocity: " .. string.format("%.2f", sensorData.velocity or 0))
m.setCursorPos(1, 7) m.setCursorPos(1, 7)
m.write("Altitude: " .. string.format("%.2f", sensorData.altitude or 0)) m.write("Altitude: " .. string.format("%.2f", SensorData.Altitude.Altitude or 0))
else else
m.setCursorPos(1, 3) m.setCursorPos(1, 3)
m.write("Pitch: 0.00") m.write("Pitch: 0.00")
@@ -698,6 +726,9 @@ function displayInstrumentPanel(monitor, sensorData)
m.write("Autopilot: " .. autopilotStatus) m.write("Autopilot: " .. autopilotStatus)
end end
end
function displayAutopilotControls(monitor, sensorData) function displayAutopilotControls(monitor, sensorData)
if not monitor or not monitor.peripheral then return end if not monitor or not monitor.peripheral then return end
@@ -763,15 +794,16 @@ function Main()
Init() Init()
local sentinel = true local sentinel = true
print("Mainloop starting. Press 'q' to stop the loop and save configuration changes.")
while sentinel do while sentinel do
-- Update monitor displays -- Update monitor displays
if Config.Monitors.InstrumentPanelMonitor then if Config.Monitors.InstrumentPanelMonitor then
displayInstrumentPanel(Config.Monitors.InstrumentPanelMonitor) displayInstrumentPanel(Config.Monitors.InstrumentPanelMonitor, SensorData)
end end
if Config.Monitors.AutopilotControlMonitor then if Config.Monitors.AutopilotControlMonitor then
displayAutopilotControls(Config.Monitors.AutopilotControlMonitor) displayAutopilotControls(Config.Monitors.AutopilotControlMonitor, SensorData)
end end
local unindexedThrusters = checkIfThrusterIsIndexed() local unindexedThrusters = checkIfThrusterIsIndexed()