mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-02 22:40:27 +08:00
feat(failure_injection): add ESC failure unit (off/wrong) with correct MAVLink semantics (#28088)
* feat(failure_injection): add process_esc() telemetry helper Add a shared helper that applies the active FAILURE_UNIT_SYSTEM_ESC (106) failures to an esc_status before it is published, matched per ESC by esc_report.actuator_function: Off reports the ESC offline (clears its esc_online_flags bit) so it reads as "completely non-responsive"; Wrong keeps the ESC online but reports consistently wrong values. Mirrors process_battery(); a no-op stub keeps builds without the failure injection manager zero-cost. Unit tested here. * feat(failure_injection): inject ESC failures at the esc_status producers Call process_esc() where esc_status is produced (UAVCAN ESC driver and SIH) so injected ESC failures reach every consumer. Wire the ESC unit end to end: add the "esc" key to the failure CLI and mark FAILURE_UNIT_SYSTEM_ESC as supporting Off and Wrong. Regroup MOTOR to Off-only (actuation): its stuck/wrong were never implemented, so stop advertising them. * refactor(failure_detector): drop the misplaced ESC telemetry injection masks FailureInjector mapped FAILURE_UNIT_SYSTEM_MOTOR Stuck/Wrong to ESC-telemetry masks consumed by manipulateEscStatus() -- on the wrong MAVLink unit (telemetry belongs to FAILURE_UNIT_SYSTEM_ESC) and dead code: manipulateEscStatus() has had no callers since the ESC checks moved into escCheck. The equivalent behaviour now lives on the ESC unit in process_esc (Wrong directly; the old zero+offline "Stuck" as esc off). Remove the masks and the dead method; the motor-stop (Off) path ControlAllocator consumes is unchanged. * refactor(failure_injection): do the copy for the amneded esc_status in the process_esc() function This results in a clearer interface with less lines to call and the same overhead of copying once. * fix(failure_injection): add esc telemetry failure support for all simulation interfaces * fix(failure_injection): zero a disconnected ESCs telemetry It's not entirely realistic because the value would go stale in a real disconnect but better than just flagging it offline but still reporting new telemetry. --------- Co-authored-by: Matthias Grob <maetugr@gmail.com>
This commit is contained in:
1 parent
8aba32c862
commit
e816025c3d
15 files changed
+147
-50
No files matched your search
@@ -129,7 +129,9 @@ void UavcanEscController::esc_status_sub_cb(const uavcan::ReceivedDataStructure<
|
||||
_esc_status.esc_online_flags = check_escs_status();
|
||||
_esc_status.esc_armed_flags = (1 << _rotor_count) - 1;
|
||||
_esc_status.timestamp = esc_report.timestamp;
|
||||
_esc_status_pub.publish(_esc_status);
|
||||
|
||||
_failure_config.update();
|
||||
_esc_status_pub.publish(failure_injection::process_esc(_failure_config, _esc_status));
|
||||
}
|
||||
|
||||
// Register device capability for each ESC channel
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <uORB/topics/esc_status.h>
|
||||
#include <uORB/topics/esc_report.h>
|
||||
#include <uORB/topics/dronecan_node_status.h>
|
||||
#include <lib/failure_injection/FailureInjection.hpp>
|
||||
#include "../node_info.hpp"
|
||||
|
||||
class UavcanEscController
|
||||
@@ -125,6 +126,8 @@ private:
|
||||
|
||||
uint8_t _rotor_count{0};
|
||||
|
||||
failure_injection::Config _failure_config;
|
||||
|
||||
/*
|
||||
* libuavcan related things
|
||||
*/
|
||||
|
||||
@@ -91,6 +91,41 @@ void process_battery(const Config &config, uint8_t instance, battery_status_s &b
|
||||
battery_status.warning = battery_status_s::WARNING_EMERGENCY;
|
||||
}
|
||||
|
||||
esc_status_s process_esc(const Config &config, const esc_status_s &status)
|
||||
{
|
||||
esc_status_s result = status;
|
||||
|
||||
for (int i = 0; i < result.esc_count && i < esc_status_s::CONNECTED_ESC_MAX; i++) {
|
||||
const uint8_t function = result.esc[i].actuator_function;
|
||||
|
||||
if (function < esc_report_s::ACTUATOR_FUNCTION_MOTOR1 || function > esc_report_s::ACTUATOR_FUNCTION_MOTOR_MAX) {
|
||||
continue; // not a motor output
|
||||
}
|
||||
|
||||
const uint8_t instance = function - esc_report_s::ACTUATOR_FUNCTION_MOTOR1 + 1; // 1-based ESC instance
|
||||
|
||||
switch (config.mode(failure_injection_s::FAILURE_UNIT_SYSTEM_ESC, instance)) {
|
||||
case Mode::Off:
|
||||
result.esc_online_flags &= ~(1u << i);
|
||||
result.esc_armed_flags &= ~(1u << i);
|
||||
result.esc[i] = esc_report_s{};
|
||||
result.esc[i].actuator_function = function;
|
||||
break;
|
||||
|
||||
case Mode::Wrong:
|
||||
result.esc[i].esc_voltage *= 0.1f;
|
||||
result.esc[i].esc_current *= 0.1f;
|
||||
result.esc[i].esc_rpm *= 10;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace failure_injection
|
||||
|
||||
#endif // CONFIG_MODULES_FAILURE_INJECTION_MANAGER
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/esc_status.h>
|
||||
#include <uORB/topics/failure_injection.h>
|
||||
|
||||
struct battery_status_s;
|
||||
@@ -195,6 +196,16 @@ inline bool process(const Config &config, uint8_t unit, uint8_t uorb_instance)
|
||||
*/
|
||||
void process_battery(const Config &config, uint8_t instance, battery_status_s &battery_status);
|
||||
|
||||
/**
|
||||
* ESC counterpart to process(): apply the active FAILURE_UNIT_SYSTEM_ESC failures to a copy of
|
||||
* status (matched per ESC by actuator_function). Off zeroes the ESC's telemetry (keeping only
|
||||
* actuator_function) and reports it offline and unarmed; Wrong keeps it online but reports
|
||||
* consistently wrong values. Takes status by const reference and returns the mutated copy so callers
|
||||
* can't accidentally apply it in place to a persistent status, which would compound Wrong across
|
||||
* calls. Call after Config::update().
|
||||
*/
|
||||
esc_status_s process_esc(const Config &config, const esc_status_s &status);
|
||||
|
||||
#else // !CONFIG_MODULES_FAILURE_INJECTION_MANAGER
|
||||
|
||||
class Config
|
||||
@@ -222,6 +233,8 @@ inline bool process(const Config &, uint8_t, uint8_t) { return true; }
|
||||
|
||||
inline void process_battery(const Config &, uint8_t, battery_status_s &) {}
|
||||
|
||||
inline esc_status_s process_esc(const Config &, const esc_status_s &status) { return status; }
|
||||
|
||||
#endif // CONFIG_MODULES_FAILURE_INJECTION_MANAGER
|
||||
|
||||
} // namespace failure_injection
|
||||
@@ -33,9 +33,6 @@
|
||||
|
||||
#include "FailureInjector.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <uORB/topics/actuator_motors.h>
|
||||
|
||||
void FailureInjector::update()
|
||||
{
|
||||
if (_failure_config.update()) {
|
||||
@@ -46,47 +43,10 @@ void FailureInjector::update()
|
||||
void FailureInjector::rebuildMasks()
|
||||
{
|
||||
_motor_stop_mask = 0;
|
||||
_esc_telemetry_blocked_mask = 0;
|
||||
_esc_telemetry_wrong_mask = 0;
|
||||
|
||||
for (int i = 0; i < esc_status_s::CONNECTED_ESC_MAX; i++) {
|
||||
switch (_failure_config.mode(failure_injection_s::FAILURE_UNIT_SYSTEM_MOTOR, i + 1)) {
|
||||
case failure_injection::Mode::Off:
|
||||
if (_failure_config.mode(failure_injection_s::FAILURE_UNIT_SYSTEM_MOTOR, i + 1) == failure_injection::Mode::Off) {
|
||||
_motor_stop_mask |= 1u << i;
|
||||
break;
|
||||
|
||||
case failure_injection::Mode::Stuck:
|
||||
_esc_telemetry_blocked_mask |= 1u << i;
|
||||
break;
|
||||
|
||||
case failure_injection::Mode::Wrong:
|
||||
_esc_telemetry_wrong_mask |= 1u << i;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FailureInjector::manipulateEscStatus(esc_status_s &status)
|
||||
{
|
||||
if (_esc_telemetry_blocked_mask != 0 || _esc_telemetry_wrong_mask != 0) {
|
||||
for (int i = 0; i < status.esc_count; i++) {
|
||||
const unsigned i_esc = status.esc[i].actuator_function - actuator_motors_s::ACTUATOR_FUNCTION_MOTOR1;
|
||||
|
||||
if (_esc_telemetry_blocked_mask & (1 << i_esc)) {
|
||||
unsigned function = status.esc[i].actuator_function;
|
||||
memset(&status.esc[i], 0, sizeof(status.esc[i]));
|
||||
status.esc[i].actuator_function = function;
|
||||
status.esc_online_flags &= ~(1 << i);
|
||||
|
||||
} else if (_esc_telemetry_wrong_mask & (1 << i_esc)) {
|
||||
// Create wrong rerport for this motor by scaling key values up and down
|
||||
status.esc[i].esc_voltage *= 0.1f;
|
||||
status.esc[i].esc_current *= 0.1f;
|
||||
status.esc[i].esc_rpm *= 10.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,6 @@ public:
|
||||
|
||||
void update();
|
||||
|
||||
void manipulateEscStatus(esc_status_s &status);
|
||||
uint32_t getMotorStopMask() { return _motor_stop_mask; }
|
||||
private:
|
||||
// Rebuild the motor masks from the active failure_injection configuration.
|
||||
@@ -53,6 +52,4 @@ private:
|
||||
failure_injection::Config _failure_config;
|
||||
|
||||
uint32_t _motor_stop_mask{};
|
||||
uint32_t _esc_telemetry_blocked_mask{};
|
||||
uint32_t _esc_telemetry_wrong_mask{};
|
||||
};
|
||||
@@ -79,6 +79,7 @@ failure_injection_s make_config(uint8_t unit, uint16_t instance_mask, uint8_t fa
|
||||
constexpr uint8_t GYRO = failure_injection_s::FAILURE_UNIT_SENSOR_GYRO;
|
||||
constexpr uint8_t GPS = failure_injection_s::FAILURE_UNIT_SENSOR_GPS;
|
||||
constexpr uint8_t MOTOR = failure_injection_s::FAILURE_UNIT_SYSTEM_MOTOR;
|
||||
constexpr uint8_t ESC = failure_injection_s::FAILURE_UNIT_SYSTEM_ESC;
|
||||
|
||||
constexpr uint8_t OK = failure_injection_s::FAILURE_TYPE_OK;
|
||||
constexpr uint8_t OFF = failure_injection_s::FAILURE_TYPE_OFF;
|
||||
@@ -267,3 +268,72 @@ TEST(FailureInjectionConfig, ProcessMessageLessSuppressesOnlyOff)
|
||||
EXPECT_FALSE(process(config, GYRO, 1));
|
||||
EXPECT_TRUE(process(config, GYRO, 0));
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// process_esc(): ESC Off / Wrong on the multi-instance esc_status
|
||||
// ===========================================================================
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
esc_status_s make_esc_status(uint8_t num_motors)
|
||||
{
|
||||
esc_status_s status{};
|
||||
status.esc_count = num_motors;
|
||||
status.esc_online_flags = (1u << num_motors) - 1; // all online
|
||||
|
||||
for (uint8_t i = 0; i < num_motors; i++) {
|
||||
status.esc[i].actuator_function = esc_report_s::ACTUATOR_FUNCTION_MOTOR1 + i;
|
||||
status.esc[i].timestamp = 1000;
|
||||
status.esc[i].esc_voltage = 16.f;
|
||||
status.esc[i].esc_current = 5.f;
|
||||
status.esc[i].esc_rpm = 4000;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(FailureInjectionConfig, ProcessEscOffReportsOffline)
|
||||
{
|
||||
Config config;
|
||||
config.set(make_config(ESC, 0x1, OFF)); // ESC 1
|
||||
|
||||
esc_status_s status = make_esc_status(4);
|
||||
status = process_esc(config, status);
|
||||
|
||||
EXPECT_EQ(status.esc_online_flags & 0x1u, 0u); // motor 1 reported offline
|
||||
EXPECT_EQ(status.esc_online_flags & 0xEu, 0xEu); // motors 2-4 untouched
|
||||
}
|
||||
|
||||
TEST(FailureInjectionConfig, ProcessEscMapsByActuatorFunction)
|
||||
{
|
||||
// Motor 3 sits on ESC slot 0; failing motor 3 must take slot 0 offline.
|
||||
Config config;
|
||||
config.set(make_config(ESC, 0x4, OFF)); // ESC 3 -> instance bit (3 - 1)
|
||||
|
||||
esc_status_s status{};
|
||||
status.esc_count = 1;
|
||||
status.esc_online_flags = 0x1;
|
||||
status.esc[0].actuator_function = esc_report_s::ACTUATOR_FUNCTION_MOTOR1 + 2; // Motor 3
|
||||
|
||||
status = process_esc(config, status);
|
||||
|
||||
EXPECT_EQ(status.esc_online_flags & 0x1u, 0u);
|
||||
}
|
||||
|
||||
TEST(FailureInjectionConfig, ProcessEscWrongScalesTelemetryButStaysOnline)
|
||||
{
|
||||
Config config;
|
||||
config.set(make_config(ESC, 0x1, WRONG)); // ESC 1
|
||||
|
||||
esc_status_s status = make_esc_status(4);
|
||||
status = process_esc(config, status);
|
||||
|
||||
EXPECT_EQ(status.esc_online_flags & 0xFu, 0xFu); // all still online
|
||||
EXPECT_FLOAT_EQ(status.esc[0].esc_voltage, 1.6f); // 16 * 0.1
|
||||
EXPECT_FLOAT_EQ(status.esc[0].esc_current, 0.5f); // 5 * 0.1
|
||||
EXPECT_EQ(status.esc[0].esc_rpm, 40000); // 4000 * 10
|
||||
EXPECT_FLOAT_EQ(status.esc[1].esc_voltage, 16.f); // other ESCs untouched
|
||||
}
|
||||
@@ -45,6 +45,7 @@ namespace
|
||||
constexpr uint8_t GYRO = failure_injection_s::FAILURE_UNIT_SENSOR_GYRO;
|
||||
constexpr uint8_t GPS = failure_injection_s::FAILURE_UNIT_SENSOR_GPS;
|
||||
constexpr uint8_t MOTOR = failure_injection_s::FAILURE_UNIT_SYSTEM_MOTOR;
|
||||
constexpr uint8_t ESC = failure_injection_s::FAILURE_UNIT_SYSTEM_ESC;
|
||||
|
||||
constexpr uint8_t OK = failure_injection_s::FAILURE_TYPE_OK;
|
||||
constexpr uint8_t OFF = failure_injection_s::FAILURE_TYPE_OFF;
|
||||
@@ -60,7 +61,12 @@ TEST(FailureTable, SupportedCatalogueMatchesInventory)
|
||||
EXPECT_TRUE(FailureTable::isSupported(GYRO, STUCK));
|
||||
EXPECT_FALSE(FailureTable::isSupported(GYRO, WRONG)); // no gyro WRONG today
|
||||
EXPECT_TRUE(FailureTable::isSupported(GPS, WRONG));
|
||||
EXPECT_TRUE(FailureTable::isSupported(MOTOR, WRONG));
|
||||
EXPECT_TRUE(FailureTable::isSupported(MOTOR, OFF));
|
||||
EXPECT_FALSE(FailureTable::isSupported(MOTOR, STUCK)); // motor is off-only (actuation)
|
||||
EXPECT_FALSE(FailureTable::isSupported(MOTOR, WRONG));
|
||||
EXPECT_TRUE(FailureTable::isSupported(ESC, OFF));
|
||||
EXPECT_TRUE(FailureTable::isSupported(ESC, WRONG)); // ESC: offline or wrong telemetry
|
||||
EXPECT_FALSE(FailureTable::isSupported(ESC, STUCK)); // no frozen-telemetry (stuck) support
|
||||
EXPECT_FALSE(FailureTable::isSupported(GYRO, GARBAGE)); // GARBAGE unimplemented
|
||||
// Distance sensor (rangefinder) supports OFF/STUCK on hardware, but not WRONG.
|
||||
EXPECT_TRUE(FailureTable::isSupported(failure_injection_s::FAILURE_UNIT_SENSOR_DISTANCE_SENSOR, OFF));
|
||||
|
||||
@@ -54,7 +54,6 @@ bool FailureTable::isSupported(uint8_t unit, uint8_t type)
|
||||
|
||||
case failure_injection_s::FAILURE_UNIT_SENSOR_GPS:
|
||||
case failure_injection_s::FAILURE_UNIT_SENSOR_AIRSPEED:
|
||||
case failure_injection_s::FAILURE_UNIT_SYSTEM_MOTOR:
|
||||
return type == failure_injection_s::FAILURE_TYPE_OK
|
||||
|| type == failure_injection_s::FAILURE_TYPE_OFF
|
||||
|| type == failure_injection_s::FAILURE_TYPE_STUCK
|
||||
@@ -62,9 +61,15 @@ bool FailureTable::isSupported(uint8_t unit, uint8_t type)
|
||||
|
||||
case failure_injection_s::FAILURE_UNIT_SENSOR_VIO:
|
||||
case failure_injection_s::FAILURE_UNIT_SYSTEM_BATTERY:
|
||||
case failure_injection_s::FAILURE_UNIT_SYSTEM_MOTOR:
|
||||
return type == failure_injection_s::FAILURE_TYPE_OK
|
||||
|| type == failure_injection_s::FAILURE_TYPE_OFF;
|
||||
|
||||
case failure_injection_s::FAILURE_UNIT_SYSTEM_ESC:
|
||||
return type == failure_injection_s::FAILURE_TYPE_OK
|
||||
|| type == failure_injection_s::FAILURE_TYPE_OFF
|
||||
|| type == failure_injection_s::FAILURE_TYPE_WRONG;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ if (gz-transport_FOUND)
|
||||
drivers_magnetometer
|
||||
drivers_rangefinder
|
||||
drivers_barometer
|
||||
failure_injection
|
||||
mixer_module
|
||||
px4_work_queue
|
||||
${GZ_TRANSPORT_TARGET}
|
||||
|
||||
@@ -132,7 +132,8 @@ void GZMixingInterfaceESC::motorSpeedCallback(const gz::msgs::Actuators &actuato
|
||||
|
||||
if (esc_status.esc_count > 0) {
|
||||
esc_status.timestamp = hrt_absolute_time();
|
||||
_esc_status_pub.publish(esc_status);
|
||||
_failure_config.update();
|
||||
_esc_status_pub.publish(failure_injection::process_esc(_failure_config, esc_status));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&_node_mutex);
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <lib/failure_injection/FailureInjection.hpp>
|
||||
#include <lib/mixer_module/mixer_module.hpp>
|
||||
|
||||
#include <gz/msgs.hh>
|
||||
@@ -82,5 +83,6 @@ private:
|
||||
gz::transport::Node::Publisher _actuators_pub;
|
||||
|
||||
uORB::Publication<esc_status_s> _esc_status_pub{ORB_ID(esc_status)};
|
||||
failure_injection::Config _failure_config;
|
||||
|
||||
};
|
||||
@@ -169,7 +169,8 @@ void SimulatorMavlink::send_esc_telemetry(mavlink_hil_actuator_controls_t hil_ac
|
||||
esc_status.esc_armed_flags = (1u << esc_status.esc_count) - 1;
|
||||
esc_status.esc_online_flags = (1u << esc_status.esc_count) - 1;
|
||||
|
||||
_esc_status_pub.publish(esc_status);
|
||||
// _failure_config refreshed in updateFailureConfig(), called each loop before send_controls()
|
||||
_esc_status_pub.publish(failure_injection::process_esc(_failure_config, esc_status));
|
||||
}
|
||||
|
||||
void SimulatorMavlink::send_controls()
|
||||
|
||||
@@ -437,7 +437,7 @@ void Sih::publish_esc_status()
|
||||
_esc_status.esc_armed_flags = (1u << motor_idx) - 1;
|
||||
}
|
||||
|
||||
_esc_status_pub.publish(_esc_status);
|
||||
_esc_status_pub.publish(failure_injection::process_esc(_failure_config, _esc_status));
|
||||
}
|
||||
|
||||
void Sih::generate_force_and_torques(const float dt)
|
||||
|
||||
@@ -64,6 +64,7 @@ static constexpr FailureUnit failure_units[] = {
|
||||
{ "airspeed", vehicle_command_s::FAILURE_UNIT_SENSOR_AIRSPEED},
|
||||
{ "battery", vehicle_command_s::FAILURE_UNIT_SYSTEM_BATTERY},
|
||||
{ "motor", vehicle_command_s::FAILURE_UNIT_SYSTEM_MOTOR},
|
||||
{ "esc", vehicle_command_s::FAILURE_UNIT_SYSTEM_ESC},
|
||||
{ "servo", vehicle_command_s::FAILURE_UNIT_SYSTEM_SERVO},
|
||||
{ "avoidance", vehicle_command_s::FAILURE_UNIT_SYSTEM_AVOIDANCE},
|
||||
{ "rc_signal", vehicle_command_s::FAILURE_UNIT_SYSTEM_RC_SIGNAL},
|
||||
|
||||
Reference in new issue
Block a user