refactor(vtol_att_control): move the front transition check into its own class

The fit and the decision do not depend on the VTOL type, only the forward
thrust share does. As a class without uORB, another VTOL type can feed it
its own share, for example a tiltrotor from its tilt, and the fit is
tested on synthetic timestamps instead of in real time. Like
FirstOrderHoldAltitude in fw_mode_manager, it lives in the module that
uses it.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: jonas <jonspero@me.com>
This commit is contained in:
jonas committed 2026-11-20 11:29:40 +01:00
1 parent 0a0d12fb20
commit a0ddfa9254
7 files changed
+432 -151

No files matched your search

@@ -39,6 +39,8 @@ px4_add_module(
vtol_type.cpp
tailsitter.cpp
standard.cpp
FrontTransitionThrustCheck.cpp
FrontTransitionThrustCheck.hpp
MODULE_CONFIG
standard_params.yaml
tiltrotor_params.yaml
@@ -47,4 +49,5 @@ px4_add_module(
hysteresis
)
px4_add_unit_gtest(SRC FrontTransitionThrustCheckTest.cpp EXTRA_SRCS FrontTransitionThrustCheck.cpp LINKLIBS mathlib)
px4_add_functional_gtest(SRC test_vtol_quadchute.cpp LINKLIBS modules__vtol_att_control)
@@ -0,0 +1,81 @@
/****************************************************************************
*
* Copyright (c) 2026 PX4 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 PX4 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.
*
****************************************************************************/
#include "FrontTransitionThrustCheck.hpp"
#include <cmath>
#include <mathlib/mathlib.h>
using namespace time_literals;
static constexpr float kMaxStartShare = 0.5f; // of the transition thrust
static constexpr hrt_abstime kMaxSampleGap = 100_ms;
static constexpr float kCheckTime = 1.f; // [s] at the transition thrust
void FrontTransitionThrustCheck::start(float start_share)
{
_last_sample = 0;
_start_share = start_share;
_weighted_speed_gain = 0.f;
_weighted_time = 0.f;
_checking = start_share < kMaxStartShare;
}
bool FrontTransitionThrustCheck::update(hrt_abstime timestamp_sample, float thrust_share, float forward_acceleration,
float min_acceleration)
{
// integrate only between consecutive samples, not over gaps
const hrt_abstime last_sample = _last_sample;
_last_sample = timestamp_sample;
const bool consecutive = (last_sample != 0) && (timestamp_sample > last_sample)
&& (timestamp_sample - last_sample < kMaxSampleGap);
if (!_checking || !consecutive || !std::isfinite(forward_acceleration)) {
return false;
}
// the acceleration is thrust minus drag, divided by the mass: only the thrust added since the start counts
const float added_share = math::max(thrust_share - _start_share, 0.f);
const float dt = (timestamp_sample - last_sample) * 1e-6f;
_weighted_speed_gain += added_share * forward_acceleration * dt;
_weighted_time += added_share * added_share * dt;
if (_weighted_time < math::sq(1.f - _start_share) * kCheckTime) {
return false;
}
_checking = false;
// fitted acceleration for the whole transition thrust below the minimum
return _weighted_speed_gain < min_acceleration * _weighted_time;
}
@@ -0,0 +1,80 @@
/****************************************************************************
*
* Copyright (c) 2026 PX4 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 PX4 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.
*
****************************************************************************/
/**
* @file FrontTransitionThrustCheck.hpp
*
* Checks at the start of a front transition, where the drag is still low, that the forward thrust accelerates the
* vehicle. Example: with a failed pusher, the forward acceleration stays about zero at the transition throttle.
*/
#pragma once
#include <drivers/drv_hrt.h>
class FrontTransitionThrustCheck
{
public:
/**
* Restart for a new front transition. Not checked if the forward thrust at the start (e.g. pusher assist) is
* half of the transition thrust or more: what is added is too small to tell from gusts.
*
* @param start_share forward thrust at the start, as a share of the transition thrust
*/
void start(float start_share);
/** No check until the next start() */
void skip() { _checking = false; }
bool isChecking() const { return _checking; }
/**
* Fits the forward acceleration to the thrust added since the start (least squares, so each sample counts with
* its thrust) and decides once the samples weigh as much as 1 s at the transition thrust.
*
* @param timestamp_sample [us] samples 100 ms or more apart are not integrated
* @param thrust_share forward thrust as a share of the transition thrust, 1 at the transition throttle
* @param forward_acceleration [m/s^2] accelerometer along the body x axis, a non-finite sample is skipped
* @param min_acceleration [m/s^2] required for the whole transition thrust. Example: 0.8 asks for 0.61 if 24%
* of the transition thrust was already there at the start.
* @return true once, if the fitted acceleration stays below min_acceleration
*/
bool update(hrt_abstime timestamp_sample, float thrust_share, float forward_acceleration, float min_acceleration);
private:
hrt_abstime _last_sample{0};
float _start_share{0.f};
float _weighted_speed_gain{0.f}; ///< [m/s] forward acceleration integrated, weighted by the added thrust
float _weighted_time{0.f}; ///< [s] time integrated, weighted by the added thrust squared
bool _checking{false};
};
@@ -0,0 +1,227 @@
/****************************************************************************
*
* Copyright (c) 2026 PX4 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 PX4 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.
*
****************************************************************************/
/**
* @file FrontTransitionThrustCheckTest.cpp
*
* Front transitions sampled at 200 Hz. The thrust share is 1 at the transition throttle, and grows with the throttle
* squared while the throttle ramps up.
*/
#include <gtest/gtest.h>
#include "FrontTransitionThrustCheck.hpp"
#include <cmath>
#include <functional>
using namespace time_literals;
namespace
{
constexpr hrt_abstime kSampleInterval = 5_ms;
constexpr float kMinAcceleration = 0.8f; // [m/s^2] VT_EF_FT_ACC default
struct Sample {
float thrust_share;
float forward_acceleration; ///< [m/s^2]
};
// Flies a front transition for duration [s], with the sample at each time [s] since its start.
// Returns the time of the failure, or NAN.
float failureTime(FrontTransitionThrustCheck &check, float duration, const std::function<Sample(float)> &sample_at,
float min_acceleration = kMinAcceleration)
{
const hrt_abstime start = 10_s;
for (hrt_abstime elapsed = 0; elapsed < (hrt_abstime)(duration * 1e6f); elapsed += kSampleInterval) {
const float time = elapsed * 1e-6f;
const Sample sample = sample_at(time);
if (check.update(start + elapsed, sample.thrust_share, sample.forward_acceleration, min_acceleration)) {
return time;
}
}
return NAN;
}
// The throttle steps to the transition throttle, as with VT_PSHER_SLEW 0
std::function<Sample(float)> atTransitionThrottle(float forward_acceleration)
{
return [forward_acceleration](float) { return Sample{1.f, forward_acceleration}; };
}
// The throttle ramps up to the transition throttle in ramp_time [s]. A working pusher accelerates with its thrust.
std::function<Sample(float)> throttleRamp(float ramp_time, float acceleration_at_transition_throttle)
{
return [ = ](float time) {
const float throttle = fminf(time / ramp_time, 1.f);
const float thrust_share = throttle * throttle;
const float forward_acceleration = acceleration_at_transition_throttle * thrust_share;
return Sample{thrust_share, forward_acceleration};
};
}
} // namespace
TEST(FrontTransitionThrustCheckTest, NoAccelerationFailsAfterOneSecond)
{
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_NEAR(failureTime(check, 3.f, atTransitionThrottle(0.f)), 1.f, 0.01f);
EXPECT_FALSE(check.isChecking()); // decided once
}
TEST(FrontTransitionThrustCheckTest, AccelerationAboveTheMinimumPasses)
{
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_TRUE(std::isnan(failureTime(check, 3.f, atTransitionThrottle(1.f))));
EXPECT_FALSE(check.isChecking());
}
TEST(FrontTransitionThrustCheckTest, MinimumAccelerationIsAnInput)
{
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_FALSE(std::isnan(failureTime(check, 3.f, atTransitionThrottle(1.5f), 2.f)));
check.start(0.f);
EXPECT_TRUE(std::isnan(failureTime(check, 3.f, atTransitionThrottle(2.5f), 2.f)));
}
TEST(FrontTransitionThrustCheckTest, OnlyTheStartOfTheTransitionIsChecked)
{
// after the decision, the drag decelerates the vehicle
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_TRUE(std::isnan(failureTime(check, 3.f, [](float time) { return Sample{1.f, time < 1.7f ? 3.f : -2.f}; })));
}
TEST(FrontTransitionThrustCheckTest, SlowSpinUpPasses)
{
// a motor that needs 0.25 s to spin up after the throttle step, with twice the minimum acceleration
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_TRUE(std::isnan(failureTime(check, 3.f, [](float time) { return Sample{1.f, time < 0.25f ? 0.f : 1.6f}; })));
}
TEST(FrontTransitionThrustCheckTest, SamplesWithGapsAreNotIntegrated)
{
// samples 150 ms apart are not consecutive: nothing is integrated, so there is no decision
FrontTransitionThrustCheck check;
check.start(0.f);
for (hrt_abstime timestamp = 10_s; timestamp < 13_s; timestamp += 150_ms) {
EXPECT_FALSE(check.update(timestamp, 1.f, 0.f, kMinAcceleration));
}
EXPECT_TRUE(check.isChecking());
}
TEST(FrontTransitionThrustCheckTest, NonFiniteAccelerationIsSkipped)
{
// no acceleration from 0.5 s on: the check decides 1 s later
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_NEAR(failureTime(check, 3.f, [](float time) { return Sample{1.f, time < 0.5f ? NAN : 0.f}; }), 1.5f, 0.01f);
}
TEST(FrontTransitionThrustCheckTest, ThrustAtTheStartLowersTheRequiredAcceleration)
{
// pusher assist at 0.49 of the transition throttle: the transition adds 1 - 0.49^2 = 76% of the transition
// thrust, so it has to accelerate by at least 0.76 * 0.8 = 0.61 m/s^2
const float start_share = 0.49f * 0.49f;
FrontTransitionThrustCheck check;
check.start(start_share);
EXPECT_TRUE(std::isnan(failureTime(check, 3.f, atTransitionThrottle(0.7f))));
check.start(start_share);
EXPECT_NEAR(failureTime(check, 3.f, atTransitionThrottle(0.5f)), 1.f, 0.01f);
}
TEST(FrontTransitionThrustCheckTest, HalfTheTransitionThrustAtTheStartIsNotChecked)
{
FrontTransitionThrustCheck check;
check.start(0.5f);
EXPECT_FALSE(check.isChecking());
EXPECT_TRUE(std::isnan(failureTime(check, 3.f, atTransitionThrottle(-1.f))));
check.start(0.49f);
EXPECT_FALSE(std::isnan(failureTime(check, 3.f, atTransitionThrottle(-1.f))));
}
TEST(FrontTransitionThrustCheckTest, WeakPusherFailsWhileTheThrottleRampsUp)
{
// a 2 s ramp weighs as much as 2 s / 5 = 0.4 s at the transition throttle, so the check decides 0.6 s after it
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_NEAR(failureTime(check, 4.f, throttleRamp(2.f, 0.4f)), 2.6f, 0.01f);
}
TEST(FrontTransitionThrustCheckTest, WorkingPusherPassesWhileTheThrottleRampsUp)
{
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_TRUE(std::isnan(failureTime(check, 4.f, throttleRamp(2.f, 1.6f))));
EXPECT_FALSE(check.isChecking());
}
TEST(FrontTransitionThrustCheckTest, EarlyAccelerationDoesNotHideALaterFailure)
{
// more acceleration at low throttle than the thrust gives, then the pusher stops: samples count with the
// thrust, so the start of the ramp weighs little
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_FALSE(std::isnan(failureTime(check, 4.f, [](float time) {
const float throttle = fminf(time / 2.f, 1.f);
return Sample{throttle * throttle, time < 0.5f ? 3.f : 0.f};
})));
}
TEST(FrontTransitionThrustCheckTest, SkippedTransitionIsNotChecked)
{
FrontTransitionThrustCheck check;
check.start(0.f);
check.skip();
EXPECT_TRUE(std::isnan(failureTime(check, 3.f, atTransitionThrottle(0.f))));
}
TEST(FrontTransitionThrustCheckTest, EachTransitionIsCheckedAgain)
{
FrontTransitionThrustCheck check;
check.start(0.f);
EXPECT_TRUE(std::isnan(failureTime(check, 2.f, atTransitionThrottle(1.f))));
check.start(0.f);
EXPECT_NEAR(failureTime(check, 2.f, atTransitionThrottle(0.f)), 1.f, 0.01f);
}
+17 -41
View File
@@ -137,14 +137,17 @@ void Standard::update_vtol_state()
* unsafe flying state. */
resetTransitionStates();
// Not checked when the front transition interrupts a back transition, as the pusher just flew the vehicle,
// or when pusher assist already gives half of the transition thrust: the rest is too small to tell from gusts.
static constexpr float kMinAddedThrust = 0.5f; // share of the transition thrust
_ft_check = {};
_ft_check.transition_throttle = getFrontTransitionThrottle();
_ft_check.done = (_vtol_mode == vtol_mode::TRANSITION_TO_MC)
|| (math::sq(_pusher_throttle) >= (1.f - kMinAddedThrust) * math::sq(_ft_check.transition_throttle));
_ft_check.start_throttle = _pusher_throttle;
// not checked when the front transition interrupts a back transition, as the pusher just flew the vehicle,
// or without transition throttle
_ft_transition_throttle = getFrontTransitionThrottle();
if (_vtol_mode == vtol_mode::TRANSITION_TO_MC || _ft_transition_throttle < FLT_EPSILON) {
_ft_thrust_check.skip();
} else {
// the pusher thrust grows with the throttle squared, pusher assist may already push
_ft_thrust_check.start(math::sq(_pusher_throttle / _ft_transition_throttle));
}
_vtol_mode = vtol_mode::TRANSITION_TO_FW;
@@ -315,42 +318,15 @@ bool Standard::isPusherFailureDetectedInFrontTransition()
{
vehicle_acceleration_s vehicle_acceleration;
if (!isFtPusherCheckEnabled() || !_vehicle_acceleration_sub.update(&vehicle_acceleration)) {
if (!isFtPusherCheckEnabled() || !_ft_thrust_check.isChecking() || can_transition_on_ground()
|| !_vehicle_acceleration_sub.update(&vehicle_acceleration)) {
return false;
}
// integrate only between consecutive samples, not over gaps
static constexpr hrt_abstime kMaxSampleGap = 100_ms;
const hrt_abstime last_sample = _ft_check.last_sample;
_ft_check.last_sample = vehicle_acceleration.timestamp_sample;
const bool consecutive = (last_sample != 0) && (vehicle_acceleration.timestamp_sample > last_sample)
&& (vehicle_acceleration.timestamp_sample - last_sample < kMaxSampleGap);
if (_ft_check.done || !consecutive || can_transition_on_ground()) {
return false;
}
// thrust grows with the throttle squared: share of the transition thrust added since the transition started
const float start_thrust = math::sq(_ft_check.start_throttle / _ft_check.transition_throttle);
const float added_thrust = math::max(math::sq(_pusher_throttle / _ft_check.transition_throttle) - start_thrust, 0.f);
// Least-squares fit of the forward acceleration (pusher thrust minus drag, divided by the mass) to the added
// thrust: each sample counts with its thrust, so the low throttle at the start of the ramp weighs little.
const float dt = (vehicle_acceleration.timestamp_sample - last_sample) * 1e-6f;
_ft_check.weighted_speed_gain += added_thrust * vehicle_acceleration.xyz[0] * dt;
_ft_check.weighted_time += added_thrust * added_thrust * dt;
// [s] decide once the samples weigh as much as this time at the transition throttle
static constexpr float kCheckTime = 1.f;
if (_ft_check.weighted_time < math::sq(1.f - start_thrust) * kCheckTime) {
return false;
}
_ft_check.done = true;
// fitted acceleration at the transition throttle below VT_EF_FT_ACC
return _ft_check.weighted_speed_gain < _param_vt_ef_ft_acc.get() * _ft_check.weighted_time;
// the pusher thrust grows with the throttle squared
const float thrust_share = math::sq(_pusher_throttle / _ft_transition_throttle);
return _ft_thrust_check.update(vehicle_acceleration.timestamp_sample, thrust_share, vehicle_acceleration.xyz[0],
_param_vt_ef_ft_acc.get());
}
void Standard::update_fw_state()
+3 -9
View File
@@ -45,6 +45,7 @@
#ifndef STANDARD_H
#define STANDARD_H
#include "FrontTransitionThrustCheck.hpp"
#include "vtol_type.h"
#include <uORB/Subscription.hpp>
@@ -85,15 +86,8 @@ private:
// front transition (ft) check: forward acceleration fitted to the pusher thrust added since the start
uORB::Subscription _vehicle_acceleration_sub{ORB_ID(vehicle_acceleration)};
struct FtPusherCheck {
hrt_abstime last_sample{0};
float transition_throttle{0.f}; ///< when the front transition started
float start_throttle{0.f}; ///< pusher assist throttle when the front transition started
float weighted_speed_gain{0.f}; ///< [m/s] forward acceleration integrated, weighted by the added thrust
float weighted_time{0.f}; ///< [s] time integrated, weighted by the added thrust squared
bool done{true}; ///< checked in this front transition, or not needed
} _ft_check{};
FrontTransitionThrustCheck _ft_thrust_check{};
float _ft_transition_throttle{0.f}; ///< when the front transition started
bool _ft_pusher_failed{false}; ///< latched until reboot or until VT_EF_FT_ACC is set to 0
@@ -342,9 +342,8 @@ TEST_F(VtolForwardPropulsionFailureTest, TiltrotorDisablingDetectionAllowsFrontT
EXPECT_EQ(tiltrotor.get_mode(), mode::TRANSITION_TO_FW);
}
// In a front transition, the forward acceleration fitted to the added pusher thrust (thrust grows with the throttle
// squared) has to reach VT_EF_FT_ACC (0.8 m/s^2 by default) at the transition throttle. The check decides once the
// samples weigh as much as 1 s at the transition throttle.
// How Standard feeds the front transition check, whose fit FrontTransitionThrustCheckTest covers: the thrust share is
// the pusher throttle squared, relative to the transition throttle. With VT_PSHER_SLEW 0 it decides after 1 s.
class VtolFrontTransitionPusherTest : public VtolForwardPropulsionFailureTest
{
protected:
@@ -383,7 +382,7 @@ protected:
}
// Fly the front transition until the quad-chute or the timeout, returns the time. The forward acceleration is a
// function of the time since the start of this flight, a NAN acceleration publishes none.
// function of the time since the start of this flight.
template<typename ForwardAcceleration>
hrt_abstime flyFrontTransitionWith(VtolAttitudeControl &attc, Standard &standard,
ForwardAcceleration acceleration_at, hrt_abstime timeout)
@@ -391,15 +390,11 @@ protected:
const hrt_abstime start = hrt_absolute_time();
while (!attc.is_fixed_wing_system_failure() && hrt_elapsed_time(&start) < timeout) {
const float forward_acceleration = acceleration_at(hrt_elapsed_time(&start));
if (PX4_ISFINITE(forward_acceleration)) {
vehicle_acceleration_s vehicle_acceleration{};
vehicle_acceleration.timestamp_sample = hrt_absolute_time();
vehicle_acceleration.xyz[0] = forward_acceleration;
vehicle_acceleration.timestamp = hrt_absolute_time();
_vehicle_acceleration_pub.publish(vehicle_acceleration);
}
vehicle_acceleration_s vehicle_acceleration{};
vehicle_acceleration.timestamp_sample = hrt_absolute_time();
vehicle_acceleration.xyz[0] = acceleration_at(hrt_elapsed_time(&start));
vehicle_acceleration.timestamp = hrt_absolute_time();
_vehicle_acceleration_pub.publish(vehicle_acceleration);
attc.get_mc_virtual_att_sp()->timestamp = hrt_absolute_time();
attc.get_fw_virtual_att_sp()->timestamp = hrt_absolute_time();
@@ -473,60 +468,24 @@ TEST_F(VtolFrontTransitionPusherTest, ForwardAccelerationIsNoPusherFailure)
Standard standard(&attc);
startFrontTransition(attc, standard);
flyFrontTransition(attc, standard, 1.f, 2500_ms);
flyFrontTransition(attc, standard, 1.f, 1500_ms);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
EXPECT_EQ(standard.get_mode(), mode::TRANSITION_TO_FW);
}
TEST_F(VtolFrontTransitionPusherTest, PusherFailingAfterTheCheckIsNotDetected)
TEST_F(VtolFrontTransitionPusherTest, LowerTransitionThrottleDecidesAfterOneSecondToo)
{
const float transition_throttle = 0.6f;
param_set(param_find("VT_F_TRANS_THR"), &transition_throttle);
VtolAttitudeControl attc;
Standard standard(&attc);
startFrontTransition(attc, standard);
// the check only covers the start of the transition, where drag is low, then drag decelerates the vehicle
flyFrontTransition(attc, standard, 3.f, 1700_ms);
flyFrontTransition(attc, standard, -2.f, 2500_ms);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
}
TEST_F(VtolFrontTransitionPusherTest, SlowPusherSpinUpIsNoPusherFailure)
{
VtolAttitudeControl attc;
Standard standard(&attc);
startFrontTransition(attc, standard);
// a motor that needs 0.25 s to spin up after the throttle step, with twice VT_EF_FT_ACC
flyFrontTransition(attc, standard, 0.f, 250_ms);
flyFrontTransition(attc, standard, 1.6f, 2500_ms);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
}
TEST_F(VtolFrontTransitionPusherTest, MissingAccelerationIsNoPusherFailure)
{
VtolAttitudeControl attc;
Standard standard(&attc);
startFrontTransition(attc, standard);
flyFrontTransition(attc, standard, NAN, 2500_ms);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
}
TEST_F(VtolFrontTransitionPusherTest, AccelerationSamplesWithGapsAreNotAveraged)
{
VtolAttitudeControl attc;
Standard standard(&attc);
startFrontTransition(attc, standard);
// samples 150 ms apart are not consecutive: nothing is averaged, so there is no decision
const hrt_abstime start = hrt_absolute_time();
while (hrt_elapsed_time(&start) < 3_s) {
flyFrontTransition(attc, standard, 0.f, 5_ms);
flyFrontTransition(attc, standard, NAN, 145_ms);
}
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
// the thrust share is relative to the transition throttle, so 0.6 counts as the whole transition thrust
const hrt_abstime transition_time = flyFrontTransition(attc, standard, 0.f, 3_s);
EXPECT_TRUE(attc.is_fixed_wing_system_failure());
EXPECT_GE(transition_time, 1_s);
EXPECT_LT(transition_time, 1300_ms);
}
TEST_F(VtolFrontTransitionPusherTest, PusherAssistBeforeTheTransitionLowersTheRequiredAcceleration)
@@ -540,7 +499,7 @@ TEST_F(VtolFrontTransitionPusherTest, PusherAssistBeforeTheTransitionLowersTheRe
ASSERT_NEAR(runCycle(attc, standard, true), 0.49f, 0.01f);
startFrontTransition(attc, standard);
flyFrontTransition(attc, standard, 0.7f, 2500_ms);
flyFrontTransition(attc, standard, 0.7f, 1500_ms);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
}
@@ -571,18 +530,6 @@ TEST_F(VtolFrontTransitionPusherTest, AccelerationBelowVtEfFtAccIsPusherFailure)
EXPECT_EQ(quadchuteReason(attc), QuadchuteReason::ForwardPropulsionFailure);
}
TEST_F(VtolFrontTransitionPusherTest, AccelerationAboveVtEfFtAccIsNoPusherFailure)
{
const float ft_acc = 2.f;
param_set(param_find("VT_EF_FT_ACC"), &ft_acc);
VtolAttitudeControl attc;
Standard standard(&attc);
startFrontTransition(attc, standard);
flyFrontTransition(attc, standard, 2.5f, 2500_ms);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
}
TEST_F(VtolFrontTransitionPusherTest, PusherAssistGivingHalfTheTransitionThrustIsNotChecked)
{
const float transition_throttle = 0.6f;
@@ -595,7 +542,7 @@ TEST_F(VtolFrontTransitionPusherTest, PusherAssistGivingHalfTheTransitionThrustI
runCycle(attc, standard, true);
startFrontTransition(attc, standard);
flyFrontTransition(attc, standard, -1.f, 2500_ms);
flyFrontTransition(attc, standard, -1.f, 1500_ms);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
}
@@ -614,33 +561,6 @@ TEST_F(VtolFrontTransitionPusherTest, WeakPusherWhileTheThrottleRampsUpIsPusherF
EXPECT_LT(transition_time, 2800_ms);
}
TEST_F(VtolFrontTransitionPusherTest, WorkingPusherWhileTheThrottleRampsUpIsNoPusherFailure)
{
const float pusher_slew = 0.5f;
param_set(param_find("VT_PSHER_SLEW"), &pusher_slew);
VtolAttitudeControl attc;
Standard standard(&attc);
startFrontTransition(attc, standard);
flyFrontTransitionThrottleRamp(attc, standard, 1.6f, pusher_slew, 4_s);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
}
TEST_F(VtolFrontTransitionPusherTest, EarlyAccelerationDoesNotHideALaterFailure)
{
const float pusher_slew = 0.5f;
param_set(param_find("VT_PSHER_SLEW"), &pusher_slew);
VtolAttitudeControl attc;
Standard standard(&attc);
startFrontTransition(attc, standard);
// more acceleration at low throttle than the throttle squared gives, then the pusher stops: samples count with
// the pusher thrust, so the start of the ramp weighs little
flyFrontTransition(attc, standard, 3.f, 500_ms);
flyFrontTransition(attc, standard, 0.f, 3_s);
EXPECT_TRUE(attc.is_fixed_wing_system_failure());
}
TEST_F(VtolFrontTransitionPusherTest, DisabledCheckIsNoPusherFailure)
{
const float ft_acc = 0.f;
@@ -649,7 +569,7 @@ TEST_F(VtolFrontTransitionPusherTest, DisabledCheckIsNoPusherFailure)
Standard standard(&attc);
startFrontTransition(attc, standard);
flyFrontTransition(attc, standard, -1.f, 2500_ms);
flyFrontTransition(attc, standard, -1.f, 1500_ms);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
}
@@ -706,6 +626,6 @@ TEST_F(VtolFrontTransitionPusherTest, FrontTransitionFromBackTransitionIsNotChec
// drag at this speed can hide the acceleration of a working pusher
setCalibratedAirspeed(attc, 9.f);
flyFrontTransition(attc, standard, 0.f, 2500_ms);
flyFrontTransition(attc, standard, 0.f, 1500_ms);
EXPECT_FALSE(attc.is_fixed_wing_system_failure());
}