Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

TinyMPU return strange values if used with delay #20

Closed
florian-str opened this issue May 14, 2020 · 3 comments
Closed

TinyMPU return strange values if used with delay #20

florian-str opened this issue May 14, 2020 · 3 comments

Comments

@florian-str
Copy link

I used the default "Angles Example" but added a delay of 1 sec at the end of the void loop(). function. The start Value seems to be ok (around +-2°) but after I started to change the pitch, it starts to return weird values. e.g. even though I put it back on the flat table, it still shows the max value and reduces it really slow (around 0.5° per delay). If I remove the delay, everything is responding immediately.
I also tried to put the printing into another function called after a delay by the loop, but the error is still the same.
I've experienced this bug both on my ESP32 and Arduino UNO (maybe on other boards to but I have only these).
Else it's a great library.

@gabriel-milan
Copy link
Owner

Hi @florian-str, thanks for getting in touch.

To be honest, I wouldn't call this a bug, since the angle calculations are done using the idea of integration:

dt = (millis() - intervalStart) * 0.001;
angGyroX = wrap(angGyroX + gyroX * dt);
angGyroY = wrap(angGyroY + gyroY * dt);
angGyroZ = wrap(angGyroZ + gyroZ * dt);

(This snippet was extracted from here)

As we know, the smaller dt is, the more accurate our results should be. But then, if you insert a delay between loops, dt grows too much, implying on awful results. Many microcontrollers like Arduino UNO are single-cored and have no workarounds on this.

On the other hand, you've mentioned an ESP32. Those guys have 2 cores and can run two parallel tasks. In that case, I would recommend that, if possible, you'd configure one of the cores for MPU6050 stuff only (or add few minor things too) and the other for your delayed loop. Please try this implementation before anything else and, if you need any help on doing so, get in touch.

I won't close this for now, since your issue is not yet fixed.

@florian-str
Copy link
Author

Thank you for your answer. I was able to make it work with the ESP32.

@gabriel-milan
Copy link
Owner

Glad to hear that. If you need anything else, please let me know.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants