2020-02-14 01:18:20 -04:00
|
|
|
/*
|
|
|
|
ESC Telemetry for Hobbywing Pro 80A HV ESC. This will be
|
|
|
|
incorporated into a broader ESC telemetry library in ArduPilot
|
|
|
|
master in the future
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
|
|
|
|
#ifdef HAL_PERIPH_ENABLE_HWESC
|
|
|
|
|
|
|
|
class HWESC_Telem {
|
|
|
|
public:
|
|
|
|
HWESC_Telem();
|
|
|
|
|
|
|
|
void init(AP_HAL::UARTDriver *uart);
|
|
|
|
bool update();
|
|
|
|
|
|
|
|
struct HWESC {
|
|
|
|
uint32_t counter;
|
|
|
|
uint16_t throttle_req;
|
|
|
|
uint16_t throttle;
|
2020-03-09 19:36:59 -03:00
|
|
|
float rpm;
|
2020-02-14 01:18:20 -04:00
|
|
|
float voltage;
|
2020-03-09 19:36:59 -03:00
|
|
|
float phase_current;
|
2020-02-14 01:18:20 -04:00
|
|
|
float current;
|
2020-03-31 20:49:02 -03:00
|
|
|
uint8_t mos_temperature;
|
|
|
|
uint8_t cap_temperature;
|
2020-03-09 19:36:59 -03:00
|
|
|
uint16_t status;
|
2020-03-31 20:49:02 -03:00
|
|
|
uint32_t error_count;
|
2020-02-14 01:18:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const HWESC &get_telem(void) {
|
|
|
|
return decoded;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
AP_HAL::UARTDriver *uart;
|
|
|
|
|
|
|
|
struct PACKED {
|
|
|
|
uint8_t header; // 0x9B
|
|
|
|
uint8_t pkt_len; // 0x16
|
|
|
|
uint32_t counter;
|
|
|
|
uint16_t throttle_req;
|
|
|
|
uint16_t throttle;
|
|
|
|
uint16_t rpm;
|
|
|
|
uint16_t voltage;
|
2020-02-14 03:52:07 -04:00
|
|
|
int16_t current;
|
2020-03-09 19:36:59 -03:00
|
|
|
int16_t phase_current;
|
2020-03-31 20:49:02 -03:00
|
|
|
uint8_t mos_temperature;
|
|
|
|
uint8_t cap_temperature;
|
2020-03-09 19:36:59 -03:00
|
|
|
uint16_t status;
|
2020-02-14 01:18:20 -04:00
|
|
|
uint16_t crc;
|
|
|
|
} pkt;
|
|
|
|
|
|
|
|
uint8_t len;
|
|
|
|
uint32_t last_read_ms;
|
2020-03-31 20:49:02 -03:00
|
|
|
uint32_t error_count;
|
2020-02-14 01:18:20 -04:00
|
|
|
|
|
|
|
struct HWESC decoded;
|
|
|
|
|
|
|
|
bool parse_packet(void);
|
2020-03-31 20:49:02 -03:00
|
|
|
uint8_t temperature_decode(uint8_t temp_raw) const;
|
2020-02-14 01:18:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HAL_PERIPH_ENABLE_HWESC
|