randomize the order of tick processing
This commit is contained in:
parent
c667006ca0
commit
29ad62627b
13
main.cpp
13
main.cpp
|
@ -8,6 +8,15 @@ MotorControl motors[4] = {
|
||||||
MotorControl(13, 12)
|
MotorControl(13, 12)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void handle_tick(unsigned long cur_micros) {
|
||||||
|
// Randomize the order we process motor ticks every time
|
||||||
|
// This helps reduce the minor frequency discrepancies between each motor
|
||||||
|
unsigned long start_val = (cur_micros / 10) % 4;
|
||||||
|
for (unsigned long i = start_val; i < start_val + 4; i++) {
|
||||||
|
motors[i % 4].Tick(cur_micros);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
init();
|
init();
|
||||||
// Enable the motor drivers
|
// Enable the motor drivers
|
||||||
|
@ -25,9 +34,7 @@ int main() {
|
||||||
while (true) {
|
while (true) {
|
||||||
unsigned long cur_micros = micros();
|
unsigned long cur_micros = micros();
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
handle_tick(cur_micros);
|
||||||
motors[i].Tick(cur_micros);
|
|
||||||
}
|
|
||||||
|
|
||||||
int new_motor = (cur_micros / 1000 / 1000) % 4;
|
int new_motor = (cur_micros / 1000 / 1000) % 4;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue