wind_estimator: move from ecl and consolidate airspeed selector

This commit is contained in:
Daniel Agar
2021-07-14 17:15:47 -04:00
parent fedf8f0266
commit 6f6d3f98a6
11 changed files with 28 additions and 66 deletions
+1 -1
View File
@@ -35,7 +35,6 @@ px4_add_git_submodule(TARGET git_matrix PATH "matrix")
px4_add_git_submodule(TARGET git_monocypher PATH "crypto/monocypher") px4_add_git_submodule(TARGET git_monocypher PATH "crypto/monocypher")
add_subdirectory(airspeed) add_subdirectory(airspeed)
add_subdirectory(airspeed_validator)
add_subdirectory(avoidance) add_subdirectory(avoidance)
add_subdirectory(battery) add_subdirectory(battery)
add_subdirectory(bezier) add_subdirectory(bezier)
@@ -70,4 +69,5 @@ add_subdirectory(terrain_estimation)
add_subdirectory(tunes) add_subdirectory(tunes)
add_subdirectory(version) add_subdirectory(version)
add_subdirectory(weather_vane) add_subdirectory(weather_vane)
add_subdirectory(wind_estimator)
add_subdirectory(world_magnetic_model) add_subdirectory(world_magnetic_model)
-1
View File
@@ -178,7 +178,6 @@ if(ECL_ASAN)
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address) set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address)
endif() endif()
add_subdirectory(airdata)
add_subdirectory(EKF) add_subdirectory(EKF)
add_subdirectory(geo) add_subdirectory(geo)
-39
View File
@@ -1,39 +0,0 @@
############################################################################
#
# Copyright (c) 2018 ECL Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name ECL nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
add_library(ecl_airdata
WindEstimator.cpp
)
add_dependencies(ecl_airdata prebuild_targets)
target_compile_definitions(ecl_airdata PRIVATE -DMODULE_NAME="ecl/airdata")
target_include_directories(ecl_airdata PUBLIC ${ECL_SOURCE_DIR})
@@ -1,6 +1,6 @@
############################################################################ ############################################################################
# #
# Copyright (c) 2019 PX4 Development Team. All rights reserved. # Copyright (c) 2018-2021 PX4 Development Team. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions # modification, are permitted provided that the following conditions
@@ -31,11 +31,8 @@
# #
############################################################################ ############################################################################
px4_add_library(AirspeedValidator AirspeedValidator.cpp) add_library(wind_estimator
WindEstimator.cpp
target_include_directories(AirspeedValidator WindEstimator.hpp
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
) )
add_dependencies(wind_estimator prebuild_targets)
target_link_libraries(AirspeedValidator PUBLIC ecl_airdata)
@@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
* *
* Copyright (c) 2018 PX4 Development Team. All rights reserved. * Copyright (c) 2018-2021 PX4 Development Team. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -163,7 +163,8 @@ WindEstimator::fuse_airspeed(uint64_t time_now, const float true_airspeed, const
const float k_tas = _state(INDEX_TAS_SCALE); const float k_tas = _state(INDEX_TAS_SCALE);
// compute kalman gain K // compute kalman gain K
const float HH0 = sqrtf(v_d * v_d + (v_e - _state(INDEX_W_E)) * (v_e - _state(INDEX_W_E)) + (v_n - _state(INDEX_W_N)) * (v_n - _state(INDEX_W_N))); const float HH0 = sqrtf(v_d * v_d + (v_e - _state(INDEX_W_E)) * (v_e - _state(INDEX_W_E)) + (v_n - _state(
INDEX_W_N)) * (v_n - _state(INDEX_W_N)));
const float HH1 = k_tas / HH0; const float HH1 = k_tas / HH0;
matrix::Matrix<float, 1, 3> H_tas; matrix::Matrix<float, 1, 3> H_tas;
@@ -177,7 +178,8 @@ WindEstimator::fuse_airspeed(uint64_t time_now, const float true_airspeed, const
K /= S(0, 0); K /= S(0, 0);
// compute innovation // compute innovation
const float airspeed_pred = k_tas * sqrtf((v_n - _state(INDEX_W_N)) * (v_n - _state(INDEX_W_N)) + (v_e - _state(INDEX_W_E)) * const float airspeed_pred = k_tas * sqrtf((v_n - _state(INDEX_W_N)) * (v_n - _state(INDEX_W_N)) + (v_e - _state(
INDEX_W_E)) *
(v_e - _state(INDEX_W_E)) + v_d * v_d); (v_e - _state(INDEX_W_E)) + v_d * v_d);
_tas_innov = true_airspeed - airspeed_pred; _tas_innov = true_airspeed - airspeed_pred;
@@ -188,7 +190,8 @@ WindEstimator::fuse_airspeed(uint64_t time_now, const float true_airspeed, const
bool reinit_filter = false; bool reinit_filter = false;
bool meas_is_rejected = false; bool meas_is_rejected = false;
meas_is_rejected = check_if_meas_is_rejected(time_now, _tas_innov, _tas_innov_var, _tas_gate, _time_rejected_tas, reinit_filter); meas_is_rejected = check_if_meas_is_rejected(time_now, _tas_innov, _tas_innov_var, _tas_gate, _time_rejected_tas,
reinit_filter);
reinit_filter |= _tas_innov_var < 0.0f; reinit_filter |= _tas_innov_var < 0.0f;
@@ -325,7 +328,7 @@ WindEstimator::run_sanity_checks()
} }
} }
if (!ISFINITE(_state(INDEX_W_N)) || !ISFINITE(_state(INDEX_W_E)) || !ISFINITE(_state(INDEX_TAS_SCALE))) { if (!PX4_ISFINITE(_state(INDEX_W_N)) || !PX4_ISFINITE(_state(INDEX_W_E)) || !PX4_ISFINITE(_state(INDEX_TAS_SCALE))) {
_initialised = false; _initialised = false;
return; return;
} }
@@ -335,6 +338,7 @@ WindEstimator::run_sanity_checks()
// to be computed once for a perticular installation. // to be computed once for a perticular installation.
if (_enforced_airspeed_scale < 0) { if (_enforced_airspeed_scale < 0) {
_state(INDEX_TAS_SCALE) = math::max(0.0f, _state(INDEX_TAS_SCALE)); _state(INDEX_TAS_SCALE) = math::max(0.0f, _state(INDEX_TAS_SCALE));
} else { } else {
_state(INDEX_TAS_SCALE) = _enforced_airspeed_scale; _state(INDEX_TAS_SCALE) = _enforced_airspeed_scale;
} }
@@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
* *
* Copyright (c) 2018 PX4 Development Team. All rights reserved. * Copyright (c) 2018-2021 PX4 Development Team. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -38,7 +38,6 @@
#pragma once #pragma once
#include <ecl.h>
#include <mathlib/mathlib.h> #include <mathlib/mathlib.h>
#include <matrix/math.hpp> #include <matrix/math.hpp>
@@ -39,7 +39,7 @@
#pragma once #pragma once
#include <airspeed/airspeed.h> #include <airspeed/airspeed.h>
#include <ecl/airdata/WindEstimator.hpp> #include <lib/wind_estimator/WindEstimator.hpp>
#include <uORB/topics/airspeed_wind.h> #include <uORB/topics/airspeed_wind.h>
+3 -2
View File
@@ -35,7 +35,8 @@ px4_add_module(
MAIN airspeed_selector MAIN airspeed_selector
SRCS SRCS
airspeed_selector_main.cpp airspeed_selector_main.cpp
AirspeedValidator.cpp
AirspeedValidator.hpp
DEPENDS DEPENDS
ecl_airdata wind_estimator
AirspeedValidator
) )
@@ -31,8 +31,10 @@
* *
****************************************************************************/ ****************************************************************************/
#include "AirspeedValidator.hpp"
#include <drivers/drv_hrt.h> #include <drivers/drv_hrt.h>
#include <ecl/airdata/WindEstimator.hpp> #include <lib/wind_estimator/WindEstimator.hpp>
#include <matrix/math.hpp> #include <matrix/math.hpp>
#include <parameters/param.h> #include <parameters/param.h>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
@@ -40,8 +42,7 @@
#include <px4_platform_common/module_params.h> #include <px4_platform_common/module_params.h>
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
#include <lib/airspeed/airspeed.h> #include <lib/airspeed/airspeed.h>
#include <AirspeedValidator.hpp> #include <lib/systemlib/mavlink_log.h>
#include <systemlib/mavlink_log.h>
#include <uORB/Subscription.hpp> #include <uORB/Subscription.hpp>
#include <uORB/SubscriptionMultiArray.hpp> #include <uORB/SubscriptionMultiArray.hpp>