1
$\begingroup$

I am using arduino with FreeRTOS and a computer with patched xenomai linux. I am using python library called pyserial to communicate with arduino. Right now I am using simple servo motors. I want to be sure that whether the communication between the arduino and my main computer is real time or not.

How can I check this, properly. I want hard real time communication between arduino and computer for balancing robot.

$\endgroup$
3
  • $\begingroup$ Can you be more specific, what do you mean "real time"? are you talking about hard real time? or just fast? $\endgroup$
    – Mark Omo
    Commented Mar 18, 2017 at 20:54
  • $\begingroup$ well its hard real time actually what i'm trying to do. $\endgroup$
    – user14148
    Commented Mar 18, 2017 at 20:57
  • $\begingroup$ It seems to be missing here that the operation system needs to support hard real time too! A program can not plan what it does when if it does not even know when it is running at the time. $\endgroup$ Commented Apr 24, 2022 at 1:55

1 Answer 1

0
$\begingroup$

pyserial and more generally python is not suited to hard real time systems, as it was simply not designed for that application, due to duck typing and other runtime provisions cannot provide deterministic latency. Depending on what you want to do you can write all your hard real time subsystems in C or some other system that is suitable for hard realtime systems and then do data processing in the background in python.

You could test this behaviour by sending a byte, having pyserial read it and do some operation (say multiply them by 2) and spit the serial string back out. You could then probe the TX and RX lines on an oscilloscope and find the latency between the first byte in and the first byte out and I would guess that you would see a jitter of 1ms or more, in most hard real time systems I have worked with the jitter is below 10us (100 times less).

Though for a balancing robot you might find that that latency and jitter is acceptable, I would suggest you try it out and see how it works and if it does not work for you then move on to writing your code in a language that is suited for Hard Realtime.

$\endgroup$
4
  • $\begingroup$ I have read that pypy which is version of python can be used for real time purpose, is that true. If i have to use c/c++ for this purpose than how can pc communicate with arduino? Is their c++ library similar to pyserial? $\endgroup$
    – user14148
    Commented Mar 18, 2017 at 21:25
  • $\begingroup$ no as far as I know there is nothing that is still python that can support Hard RT, you essentially open serial ports as files in c see here, stackoverflow.com/questions/6947413 $\endgroup$
    – Mark Omo
    Commented Mar 18, 2017 at 21:42
  • $\begingroup$ So after using the c++ to communicate with the serial device i.e arduino this problem is solved right? $\endgroup$
    – user14148
    Commented Mar 18, 2017 at 21:46
  • $\begingroup$ Well "the problem is solved" might be a stretch, programming true Hard Real Time Systems is not easy or simple, but I would say that you will get much better performance out of well structured well written c++ code than python when you are talking about real time systems $\endgroup$
    – Mark Omo
    Commented Mar 18, 2017 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.