diff --git a/main.lua b/main.lua index 06552e1..f40d7ba 100644 --- a/main.lua +++ b/main.lua @@ -710,6 +710,14 @@ function UpdateGlobalThrust() -- depending on the desired thrust vectors, some counteractive desired thrust vectors will be ignored -- lateral thrust + -- verify that SensorData.Velocity.Raw is not nil + if SensorData.Velocity.Raw == nil then + if Config.Debug then + print("DEBUG: SensorData.Velocity.Raw is nil, skipping UpdateGlobalThrust") + end + return + end + local desiredLateralThrustVectors = {} for f, v in pairs(SensorData.Velocity.Raw) do @@ -739,6 +747,14 @@ function UpdateGlobalThrust() end -- angular thrust + -- verify that SensorData.Gimbal.AngularRates is not nil + if SensorData.Gimbal.AngularRates == nil then + if Config.Debug then + print("DEBUG: SensorData.Gimbal.AngularRates is nil, skipping UpdateGlobalThrust") + end + return + end + local desiredAngularThrustVectors = {} for f, v in pairs(SensorData.Gimbal.AngularRates) do @@ -933,6 +949,11 @@ function Main() print("Mainloop starting. Press 'q' to stop the loop and save configuration changes.") while sentinel do + PollSensors() + + UpdateStabilization() + UpdateGlobalThrust() + -- Update monitor displays if Config.Monitors.InstrumentPanelMonitor then displayInstrumentPanel(Config.Monitors.InstrumentPanelMonitor, SensorData) @@ -947,10 +968,6 @@ function Main() partiallyUpdateThrusters(unindexedThrusters) end - PollSensors() - UpdateGlobalThrust() - UpdateStabilization() - local function getTerminateEvent() local event, key, is_held = os.pullEventRaw("key") if keys.getName(key) == "q" then