Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyserial/python and real time data acquisition

I have an infrared camera/tracker with which I am communicating via the serial port. I'm using the pyserial module to do this at the moment. The camera updates the position of a tracked object at the rate of 60 Hz. In order to get the position of the tracked object I execute one pyserial.write() and then listen for an incoming reply with pyserial.read(serialObj.inWaiting()). Once the reply/position has been received the while loop is reentered and so on. My question has to do with the reliability and speed of this approach. I need the position to be gotten by the computer at the rate of at least 60Hz (and the position will then be sent via UDP to a real-time OS). Is this something that Pyserial/Python are capable of or should I look into alternative C-based approaches?

Thanks, Luke

like image 268
dataman Avatar asked Nov 14 '22 16:11

dataman


1 Answers

This is more a matter of latency than speed.

Python always performs memory allocation and release, but if the data is reused, the same memory will be reused by the C library. So the OS (C library / UDP/IP stack) will have more impact than Python itself.

I really think you should use a serial port on your RTOS machine and use C code and pre-allocated buffers.

like image 170
cJ Zougloub Avatar answered Dec 17 '22 00:12

cJ Zougloub