Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/AP_Periph/esc_apd_telem.h
9314 views
1
/*
2
ESC Telemetry for APD ESC.
3
*/
4
5
#pragma once
6
7
#include <AP_HAL/AP_HAL.h>
8
9
#if AP_PERIPH_ESC_APD_ENABLED
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 // AP_PERIPH_ESC_APD_ENABLED
62
63