From 08ddae8882bb573541c7c544823385915fc53544 Mon Sep 17 00:00:00 2001 From: priseborough Date: Wed, 21 Jun 2017 10:50:30 +1000 Subject: [PATCH] AP_NavEKF3: Clean up aiding mode logic using switch statements --- libraries/AP_NavEKF3/AP_NavEKF3_Control.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libraries/AP_NavEKF3/AP_NavEKF3_Control.cpp b/libraries/AP_NavEKF3/AP_NavEKF3_Control.cpp index 50247f94f4..774b059e52 100644 --- a/libraries/AP_NavEKF3/AP_NavEKF3_Control.cpp +++ b/libraries/AP_NavEKF3/AP_NavEKF3_Control.cpp @@ -283,7 +283,8 @@ void NavEKF3_core::setAidingMode() // check to see if we are starting or stopping aiding and set states and modes as required if (PV_AidingMode != PV_AidingModePrev) { // set various usage modes based on the condition when we start aiding. These are then held until aiding is stopped. - if (PV_AidingMode == AID_NONE) { + switch (PV_AidingMode) { + case AID_NONE: // We have ceased aiding GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_WARNING, "EKF3 IMU%u stopped aiding",(unsigned)imu_index); // When not aiding, estimate orientation & height fusing synthetic constant position and zero velocity measurement to constrain tilt errors @@ -303,7 +304,9 @@ void NavEKF3_core::setAidingMode() // reset relative aiding sensor fusion activity status flowFusionActive = false; bodyVelFusionActive = false; - } else if (PV_AidingMode == AID_RELATIVE) { + break; + + case AID_RELATIVE: // We are doing relative position navigation where velocity errors are constrained, but position drift will occur GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_INFO, "EKF3 IMU%u started relative aiding",(unsigned)imu_index); if (readyToUseOptFlow()) { @@ -317,7 +320,9 @@ void NavEKF3_core::setAidingMode() } posTimeout = true; velTimeout = true; - } else if (PV_AidingMode == AID_ABSOLUTE) { + break; + + case AID_ABSOLUTE: if (readyToUseGPS()) { // We are commencing aiding using GPS - this is the preferred method posResetSource = GPS; @@ -340,6 +345,10 @@ void NavEKF3_core::setAidingMode() lastPosPassTime_ms = imuSampleTime_ms; lastVelPassTime_ms = imuSampleTime_ms; lastRngBcnPassTime_ms = imuSampleTime_ms; + break; + + default: + break; } // Always reset the position and velocity when changing mode