dshot: bdshot fix esc offline/online checks

This commit is contained in:
Peter van der Perk
2024-05-30 04:56:42 -04:00
committed by David Sidrane
parent 0e41f9730f
commit 5d2fda6172
5 changed files with 54 additions and 8 deletions
@@ -86,8 +86,11 @@ typedef struct dshot_handler_t {
uint32_t crc_error_cnt;
uint32_t frame_error_cnt;
uint32_t no_response_cnt;
uint32_t last_no_response_cnt;
} dshot_handler_t;
#define BDSHOT_OFFLINE_COUNT 400 // If there are no responses for 400 setpoints ESC is offline
static dshot_handler_t dshot_inst[DSHOT_TIMERS] = {};
static uint32_t dshot_tcmp;
@@ -390,6 +393,7 @@ void up_bdshot_erpm(void)
} else {
dshot_inst[channel].erpm = ~(erpm >> 4) & 0xFFF;
bdshot_parsed_recv_mask |= (1 << channel);
dshot_inst[channel].last_no_response_cnt = dshot_inst[channel].no_response_cnt;
}
} else {
@@ -411,6 +415,14 @@ int up_bdshot_get_erpm(uint8_t channel, int *erpm)
return -1;
}
int up_bdshot_channel_status(uint8_t channel)
{
if (channel < DSHOT_TIMERS) {
return ((dshot_inst[channel].no_response_cnt - dshot_inst[channel].last_no_response_cnt) < BDSHOT_OFFLINE_COUNT);
}
return -1;
}
void up_bdshot_status(void)
{
@@ -418,7 +430,8 @@ void up_bdshot_status(void)
for (uint8_t channel = 0; (channel < DSHOT_TIMERS); channel++) {
if (dshot_inst[channel].init) {
PX4_INFO("Channel %i Last erpm %i value", channel, dshot_inst[channel].erpm);
PX4_INFO("Channel %i %s Last erpm %i value", channel, up_bdshot_channel_status(channel) ? "online" : "offline",
dshot_inst[channel].erpm);
PX4_INFO("CRC errors Frame error No response");
PX4_INFO("%10lu %11lu %11lu", dshot_inst[channel].crc_error_cnt, dshot_inst[channel].frame_error_cnt,
dshot_inst[channel].no_response_cnt);
@@ -158,6 +158,12 @@ int up_bdshot_get_erpm(uint8_t channel, int *erpm)
return -1;
}
int up_bdshot_channel_status(uint8_t channel)
{
// Not implemented
return -1;
}
void up_bdshot_status(void)
{
}