Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.h
Views: 1798
#pragma once12#include "AP_ESC_Telem_config.h"34#if HAL_WITH_ESC_TELEM56class AP_ESC_Telem;78class AP_ESC_Telem_Backend {9public:1011struct TelemetryData {12int16_t temperature_cdeg; // centi-degrees C, negative values allowed13float voltage; // Volt14float current; // Ampere15float consumption_mah; // milli-Ampere.hours16uint32_t usage_s; // usage seconds17int16_t motor_temp_cdeg; // centi-degrees C, negative values allowed18uint32_t last_update_ms; // last update time in milliseconds, determines whether active19uint16_t types; // telemetry types present20uint16_t count; // number of times updated21#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED22uint16_t edt2_status; // status reported by Extended DShot Telemetry v223uint16_t edt2_stress; // stress reported in dedicated messages by Extended DShot Telemetry v224#endif25#if AP_EXTENDED_ESC_TELEM_ENABLED26uint8_t input_duty; // input duty cycle27uint8_t output_duty; // output duty cycle28uint32_t flags; // Status flags29uint8_t power_percentage; // Percentage of output power30#endif // AP_EXTENDED_ESC_TELEM_ENABLED3132// return true if the data is stale33bool stale(uint32_t now_ms) const volatile;3435// return true if the requested type of data is available and not stale36bool valid(const uint16_t type_mask) const volatile;37};3839struct RpmData {40float rpm; // rpm41float prev_rpm; // previous rpm42float error_rate; // error rate in percent43uint32_t last_update_us; // last update time, greater then 0 means we've gotten data at some point44float update_rate_hz;45bool data_valid; // if this isn't set to true, then the ESC data should be ignored46};4748enum TelemetryType {49TEMPERATURE = 1 << 0,50MOTOR_TEMPERATURE = 1 << 1,51VOLTAGE = 1 << 2,52CURRENT = 1 << 3,53CONSUMPTION = 1 << 4,54USAGE = 1 << 5,55TEMPERATURE_EXTERNAL = 1 << 6,56MOTOR_TEMPERATURE_EXTERNAL = 1 << 7,57#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED58EDT2_STATUS = 1 << 8,59EDT2_STRESS = 1 << 9,60#endif61#if AP_EXTENDED_ESC_TELEM_ENABLED62INPUT_DUTY = 1 << 10,63OUTPUT_DUTY = 1 << 11,64FLAGS = 1 << 12,65POWER_PERCENTAGE = 1 << 13,66#endif // AP_EXTENDED_ESC_TELEM_ENABLED67};686970AP_ESC_Telem_Backend();7172/* Do not allow copies */73CLASS_NO_COPY(AP_ESC_Telem_Backend);7475protected:76// callback to update the rpm in the frontend, should be called by the driver when new data is available77void update_rpm(const uint8_t esc_index, const float new_rpm, const float error_rate = 0.0f);7879// callback to update the data in the frontend, should be called by the driver when new data is available80void update_telem_data(const uint8_t esc_index, const TelemetryData& new_data, const uint16_t data_present_mask);8182private:83AP_ESC_Telem* _frontend;84};8586#else8788// dummy empty class89class AP_ESC_Telem_Backend {90public:91AP_ESC_Telem_Backend(){};92};9394#endif959697