1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Fix erroneous dshot motor frame between multiple queued dshot commands

In the case of multiple queued non-blocking dshot commands, a single motor command frame would get erroneously sent in the idle time between the commands when arming. This change contains some workarounds to prevent this behavior.
This commit is contained in:
Bruce Luckcuck 2019-04-06 19:13:07 -04:00
parent 22b9f34532
commit 27e4dddeef

View file

@ -456,7 +456,11 @@ FAST_CODE bool pwmDshotCommandIsProcessing(void)
return false;
}
dshotCommandControl_t* command = &commandQueue[commandQueueTail];
return command->nextCommandAtUs && !command->waitingForIdle && command->repeats > 0;
// Check if this is the last command in the queue. If not then we want to
// keep sending the command instead of falling back to the motor value to
// prevent a motor command frame to slip through between the this and the next command.
const bool isLastCommand = (commandQueueTail + 1) % (DSHOT_MAX_COMMANDS + 1) == commandQueueHead;
return (command->nextCommandAtUs && !command->waitingForIdle && command->repeats > 0) || !isLastCommand;
}
FAST_CODE void pwmDshotCommandQueueUpdate(void)
@ -467,6 +471,12 @@ FAST_CODE void pwmDshotCommandQueueUpdate(void)
dshotCommandControl_t* command = &commandQueue[commandQueueTail];
if (!command->nextCommandAtUs && !command->waitingForIdle && !command->repeats) {
commandQueueTail = (commandQueueTail + 1) % (DSHOT_MAX_COMMANDS + 1);
if (pwmDshotCommandIsQueued()) {
// there's another command in the queue
dshotCommandControl_t* nextCommand = &commandQueue[commandQueueTail];
nextCommand->waitingForIdle = false;
nextCommand->nextCommandAtUs = micros() + command->delayAfterCommandUs;
}
}
}