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/Tools/AP_Periph/esc_apd_telem.h
Views: 1798
1
/*
2
ESC Telemetry for APD ESC.
3
*/
4
5
#pragma once
6
7
#include <AP_HAL/AP_HAL.h>
8
9
#ifdef HAL_PERIPH_ENABLE_ESC_APD
10
11
class ESC_APD_Telem {
12
public:
13
ESC_APD_Telem (AP_HAL::UARTDriver *_uart, float num_poles);
14
bool update();
15
16
CLASS_NO_COPY(ESC_APD_Telem);
17
18
struct telem {
19
uint32_t error_count;
20
float voltage;
21
float current;
22
float temperature; // kelvin
23
int32_t rpm;
24
uint8_t power_rating_pct;
25
};
26
27
const telem &get_telem(void) {
28
return decoded;
29
}
30
31
private:
32
AP_HAL::UARTDriver *uart;
33
34
union {
35
struct PACKED {
36
uint16_t voltage;
37
uint16_t temperature;
38
int16_t bus_current;
39
uint16_t reserved0;
40
uint32_t erpm;
41
uint16_t input_duty;
42
uint16_t motor_duty;
43
uint16_t reserved1;
44
uint16_t checksum; // 16 bit fletcher checksum
45
uint16_t stop; // should always be 65535 on a valid packet
46
} packet;
47
uint8_t bytes[22];
48
} received;
49
static_assert(sizeof(received.packet) == sizeof(received.bytes), "The packet must be the same size as the raw buffer");
50
51
uint8_t len;
52
53
struct telem decoded;
54
55
float pole_count;
56
57
float convert_temperature(uint16_t raw) const;
58
void shift_buffer(void);
59
};
60
61
#endif // HAL_PERIPH_ENABLE_ESC_APD
62
63