Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/modules/commander/failure_detector/FailureDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,9 @@ void FailureDetector::updateMotorStatus(const vehicle_status_s &vehicle_status,
// First wait for some ESC telemetry that has the required fields. Before that happens, don't check this ESC
// Then check

const hrt_abstime time_now = hrt_absolute_time();

// Only check while armed
if (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED) {
const hrt_abstime now = hrt_absolute_time();
const int limited_esc_count = math::min(esc_status.esc_count, esc_status_s::CONNECTED_ESC_MAX);

actuator_motors_s actuator_motors{};
Expand All @@ -282,9 +281,7 @@ void FailureDetector::updateMotorStatus(const vehicle_status_s &vehicle_status,
}

// Check for telemetry timeout
const hrt_abstime telemetry_age = time_now - cur_esc_report.timestamp;
const bool esc_timed_out = telemetry_age > 300_ms;

const bool esc_timed_out = now > cur_esc_report.timestamp + 300_ms;
const bool esc_was_valid = _motor_failure_esc_valid_current_mask & (1 << i_esc);
const bool esc_timeout_currently_flagged = _motor_failure_esc_timed_out_mask & (1 << i_esc);

Expand Down Expand Up @@ -315,7 +312,7 @@ void FailureDetector::updateMotorStatus(const vehicle_status_s &vehicle_status,

if (throttle_above_threshold && current_too_low && !esc_timed_out) {
if (_motor_failure_undercurrent_start_time[i_esc] == 0) {
_motor_failure_undercurrent_start_time[i_esc] = time_now;
_motor_failure_undercurrent_start_time[i_esc] = now;
}

} else {
Expand All @@ -325,7 +322,7 @@ void FailureDetector::updateMotorStatus(const vehicle_status_s &vehicle_status,
}

if (_motor_failure_undercurrent_start_time[i_esc] != 0
&& (time_now - _motor_failure_undercurrent_start_time[i_esc]) > _param_fd_motor_time_thres.get() * 1_ms
&& now > (_motor_failure_undercurrent_start_time[i_esc] + (_param_fd_motor_time_thres.get() * 1_ms))
&& (_motor_failure_esc_under_current_mask & (1 << i_esc)) == 0) {
// Set flag
_motor_failure_esc_under_current_mask |= (1 << i_esc);
Expand Down
Loading