From 26c6224b2e2c364c5398d11d5624e51312b37b41 Mon Sep 17 00:00:00 2001 From: Michel Pastor Date: Tue, 6 Jul 2021 00:37:01 +0200 Subject: [PATCH] AP_ESC_Telem: add method to get the temperature of the motor with highest temperature --- libraries/AP_ESC_Telem/AP_ESC_Telem.cpp | 16 ++++++++++++++++ libraries/AP_ESC_Telem/AP_ESC_Telem.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/libraries/AP_ESC_Telem/AP_ESC_Telem.cpp b/libraries/AP_ESC_Telem/AP_ESC_Telem.cpp index a82a1bdf90..6060eec2a6 100644 --- a/libraries/AP_ESC_Telem/AP_ESC_Telem.cpp +++ b/libraries/AP_ESC_Telem/AP_ESC_Telem.cpp @@ -145,6 +145,22 @@ bool AP_ESC_Telem::get_motor_temperature(uint8_t esc_index, int16_t& temp) const return true; } +// get the highest ESC temperature in centi-degrees if available, returns true if there is valid data for at least one ESC +bool AP_ESC_Telem::get_highest_motor_temperature(int16_t& temp) const +{ + uint8_t valid_escs = 0; + + for (uint8_t i = 0; i < ESC_TELEM_MAX_ESCS; i++) { + int16_t temp_temp; + if (get_motor_temperature(i, temp_temp)) { + temp = MAX(temp, temp_temp); + valid_escs++; + } + } + + return valid_escs > 0; +} + // get an individual ESC's current in Ampere if available, returns true on success bool AP_ESC_Telem::get_current(uint8_t esc_index, float& amps) const { diff --git a/libraries/AP_ESC_Telem/AP_ESC_Telem.h b/libraries/AP_ESC_Telem/AP_ESC_Telem.h index 021f5b277f..b9e43113ff 100644 --- a/libraries/AP_ESC_Telem/AP_ESC_Telem.h +++ b/libraries/AP_ESC_Telem/AP_ESC_Telem.h @@ -39,6 +39,9 @@ public: // get an individual motor's temperature in centi-degrees if available, returns true on success bool get_motor_temperature(uint8_t esc_index, int16_t& temp) const; + // get the highest ESC temperature in centi-degrees if available, returns true if there is valid data for at least one ESC + bool get_highest_motor_temperature(int16_t& temp) const; + // get an individual ESC's current in Ampere if available, returns true on success bool get_current(uint8_t esc_index, float& amps) const;