Should I use callbacks or a forever loop for driver control

I was wondering if i should use call backs or a forever loop and want to no witch one is better or if it makes no difference.

Forever loop is always a better choice for the beginners, but many times is the preferred solution for experts as well. If you have all your logic in one place it will be easier to understand what is happening at any given moment and everything is very predictable.

Callbacks make sense only when you have more code that could fit in a single function, but you are running a great risk of having conflicting commands sent to motors by different callbacks or threads. If you don’t understand concurrent programming well, please, stay away from callbacks. Only invest in learning them when you feel comfortable doing everything with the loops.

Also, don’t forget to add task::sleep(10); at the end of your loops for 10 msec delays to give other tasks a chance to do what they need to do.


Well I just spent all night figuring out call backs and I might use those for macros. F in the chat

1 Like

Ouch man.
(20 chars)