2021-02-23 18:04:06 -04:00
|
|
|
#pragma once
|
|
|
|
|
2023-03-01 02:12:36 -04:00
|
|
|
#include "AP_ESC_Telem_config.h"
|
2021-02-23 18:04:06 -04:00
|
|
|
|
|
|
|
#if HAL_WITH_ESC_TELEM
|
|
|
|
|
|
|
|
class AP_ESC_Telem;
|
|
|
|
|
|
|
|
class AP_ESC_Telem_Backend {
|
|
|
|
public:
|
|
|
|
|
|
|
|
struct TelemetryData {
|
|
|
|
int16_t temperature_cdeg; // centi-degrees C, negative values allowed
|
|
|
|
float voltage; // Volt
|
|
|
|
float current; // Ampere
|
|
|
|
float consumption_mah; // milli-Ampere.hours
|
|
|
|
uint32_t usage_s; // usage seconds
|
|
|
|
int16_t motor_temp_cdeg; // centi-degrees C, negative values allowed
|
2022-01-29 20:18:52 -04:00
|
|
|
uint32_t last_update_ms; // last update time in milliseconds, determines whether active
|
2021-02-23 18:04:06 -04:00
|
|
|
uint16_t types; // telemetry types present
|
|
|
|
uint16_t count; // number of times updated
|
2024-05-13 20:16:21 -03:00
|
|
|
#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED
|
|
|
|
uint16_t edt2_status; // status reported by Extended DShot Telemetry v2
|
|
|
|
uint16_t edt2_stress; // stress reported in dedicated messages by Extended DShot Telemetry v2
|
|
|
|
#endif
|
2024-07-27 16:44:13 -03:00
|
|
|
#if AP_EXTENDED_ESC_TELEM_ENABLED
|
|
|
|
uint8_t input_duty; // input duty cycle
|
|
|
|
uint8_t output_duty; // output duty cycle
|
|
|
|
uint32_t flags; // Status flags
|
2024-07-27 16:03:36 -03:00
|
|
|
uint8_t power_percentage; // Percentage of output power
|
2024-07-27 16:44:13 -03:00
|
|
|
#endif // AP_EXTENDED_ESC_TELEM_ENABLED
|
2023-10-25 03:48:48 -03:00
|
|
|
|
|
|
|
// return true if the data is stale
|
2024-08-06 21:37:49 -03:00
|
|
|
bool stale(uint32_t now_ms) const volatile;
|
|
|
|
|
|
|
|
// return true if the requested type of data is available and not stale
|
|
|
|
bool valid(const uint16_t type_mask) const volatile;
|
2021-02-23 18:04:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RpmData {
|
|
|
|
float rpm; // rpm
|
|
|
|
float prev_rpm; // previous rpm
|
|
|
|
float error_rate; // error rate in percent
|
2023-07-21 14:07:13 -03:00
|
|
|
uint32_t last_update_us; // last update time, greater then 0 means we've gotten data at some point
|
2021-02-23 18:04:06 -04:00
|
|
|
float update_rate_hz;
|
2023-07-21 14:07:13 -03:00
|
|
|
bool data_valid; // if this isn't set to true, then the ESC data should be ignored
|
2021-02-23 18:04:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum TelemetryType {
|
|
|
|
TEMPERATURE = 1 << 0,
|
|
|
|
MOTOR_TEMPERATURE = 1 << 1,
|
|
|
|
VOLTAGE = 1 << 2,
|
|
|
|
CURRENT = 1 << 3,
|
|
|
|
CONSUMPTION = 1 << 4,
|
2022-10-11 16:34:32 -03:00
|
|
|
USAGE = 1 << 5,
|
|
|
|
TEMPERATURE_EXTERNAL = 1 << 6,
|
|
|
|
MOTOR_TEMPERATURE_EXTERNAL = 1 << 7,
|
2024-05-13 20:16:21 -03:00
|
|
|
#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED
|
|
|
|
EDT2_STATUS = 1 << 8,
|
|
|
|
EDT2_STRESS = 1 << 9,
|
|
|
|
#endif
|
2024-07-27 16:44:13 -03:00
|
|
|
#if AP_EXTENDED_ESC_TELEM_ENABLED
|
|
|
|
INPUT_DUTY = 1 << 10,
|
|
|
|
OUTPUT_DUTY = 1 << 11,
|
2024-07-27 16:03:36 -03:00
|
|
|
FLAGS = 1 << 12,
|
|
|
|
POWER_PERCENTAGE = 1 << 13,
|
2024-07-27 16:44:13 -03:00
|
|
|
#endif // AP_EXTENDED_ESC_TELEM_ENABLED
|
2021-02-23 18:04:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
AP_ESC_Telem_Backend();
|
|
|
|
|
|
|
|
/* Do not allow copies */
|
2022-09-30 06:50:43 -03:00
|
|
|
CLASS_NO_COPY(AP_ESC_Telem_Backend);
|
2021-02-23 18:04:06 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// callback to update the rpm in the frontend, should be called by the driver when new data is available
|
2022-05-25 08:26:02 -03:00
|
|
|
void update_rpm(const uint8_t esc_index, const float new_rpm, const float error_rate = 0.0f);
|
2021-02-23 18:04:06 -04:00
|
|
|
|
|
|
|
// callback to update the data in the frontend, should be called by the driver when new data is available
|
|
|
|
void update_telem_data(const uint8_t esc_index, const TelemetryData& new_data, const uint16_t data_present_mask);
|
|
|
|
|
|
|
|
private:
|
|
|
|
AP_ESC_Telem* _frontend;
|
|
|
|
};
|
|
|
|
|
2021-05-26 08:09:32 -03:00
|
|
|
#else
|
|
|
|
|
|
|
|
// dummy empty class
|
|
|
|
class AP_ESC_Telem_Backend {
|
|
|
|
public:
|
|
|
|
AP_ESC_Telem_Backend(){};
|
|
|
|
};
|
|
|
|
|
2021-02-23 18:04:06 -04:00
|
|
|
#endif
|