From f032d0d9fcc5ade4bf79bcd35fc0c930584e5118 Mon Sep 17 00:00:00 2001
From: Daniel Agar <daniel@agar.ca>
Date: Mon, 29 Apr 2019 11:50:36 -0400
Subject: [PATCH] SYS_MC_EST_GROUP mark LPE unsupported and update airframes
 (#11925)

---
 .../init.d/airframes/1002_standard_vtol.hil   |  1 -
 ROMFS/px4fmu_common/init.d/rc.fw_apps         |  8 -----
 ROMFS/px4fmu_common/init.d/rc.mc_apps         | 25 +++++-----------
 ROMFS/px4fmu_common/init.d/rc.vtol_apps       | 29 +------------------
 posix-configs/bbblue/px4.config               |  3 --
 posix-configs/bbblue/px4_fw.config            |  3 --
 posix-configs/bebop/px4.config                |  2 --
 posix-configs/eagle/200qx/px4.config          |  1 -
 posix-configs/eagle/210qc/px4.config          |  1 -
 posix-configs/eagle/flight/px4.config         |  1 -
 posix-configs/eagle/hil/px4.config            |  1 -
 posix-configs/ocpoc/px4.config                |  1 -
 posix-configs/rpi/px4.config                  |  1 -
 posix-configs/rpi/px4_fw.config               |  1 -
 posix-configs/rpi/px4_hil.config              |  1 -
 src/lib/systemlib/system_params.c             |  4 +--
 src/modules/commander/PreflightCheck.cpp      | 11 +++++--
 17 files changed, 20 insertions(+), 74 deletions(-)

diff --git a/ROMFS/px4fmu_common/init.d/airframes/1002_standard_vtol.hil b/ROMFS/px4fmu_common/init.d/airframes/1002_standard_vtol.hil
index 6d9ea9ca26..745f0519f9 100644
--- a/ROMFS/px4fmu_common/init.d/airframes/1002_standard_vtol.hil
+++ b/ROMFS/px4fmu_common/init.d/airframes/1002_standard_vtol.hil
@@ -56,7 +56,6 @@ then
 	param set RTL_RETURN_ALT 30
 
 	param set SDLOG_DIRS_MAX 7
-	param set SYS_MC_EST_GROUP 2
 	param set SYS_RESTART_TYPE 2
 
 	param set VT_F_TRANS_THR 0.75
diff --git a/ROMFS/px4fmu_common/init.d/rc.fw_apps b/ROMFS/px4fmu_common/init.d/rc.fw_apps
index a556cf332a..bcbf1fb0a5 100644
--- a/ROMFS/px4fmu_common/init.d/rc.fw_apps
+++ b/ROMFS/px4fmu_common/init.d/rc.fw_apps
@@ -5,14 +5,6 @@
 # NOTE: Script variables are declared/initialized/unset in the rcS script.
 #
 
-# LPE
-if param compare SYS_MC_EST_GROUP 1
-then
-	echo "ERROR [init] Estimator LPE not supported on fixed wing. Using EKF2"
-	param set SYS_MC_EST_GROUP 2
-	param save
-fi
-
 #
 # Start the attitude and position estimator.
 #
diff --git a/ROMFS/px4fmu_common/init.d/rc.mc_apps b/ROMFS/px4fmu_common/init.d/rc.mc_apps
index 75a6d25c5c..65329398ef 100644
--- a/ROMFS/px4fmu_common/init.d/rc.mc_apps
+++ b/ROMFS/px4fmu_common/init.d/rc.mc_apps
@@ -9,16 +9,6 @@
 #                       Begin Estimator Group Selection                       #
 ###############################################################################
 
-#
-# INAV (deprecated).
-#
-if param compare SYS_MC_EST_GROUP 0
-then
-	echo "ERROR [init] Estimator INAV deprecated. Using EKF2"
-	param set SYS_MC_EST_GROUP 2
-	param save
-fi
-
 #
 # LPE
 #
@@ -30,21 +20,22 @@ then
 	#
 	if attitude_estimator_q start
 	then
+		echo "WARN [init] Estimator LPE unsupported, EKF2 recommended."
 		local_position_estimator start
 	else
 		echo "ERROR [init] Estimator LPE not available. Using EKF2"
 		param set SYS_MC_EST_GROUP 2
 		param save
+		reboot
 	fi
-fi
-
-#
-# EKF2
-#
-if param compare SYS_MC_EST_GROUP 2
-then
+else
+	#
+	# EKF2
+	#
+	param set SYS_MC_EST_GROUP 2
 	ekf2 start
 fi
+
 ###############################################################################
 #                        End Estimator Group Selection                        #
 ###############################################################################
diff --git a/ROMFS/px4fmu_common/init.d/rc.vtol_apps b/ROMFS/px4fmu_common/init.d/rc.vtol_apps
index 527c4ce23b..10ad0cdb7c 100644
--- a/ROMFS/px4fmu_common/init.d/rc.vtol_apps
+++ b/ROMFS/px4fmu_common/init.d/rc.vtol_apps
@@ -9,34 +9,7 @@
 #                       Begin Estimator group selection                       #
 ###############################################################################
 
-# INAV (deprecated)
-if param compare SYS_MC_EST_GROUP 0
-then
-	echo "ERROR [init] Estimator INAV deprecated. Using EKF2"
-	param set SYS_MC_EST_GROUP 2
-	param save
-fi
-
-# LPE
-if param compare SYS_MC_EST_GROUP 1
-then
-	# Try to start LPE. If it fails, start EKF2 as a default
-	# Unfortunately we do not build it on px4_fmu-v2 due to a limited flash.
-	if attitude_estimator_q start
-	then
-		local_position_estimator start
-	else
-		echo "ERROR [init] Estimator LPE not available. Using EKF2"
-		param set SYS_MC_EST_GROUP 2
-		param save
-	fi
-fi
-
-# EKF
-if param compare SYS_MC_EST_GROUP 2
-then
-	ekf2 start
-fi
+ekf2 start
 
 ###############################################################################
 #                        End Estimator group selection                        #
diff --git a/posix-configs/bbblue/px4.config b/posix-configs/bbblue/px4.config
index 8b4e4b63c0..e40b2dcea3 100644
--- a/posix-configs/bbblue/px4.config
+++ b/posix-configs/bbblue/px4.config
@@ -33,9 +33,6 @@ param set MAV_BROADCAST 1
 # MAV_TYPE: 1 Fixed wing aircraft, 2 Quadrotor
 param set MAV_TYPE 2
 
-# Set multicopter estimator group, 1 local_position_estimator, attitude_estimator_q, 2 ekf2
-param set SYS_MC_EST_GROUP 2
-
 # Three possible main power battery sources for BBBlue:
 # 1. onboard 2S LiPo battery connector, which is connect to ADC channel 6
 # 2. onboard 9-18V DC Jack, which is connect to ADC channel 5. This is the board default.
diff --git a/posix-configs/bbblue/px4_fw.config b/posix-configs/bbblue/px4_fw.config
index ec0c6379fc..414749688a 100644
--- a/posix-configs/bbblue/px4_fw.config
+++ b/posix-configs/bbblue/px4_fw.config
@@ -33,9 +33,6 @@ param set MAV_BROADCAST 1
 # MAV_TYPE: 1 Fixed wing aircraft, 2 Quadrotor
 param set MAV_TYPE 2
 
-# Set multicopter estimator group, 1 local_position_estimator, attitude_estimator_q, 2 ekf2
-param set SYS_MC_EST_GROUP 2
-
 # Three possible main power battery sources for BBBlue:
 # 1. onboard 2S LiPo battery connector, which is connect to ADC channel 6
 # 2. onboard 9-18V DC Jack, which is connect to ADC channel 5. This is the board default.
diff --git a/posix-configs/bebop/px4.config b/posix-configs/bebop/px4.config
index f470cf4dd4..5287daad56 100644
--- a/posix-configs/bebop/px4.config
+++ b/posix-configs/bebop/px4.config
@@ -36,8 +36,6 @@ param set MC_PITCHRATE_I 0.8
 param set MC_PITCHRATE_D 0.0
 param set MC_PR_INT_LIM 0.5
 
-param set SYS_MC_EST_GROUP 2
-
 df_ms5607_wrapper start
 df_mpu6050_wrapper start -R 8
 df_ak8963_wrapper start -R 32
diff --git a/posix-configs/eagle/200qx/px4.config b/posix-configs/eagle/200qx/px4.config
index 53a29d4eef..48286eec03 100644
--- a/posix-configs/eagle/200qx/px4.config
+++ b/posix-configs/eagle/200qx/px4.config
@@ -23,7 +23,6 @@ param set UART_ESC_MOTOR1 4
 param set UART_ESC_MOTOR2 2
 param set UART_ESC_MOTOR3 1
 param set UART_ESC_MOTOR4 3
-param set SYS_MC_EST_GROUP 2
 sleep 1
 df_mpu9250_wrapper start
 df_bmp280_wrapper start
diff --git a/posix-configs/eagle/210qc/px4.config b/posix-configs/eagle/210qc/px4.config
index 53a29d4eef..48286eec03 100644
--- a/posix-configs/eagle/210qc/px4.config
+++ b/posix-configs/eagle/210qc/px4.config
@@ -23,7 +23,6 @@ param set UART_ESC_MOTOR1 4
 param set UART_ESC_MOTOR2 2
 param set UART_ESC_MOTOR3 1
 param set UART_ESC_MOTOR4 3
-param set SYS_MC_EST_GROUP 2
 sleep 1
 df_mpu9250_wrapper start
 df_bmp280_wrapper start
diff --git a/posix-configs/eagle/flight/px4.config b/posix-configs/eagle/flight/px4.config
index 99578ac989..ca7624b986 100644
--- a/posix-configs/eagle/flight/px4.config
+++ b/posix-configs/eagle/flight/px4.config
@@ -1,7 +1,6 @@
 uorb start
 qshell start
 param set SYS_AUTOSTART 4001
-param set SYS_MC_EST_GROUP 2
 sleep 1
 gps start -d /dev/tty-4
 param set MAV_TYPE 2
diff --git a/posix-configs/eagle/hil/px4.config b/posix-configs/eagle/hil/px4.config
index 1dcb1fb9e0..3adb2664b9 100644
--- a/posix-configs/eagle/hil/px4.config
+++ b/posix-configs/eagle/hil/px4.config
@@ -37,7 +37,6 @@ param set MC_ROLLRATE_P 0.03
 param set ATT_W_ACC 0.0002
 param set ATT_W_MAG 0.002
 param set ATT_W_GYRO_BIAS 0.05
-param set SYS_MC_EST_GROUP 0
 sleep 1
 commander start -hil
 sensors start
diff --git a/posix-configs/ocpoc/px4.config b/posix-configs/ocpoc/px4.config
index 7d194021ea..c843c468a7 100644
--- a/posix-configs/ocpoc/px4.config
+++ b/posix-configs/ocpoc/px4.config
@@ -14,7 +14,6 @@ param set SYS_AUTOSTART 4001
 param set MAV_BROADCAST 1
 param set MAV_TYPE 2
 param set MAV_SYS_ID 1
-param set SYS_MC_EST_GROUP 2
 
 df_mpu9250_wrapper start_without_mag -R 10
 df_hmc5883_wrapper start -D /dev/i2c-4
diff --git a/posix-configs/rpi/px4.config b/posix-configs/rpi/px4.config
index a4f4a4c998..d189b292f0 100644
--- a/posix-configs/rpi/px4.config
+++ b/posix-configs/rpi/px4.config
@@ -12,7 +12,6 @@ fi
 param set SYS_AUTOSTART 4001
 param set MAV_BROADCAST 1
 param set MAV_TYPE 2
-param set SYS_MC_EST_GROUP 2
 param set BAT_CNT_V_VOLT 0.001
 param set BAT_V_DIV 10.9176300578
 param set BAT_CNT_V_CURR 0.001
diff --git a/posix-configs/rpi/px4_fw.config b/posix-configs/rpi/px4_fw.config
index 6a32cdab74..7e89775d2a 100644
--- a/posix-configs/rpi/px4_fw.config
+++ b/posix-configs/rpi/px4_fw.config
@@ -10,7 +10,6 @@ param load
 param set MAV_BROADCAST 1
 param set SYS_AUTOSTART 2100
 param set MAV_TYPE 1
-param set SYS_MC_EST_GROUP 2
 
 param set BAT_CNT_V_VOLT 0.001
 param set BAT_V_DIV 10.9176300578
diff --git a/posix-configs/rpi/px4_hil.config b/posix-configs/rpi/px4_hil.config
index 39269639bd..1a0a21e70d 100644
--- a/posix-configs/rpi/px4_hil.config
+++ b/posix-configs/rpi/px4_hil.config
@@ -12,7 +12,6 @@ param load
 param set SYS_AUTOSTART 1001
 param set MAV_BROADCAST 1
 param set MAV_TYPE 2
-param set SYS_MC_EST_GROUP 0
 dataman start
 sensors start -hil
 commander start -hil
diff --git a/src/lib/systemlib/system_params.c b/src/lib/systemlib/system_params.c
index 02da38e1ec..c2fa371eaa 100644
--- a/src/lib/systemlib/system_params.c
+++ b/src/lib/systemlib/system_params.c
@@ -100,8 +100,8 @@ PARAM_DEFINE_INT32(SYS_RESTART_TYPE, 2);
  *
  * Set the group of estimators used for multicopters and VTOLs
  *
- * @value 1 local_position_estimator, attitude_estimator_q
- * @value 2 ekf2
+ * @value 1 local_position_estimator, attitude_estimator_q (unsupported)
+ * @value 2 ekf2 (recommended)
  *
  * @min 1
  * @max 2
diff --git a/src/modules/commander/PreflightCheck.cpp b/src/modules/commander/PreflightCheck.cpp
index 29ca7225bf..9952e8ec9b 100644
--- a/src/modules/commander/PreflightCheck.cpp
+++ b/src/modules/commander/PreflightCheck.cpp
@@ -925,8 +925,15 @@ bool preflightCheck(orb_advert_t *mavlink_log_pub, vehicle_status_s &status,
 
 	/* ---- Navigation EKF ---- */
 	// only check EKF2 data if EKF2 is selected as the estimator and GNSS checking is enabled
-	int32_t estimator_type;
-	param_get(param_find("SYS_MC_EST_GROUP"), &estimator_type);
+	int32_t estimator_type = -1;
+
+	if (status.is_rotary_wing && !status.is_vtol) {
+		param_get(param_find("SYS_MC_EST_GROUP"), &estimator_type);
+
+	} else {
+		// EKF2 is currently the only supported option for FW & VTOL
+		estimator_type = 2;
+	}
 
 	if (estimator_type == 2) {
 		// don't report ekf failures for the first 10 seconds to allow time for the filter to start
-- 
GitLab