CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.h
Views: 1798
1
#pragma once
2
3
#include "AP_ESC_Telem_config.h"
4
5
#if HAL_WITH_ESC_TELEM
6
7
class AP_ESC_Telem;
8
9
class AP_ESC_Telem_Backend {
10
public:
11
12
struct TelemetryData {
13
int16_t temperature_cdeg; // centi-degrees C, negative values allowed
14
float voltage; // Volt
15
float current; // Ampere
16
float consumption_mah; // milli-Ampere.hours
17
uint32_t usage_s; // usage seconds
18
int16_t motor_temp_cdeg; // centi-degrees C, negative values allowed
19
uint32_t last_update_ms; // last update time in milliseconds, determines whether active
20
uint16_t types; // telemetry types present
21
uint16_t count; // number of times updated
22
#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED
23
uint16_t edt2_status; // status reported by Extended DShot Telemetry v2
24
uint16_t edt2_stress; // stress reported in dedicated messages by Extended DShot Telemetry v2
25
#endif
26
#if AP_EXTENDED_ESC_TELEM_ENABLED
27
uint8_t input_duty; // input duty cycle
28
uint8_t output_duty; // output duty cycle
29
uint32_t flags; // Status flags
30
uint8_t power_percentage; // Percentage of output power
31
#endif // AP_EXTENDED_ESC_TELEM_ENABLED
32
33
// return true if the data is stale
34
bool stale(uint32_t now_ms) const volatile;
35
36
// return true if the requested type of data is available and not stale
37
bool valid(const uint16_t type_mask) const volatile;
38
};
39
40
struct RpmData {
41
float rpm; // rpm
42
float prev_rpm; // previous rpm
43
float error_rate; // error rate in percent
44
uint32_t last_update_us; // last update time, greater then 0 means we've gotten data at some point
45
float update_rate_hz;
46
bool data_valid; // if this isn't set to true, then the ESC data should be ignored
47
};
48
49
enum TelemetryType {
50
TEMPERATURE = 1 << 0,
51
MOTOR_TEMPERATURE = 1 << 1,
52
VOLTAGE = 1 << 2,
53
CURRENT = 1 << 3,
54
CONSUMPTION = 1 << 4,
55
USAGE = 1 << 5,
56
TEMPERATURE_EXTERNAL = 1 << 6,
57
MOTOR_TEMPERATURE_EXTERNAL = 1 << 7,
58
#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED
59
EDT2_STATUS = 1 << 8,
60
EDT2_STRESS = 1 << 9,
61
#endif
62
#if AP_EXTENDED_ESC_TELEM_ENABLED
63
INPUT_DUTY = 1 << 10,
64
OUTPUT_DUTY = 1 << 11,
65
FLAGS = 1 << 12,
66
POWER_PERCENTAGE = 1 << 13,
67
#endif // AP_EXTENDED_ESC_TELEM_ENABLED
68
};
69
70
71
AP_ESC_Telem_Backend();
72
73
/* Do not allow copies */
74
CLASS_NO_COPY(AP_ESC_Telem_Backend);
75
76
protected:
77
// callback to update the rpm in the frontend, should be called by the driver when new data is available
78
void update_rpm(const uint8_t esc_index, const float new_rpm, const float error_rate = 0.0f);
79
80
// callback to update the data in the frontend, should be called by the driver when new data is available
81
void update_telem_data(const uint8_t esc_index, const TelemetryData& new_data, const uint16_t data_present_mask);
82
83
private:
84
AP_ESC_Telem* _frontend;
85
};
86
87
#else
88
89
// dummy empty class
90
class AP_ESC_Telem_Backend {
91
public:
92
AP_ESC_Telem_Backend(){};
93
};
94
95
#endif
96
97