is pyserial hard real time

Hello sir, i want to use arduino as a bridge which connects my main xenomial patched computer and some actuators and sensors. I want to know whether the communication between pc and arduino using pyserial is hard real time or not. I want a real time communication because the robot has to balance itself while walking, which requires very accurate control of the actuators. Or do i have to go for pypy for this purpose.

No communication between a PC and an Arduino using a USB cable or wireless link will be adequate to provide direct control for a robot. There will be too much latency in the communication. In the old days when a PC had a parallel printer port what you are thinking of may have been possible.

Your Arduino code needs to operate autonomously to balance the robot and implement occasional commands from the the PC to move forward, stop, turn left etc.

This Python - Arduino demo may be helpful. I believe the code will work on Windows if you modify the serial port references.

...R

Well what about using serial port i.e usb to serial converter + real time clock with arduino? After this is the task possible?
If no is their any way which i can make arduino communicate with my pc, so that it only acts like a bridge? If not, which board should i go for?

dineshlama:
Well what about using serial port i.e usb to serial converter + real time clock with arduino? After this is the task possible?
If no is their any way which i can make arduino communicate with my pc, so that it only acts like a bridge? If not, which board should i go for?

That does not make sense to me in the context of your Original Post. You need to explain more clearly what you are thinking of - I suspect the concept in your head is very different from what is in my head and it will be difficult to communicate effectively unless we get to a common understanding.

Of course you can communicate with an Arduino over a USB cable - that is the basis of the code in the link I posted earlier. But I have no idea what you plan to use the RTC for. And what do you mean by "only acts like a bridge"

My understanding, from your Original Post, is that you want the PC (rather than the Arduino) to control the balance of the robot - and IMHO that is not possible. However the Arduino can easily do it.

...R

well i have posted this question in here also: ros - Is it possible to use an arduino in hard real time - Robotics Stack Exchange, so what my main requirment is that; i am currentely running xenomial patched linux along with ros and orocos for computer vision and motion planning purpose. So my main computer will be running the computer vision node and it will also plan the motion for the robot arms. So in this way all the high level tasks are running in the man computer. Now what i want is to send the low level commands to actuators and read from sensors in real time. Somebody suggested me that i sould use RTOS in arduino, somebody told me that u have to first use RTOS in your own computer first to achive real time performance(which i am using the xenomai patched linux for that along with orocos library for motion planning).

So the part "only acts like a bridge" means, i want to use arduino just as a device which helps my main computer to communicate with actuators and sensors like encoders(to know the joint position), torque sensor etc. The arduino will just read the sensors data and than pass the values to the main computer running RTOS which than again sends some values to actuators through the arduino or first arduino will calculate the position by reading encoder than send the result through serial command i.e "serial.print("result")."

As i've seen pyserial or pypy can be used for this purpose, but i want to know how can i make it real time, means the communication between actuators/sensors or arduino board and main computer has to be very fast. Why do i need it is because to balance a robot in one leg while walking or running or jumping the robot joints has to be controlled very accurately and the encoder values or say the positon of those joints also has to be read very accurately and of course at very fast speed, else even small error can make the robot fall to ground or damage something(if robot is using powerful actuators).

After i use freeRTOS on arduino, will the arduino and my main computer communicate in real time?

dineshlama:
So the part "only acts like a bridge" means, i want to use arduino just as a device which helps my main computer to communicate with actuators and sensors like encoders(to know the joint position), torque sensor etc. The arduino will just read the sensors data and than pass the values to the main computer running RTOS which than again sends some values to actuators through the arduino

That is certainly clearer and it is what I thought you had in mind. Sorry. It won't work.

As i've seen pyserial or pypy can be used for this purpose, but i want to know how can i make it real time, means the communication between actuators/sensors or arduino board and main computer has to be very fast. Why do i need it is because to balance a robot in one leg while walking or running or jumping the robot joints has to be controlled very accurately and the encoder values or say the positon of those joints also has to be read very accurately and of course at very fast speed, else even small error can make the robot fall to ground or damage something(if robot is using powerful actuators).

And the reason it won't work is because you cannot be certain that the data will transfer at the exact moment that it is needed. It is not a question of the speed of data throughput - at (say) 500,000 baud it would probably be fast enough. The problem is that there may be a delay (due to the USB system or any wireless system) before the transmission of a particular message is started. The reason people use Arduinos (and their equivalents) for time critical tasks is precisely because they don't hav an operating system that can be side-tracked by another task at a critical moment.

There is a relatively simple solution - offload the time-critical tasks to the Arduino and just use the PC to send it high level commands such as turn-left or stop which won't be affected by a delay of a few millisecs. This process of splitting the tasks is in widespread use.

...R

Sir can u suggest me any other way to control the hardware in hard real time i.e at exact time without any error. Should i go for any other microcontroller, embedded device? Or should i run hole the high level and low level programs in the single computer only like jetson tk1 or odroid xu4? Can if their is any delay or error in sending the command at exact time u know the robot will not balance itself and fall on ground, or can do any movement task.

dineshlama:
Sir can u suggest me any other way to control the hardware in hard real time i.e at exact time without any error.

I'm not sure what you are asking.

Are you rejecting my suggestion to off-load the real-time control to the Arduino? If so, I don't understand why you would reject it? (An Arduino is ideal for real-time stuff). Maybe if you can explain that I will be better able to help.

And if you are not rejecting that suggestion then it provides the solution you need.

...R

ok i didn't noticed that off loading part. Thanks, u solved my problem.

dineshlama:
ok i didn't noticed that off loading part. Thanks, u solved my problem.

I did first mention it in Reply #1 :slight_smile:

...R