begin properly implementing monitor display logic
This commit is contained in:
122
main.lua
122
main.lua
@@ -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,11 +457,21 @@ function PollVelocity()
|
|||||||
|
|
||||||
-- Velocity Sensors
|
-- Velocity Sensors
|
||||||
VelocityVectors = {}
|
VelocityVectors = {}
|
||||||
for vsindex, velsensor in pairs(velSensors) do
|
local next = next
|
||||||
local vsAxis = velsensor.getAxis()
|
if next(velSensors) == nil then
|
||||||
local vsVelocity = velsensor.getVelocity()
|
|
||||||
VelocityVectors[vsAxis] = vsVelocity
|
SensorData.Velocity = {}
|
||||||
|
|
||||||
|
for vsindex, velsensor in pairs(velSensors) do
|
||||||
|
|
||||||
|
local vsAxis = velsensor.getAxis()
|
||||||
|
local vsVelocity = velsensor.getVelocity()
|
||||||
|
VelocityVectors[vsAxis] = vsVelocity
|
||||||
|
|
||||||
|
SensorData.Velocity.Raw = VelocityVectors
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function PollAltitude()
|
function PollAltitude()
|
||||||
@@ -467,19 +479,32 @@ function PollAltitude()
|
|||||||
|
|
||||||
-- 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
|
||||||
|
|
||||||
function PollNavTable()
|
function PollNavTable()
|
||||||
local navTable = peripheral.find("navigation_table") -- enforce one nav table
|
local navTable = peripheral.find("navigation_table") -- enforce one nav table
|
||||||
|
|
||||||
-- 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
|
||||||
|
|
||||||
@@ -667,35 +693,40 @@ function displayInstrumentPanel(monitor, sensorData)
|
|||||||
m.write("Caero Attitude Control")
|
m.write("Caero Attitude Control")
|
||||||
m.setCursorPos(1, 2)
|
m.setCursorPos(1, 2)
|
||||||
m.write("----------------------")
|
m.write("----------------------")
|
||||||
|
|
||||||
if sensorData then
|
local next = next
|
||||||
m.setCursorPos(1, 3)
|
if next(sensorData) ~= nil then
|
||||||
m.write("Pitch: " .. string.format("%.2f", sensorData.gimbal.pitch or 0))
|
if sensorData then
|
||||||
m.setCursorPos(1, 4)
|
m.setCursorPos(1, 3)
|
||||||
m.write("Roll: " .. string.format("%.2f", sensorData.gimbal.roll or 0))
|
m.write("Pitch: " .. string.format("%.2f", SensorData.Gimbal.Angles.xAngle or 0))
|
||||||
m.setCursorPos(1, 5)
|
m.setCursorPos(1, 4)
|
||||||
m.write("Yaw: " .. string.format("%.2f", sensorData.navTable.heading or 0))
|
m.write("Roll: " .. string.format("%.2f", SensorData.Gimbal.Angles.zAngle or 0))
|
||||||
m.setCursorPos(1, 6)
|
m.setCursorPos(1, 5)
|
||||||
m.write("Velocity: " .. string.format("%.2f", sensorData.velocity or 0))
|
m.write("Yaw: " .. string.format("%.2f", SensorData.NavTable.Heading or 0))
|
||||||
m.setCursorPos(1, 7)
|
m.setCursorPos(1, 6)
|
||||||
m.write("Altitude: " .. string.format("%.2f", sensorData.altitude or 0))
|
m.write("Velocity: " .. string.format("%.2f", sensorData.velocity or 0))
|
||||||
else
|
m.setCursorPos(1, 7)
|
||||||
m.setCursorPos(1, 3)
|
m.write("Altitude: " .. string.format("%.2f", SensorData.Altitude.Altitude or 0))
|
||||||
m.write("Pitch: 0.00")
|
else
|
||||||
m.setCursorPos(1, 4)
|
m.setCursorPos(1, 3)
|
||||||
m.write("Roll: 0.00")
|
m.write("Pitch: 0.00")
|
||||||
m.setCursorPos(1, 5)
|
m.setCursorPos(1, 4)
|
||||||
m.write("Yaw: 0.00")
|
m.write("Roll: 0.00")
|
||||||
m.setCursorPos(1, 6)
|
m.setCursorPos(1, 5)
|
||||||
m.write("Velocity: 0.00")
|
m.write("Yaw: 0.00")
|
||||||
m.setCursorPos(1, 7)
|
m.setCursorPos(1, 6)
|
||||||
m.write("Altitude: 0.00")
|
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
|
end
|
||||||
|
|
||||||
-- Display autopilot status
|
|
||||||
local autopilotStatus = Config.Autopilot.AutopilotEngaged and "ON" or "OFF"
|
|
||||||
m.setCursorPos(1, 9)
|
|
||||||
m.write("Autopilot: " .. autopilotStatus)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function displayAutopilotControls(monitor, sensorData)
|
function displayAutopilotControls(monitor, sensorData)
|
||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user