Pyserial / python and real-time data collection

I have an infrared camera / tracker that I communicate with through the serial port. I am using the pyserial module to do this at the moment. The camera updates the position of the tracked object at a speed of 60 Hz. To get the position of the tracked object, I execute one pyserial.write () and then listen for the incoming response using pyserial.read (serialObj.inWaiting ()). As soon as the response / position is received, the while loop is introduced again and so on. My question is related to the reliability and speed of this approach. I need a position that a computer should get at a speed of at least 60 Hz (and then the position will be sent via UDP in real-time OS). Is this something that Pyserial / Python is capable of or should I look for alternative C-based approaches?

Thanks Luke

+5
source share
3 answers

Python should be fine, but it's best to keep track of how much you read per second. Count how many times a reading has been read every second, and if that number is too low, write in a performance log or similar. You should also consider disconnecting some of the I / O from the rest of your python program (if any), since read locks are blocked using pyserial.

0
source

This is more of a delay than speed.

Python always allocates and frees memory, but if the data is reused, the same memory will be reused by the C library. Thus, the OS (C / UDP / IP stack library) will have a greater impact than Python itself.

, RTOS C- .

+1

I would suspect that Python will keep track of the data well. My advice would be to try it, and if Python turns out to be lagging around, try PyPy instead - a Python implementation that will compile most of your internal loops to machine code for speeds close to C.

http://pypy.org/

0
source

All Articles