Page 1 of 1

Python loop @ 80Hz

Posted: Wed Mar 01, 2017 8:18 am
by musicboy
Hi all,

I need to run a control loop for a robot at 80Hz in Python.
Obviously there are various ways to do this using time/datetime etc, starting each loop iteration once dt has elapsed.
I have two questions:
1) I have heard that when using time/datetime, the values may not always be accurate at the milliseconds level. Thoughts?
2) Clearly the program will be running on top of Raspbian, and so it is not guaranteed that the program will make 80Hz every time. Is there anything I can strip down to make this more likely?

Any help much appreciated.
Ta

Re: Python loop @ 80Hz

Posted: Wed Mar 01, 2017 8:41 am
by rpdom
80Hz is not very fast. What is the frequency tolerance of your robot? It may be that the Pi's timing will be sufficient.

Re: Python loop @ 80Hz

Posted: Wed Mar 01, 2017 9:54 am
by ghp
For what purpose do you need 80Hz? If it is just for a trigger or sync signal, you could use frequency output on GPIO4.
If you want to perform some actions in python, the things to execute must fit inside 12.5ms time frame...
Regards,
Gerhard

Re: Python loop @ 80Hz

Posted: Wed Mar 01, 2017 1:31 pm
by musicboy
80Hz is a ballpark figure for the frequency at which I need to step the motors on the bot.
The PID loop will be running at ~30Hz since that is the maximum sampling frequency of my accelerometer

Re: Python loop @ 80Hz

Posted: Thu Mar 02, 2017 9:11 pm
by ghp
Hello,
was curious to see how accurate an 80Hz loop in python is on a Pi.
See http://heppg.de/ikg/wordpress/?p=914 for the results.
Accuracy can be achieved close to 0.1ms.
Regards,
Gerhard

Re: Python loop @ 80Hz

Posted: Fri Mar 03, 2017 1:35 pm
by musicboy
Thanks very much for looking into it in such detail!
Much appreciated.