On Sun, 31 Jul 2016 10:32:18 -0700 (PDT),
jacksonist.lugi@gmail.com declaimed the
following:
my goal is to read serial data from an IMU that sends packets of data in a
high speed and make stabilization program for 2 motors.
it doesn't need it to be super fast, it needs to update at around 20-30
times a second tops.
You haven't specified the size of said packets, but at 20Hz, you've got
a full 50mSec between updates. For comparison, that is over two normal
time-slices for Windows 7 processes. The Linux scheduler seems to adjust
time-slices based on load and "nice" value:
Either way, if the process is blocking on I/O requests, there's
probably enough CPU available to handle it. At high speed serial
(115200bps, 8N1), you are looking at 5760 bits in a 50mSec window, or 576
bytes [start, 8bits, stop => 10 bits/byte]. I suspect your data is probably
closer to 50 bytes, so call it 5mSec to read... That gives you [using Win7
value] another 15mSec to process the data and generate output before
getting swapped out by the scheduler. Of course, if you are the only
process really doing anything, the odds are that the scheduler will just
bring you back into running state <G>
Since the low-level I/O, even from Python, is rather optimized (C
runtime library), I doubt it will be a concern.
def looper():
... strt = time.time()
... endt = strt + 0.050
... l = 0
... while time.time() < endt:
... l += 1
... print "Loops completed: %s" % l
...
looper()
Loops completed: 413376
That's on a 3.4GHz Win7 box.
Hmmm... the BBB seems a bit slower than I'd expected -- or time.time()
is returning greatly different units between Windows and the BBB
login as: debian
Debian GNU/Linux 7
BeagleBoard.org Debian Image 2015-11-12
Support/FAQ: Beagleboard:BeagleBoneBlack Debian - eLinux.org
default username:password is [debian:temppwd]
debian@beaglebone:~$ vim looper.py
debian@beaglebone:~$ python looper.py
Loops completed: 4131
Only 1% of the speed on the Win7 box?!
Seems consistent though... Adding some arithmetic...
def looper():
... strt = time.time()
... endt = strt + 0.050
... l = 0
... while time.time() < endt:
... l += 1
... _ = l * l
... print "Loops completed: %s" % l
...
looper()
Loops completed: 219002
vs
debian@beaglebone:~$ vim looper.py
debian@beaglebone:~$ python looper.py
Loops completed: 2406
I'd been thinking maybe 25% (1GHz 32-bit vs 3.4GHz 64-bit)... Floating
point may be killing it, since I don't think the BBB has double precision
hardware (could be wrong).