1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 22:35:23 +03:00

Improved retry timeout check and 10 seconds of no response from ESCs check

This commit is contained in:
Bas Delfos 2016-11-27 12:27:25 +01:00
parent 2ffe57761e
commit c1d442279f

View file

@ -89,7 +89,7 @@ static uint8_t tlmFramePosition = 0;
static serialPort_t *escSensorPort = NULL;
static esc_telemetry_t escSensorData[MAX_SUPPORTED_MOTORS];
static uint32_t escTriggerTimestamp = -1;
static uint32_t escTriggerLastTimestamp = -1;
static uint32_t escLastResponseTimestamp;
static uint8_t timeoutRetryCount = 0;
static uint8_t totalRetryCount = 0;
@ -208,7 +208,7 @@ void escSensorProcess(timeUs_t currentTimeUs)
}
// Wait period of time before requesting telemetry (let the system boot first)
if (millis() < ESC_BOOTTIME) {
if (currentTimeMs < ESC_BOOTTIME) {
return;
}
else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_WAIT) {
@ -216,7 +216,7 @@ void escSensorProcess(timeUs_t currentTimeUs)
escSensorTriggerState = ESC_SENSOR_TRIGGER_READY;
escSensorMotor = 0;
escTriggerTimestamp = currentTimeMs;
escTriggerLastTimestamp = escTriggerTimestamp;
escLastResponseTimestamp = escTriggerTimestamp;
}
else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_READY) {
DEBUG_SET(DEBUG_ESC_SENSOR, 0, escSensorMotor+1);
@ -225,6 +225,7 @@ void escSensorProcess(timeUs_t currentTimeUs)
motor->requestTelemetry = true;
escSensorTriggerState = ESC_SENSOR_TRIGGER_PENDING;
}
else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_PENDING) {
if (escTriggerTimestamp + ESC_REQUEST_TIMEOUT < currentTimeMs) {
// ESC did not repond in time, retry
@ -265,9 +266,11 @@ void escSensorProcess(timeUs_t currentTimeUs)
selectNextMotor();
escSensorTriggerState = ESC_SENSOR_TRIGGER_READY;
escLastResponseTimestamp = currentTimeMs;
}
}
if (escTriggerLastTimestamp + 10000 < currentTimeMs) {
if (escLastResponseTimestamp + 10000 < currentTimeMs) {
// ESCs did not respond for 10 seconds
// Disable ESC telemetry and reset voltage and current to let the use know something is wrong
freeEscSensorPort();
@ -282,8 +285,8 @@ static void selectNextMotor(void)
if (escSensorMotor == getMotorCount()) {
escSensorMotor = 0;
}
timeoutRetryCount = 0;
escTriggerTimestamp = millis();
escTriggerLastTimestamp = escTriggerTimestamp;
}
//-- CRC