accurate-timed-loop-0.0.14
توضیحات
Accurate timed loop
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | accurate-timed-loop-0.0.14 |
| نام | accurate-timed-loop |
| نسخه کتابخانه | 0.0.14 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | JA |
| ایمیل نویسنده | cppgent0@gmail.com |
| آدرس صفحه اصلی | https://bitbucket.org/arrizza-public/accurate-timed-loop/src/master |
| آدرس اینترنتی | https://pypi.org/project/accurate-timed-loop/ |
| مجوز | MIT |
# Accurate Timed Loop #
This is a python module that provide a way to have an acccurate timed loop.
For example if you need to do an activity every 250ms +/-10ms, this loop will do that.
### Sample code ###
see sample.py for a full example
```python
import accurate_timed_loop
loop_delay = 0.250 # seconds
total_wait = 25.0 # seconds
for elapsed, start_time in accurate_timed_loop.accurate_wait(total_wait, loop_delay):
# ... do task every 250 mS
pass
```
### Accuracy and Limitations ###
The sample.py does testing and shows that on Windows MSYS2 the std deviation error is roughly
4mS in a 250mS loop. This means that 95% of loops will be +/-8 mS of the requested loop_delay.
```text
expected elapsed diff1(ms) actual(s) diff2(ms)
1 0.000000 0.000000 0.000 0.000000 0.000
2 0.250000 0.257294 7.294 0.257294 7.294
<snip>
100 24.750000 24.764093 14.093 24.764093 14.093
101 25.000000 25.015579 15.579 25.015579 15.579
Stats:
loop count : 101 loops
Error Range : 0.000 to 24.406 mS
Error Stddev : 5.009 mS
Error Average : 8.863 mS
sample rc=0
doit overall rc=0
```
This value is specific to Windows and to the PC that it is running on.
To make it more accurate for your PC and OS use the fixed_adjustment parameter.
Set it so the minimum and maximum are roughly symmetrical around 0.
The Stdev and Average error values at that point should be miminal.
```python
import accurate_timed_loop
loop_delay = 0.250 # seconds
total_wait = 25.0 # seconds
adj = 0.012200 # win mys2
for elapsed, start_time in accurate_timed_loop.accurate_wait(total_wait, loop_delay, fixed_adjustment=adj):
# ... do task every 250 mS
pass
```
Re-run this several times, and tweak the fixed adjustment.
This report shows that std deviation is much better.
```text
expected elapsed diff1(ms) actual(s) diff2(ms)
1 0.000000 0.000000 0.000 0.000000 0.000
2 0.250000 0.251537 1.537 0.251537 1.537
<snip>
101 25.000000 24.989502 -10.498 24.989502 -10.498
102 25.250000 25.241386 -8.614 25.241386 -8.614
Stats:
loop count : 102 loops
Error Range : -11.591 to 17.286 mS
Error Stddev : 3.933 mS
Error Average : 5.549 mS
sample rc=0
doit overall rc=0
```
Limitations:
* there is NO guarantee that the average error will always be that low or that consistent
```text
# === first run:
Stats:
loop count : 102 loops
Error Range : -11.591 to 17.286 mS
Error Stddev : 3.933 mS
Error Average : 5.549 mS
# === second run:
Stats:
loop count : 102 loops
Error Range : -11.897 to 11.435 mS
Error Stddev : 3.692 mS
Error Average : 5.380 mS
sample rc=0
doit overall rc=0
# === third run:
Stats:
loop count : 101 loops
Error Range : -11.626 to 18.453 mS
Error Stddev : 3.851 mS
Error Average : 4.527 mS
sample rc=0
doit overall rc=0
# === fourth run:
Stats:
loop count : 102 loops
Error Range : -11.851 to 15.891 mS
Error Stddev : 4.147 mS
Error Average : 5.072 mS
sample rc=0
doit overall rc=0
# === fifth run:
Stats:
loop count : 101 loops
Error Range : -11.251 to 6.205 mS
Error Stddev : 3.229 mS
Error Average : 4.704 mS
sample rc=0
doit overall rc=0
```
* the incoming "elapsed" parameter will not be after your expected delay.
For example these two came in:
* at 24.749 seconds instead of the expected 24.750 seconds
* at 24.999 seconds instead of the expected 25.000 seconds
```text
expected elapsed diff1(ms) actual(s) diff2(ms)
100 24.750000 24.749573 -0.427 24.749573 -0.427
101 25.000000 24.999601 -0.399 24.999601 -0.399
```
نحوه نصب
نصب پکیج whl accurate-timed-loop-0.0.14:
pip install accurate-timed-loop-0.0.14.whl
نصب پکیج tar.gz accurate-timed-loop-0.0.14:
pip install accurate-timed-loop-0.0.14.tar.gz