Saccade motor moves

I have an issue concenring pypot which never appear before :

I execute the code below :

import pypot.robot
import time
from numpy import *


robot = pypot.robot.from_json("full_poppy.json")

t0 = time.time()
while True:
    robot.r_elbow_y.goal_position = sin(time.time()-t0)*20-20
    robot.r_elbow_y.compliant = False

I obtain saccaded moves (one position every 3 or 4 seconds)

But when when I do this :

import pypot.robot
import time
from numpy import *


robot = pypot.robot.from_json("full_poppy.json")

t0 = time.time()
while True:
    robot.r_elbow_y.goal_position = sin(time.time()-t0)*20-20
    robot.r_elbow_y.compliant = False
    print 1

it works very well.

It is like an issue about task priority…
Have you ever seen this ?

When you execute this code:

The loop will be executed very fast (more than 100k requests per seconds on my computer). The robot is overflooded and cannot follow thes commands.
When you add a “print 1”, the consol output slow a lot the inner loop, it’ll will work a bit better.
The best is to add a time.sleep(0.05) in the loop.

This one is a bit tricky @Thot!

To continue en @Theo answer, I think what is actually happening is as your while loop will run at an extremely high frequency (nothing inside it should take more than a few µs), the scheduler will never have the opportunity to switch to another thread as the synchronisation thread for instance. Thus, you order will actually be never sent to the robot. The print that you are using in the second example as it is making a sys call, gives the scheduler an opportunity to switch to another thread.

I’m actually pretty sure that the behaviour of your program will vary a lot depending on the OS you are using. Nevertheless, it’s never a good idea to have such tight loop in your program it will use 100% CPU doing nothing. In your case having this loop run at more than 50Hz will not have any effect as the synchronisation loop are running at 50Hz.

Thanks for your answer, it is the solution. I did not understand since I ran the script on windows, and all was OK…
So now I understand it is not an issue on the ODROID.
Nevertheless I have another issue, I open a new subject for this.

I tested on Linux replaciing print by time.sleep(0.001)… Ca marche super bien !!

:grinning: