does the argument for sys.sleep() can be a fraction i.e .001 for a millisecond sleep? Is there any other way to give a thread a deterministic execution time; if no pause is given what is the chunk of time that thread runs before another one is scheduled?
vex.sleep() is available but not documented - any particular reason?
Yes, sys.sleep() can take fractions, e.g.
sys.sleep(0.01) #one hundredth of a second
I think the timing is accurate to 1 ms
As for how our threading works in-depth, I should be putting up some documents on that within the week.
To answer this particular question, we use a preemptive scheduler for all our languages. We don’t expose many threading tools in the Python API, so you will be rather at the mercy of the scheduler in Python and Blockly. The best way to have a more deterministic execution time in Python would probably be to only have a single thread. Though I am curious as to what you’re trying to accomplish that needs such a strict execution time?
I was looking into implementing a PID control where both the motors are controlled by a separate thread. 1s sleep would be too coarse- so having the millisec fraction helps. The setpoint would be in the main navigation thread and the actual command going to the motors would come from the two threads controlling them. Of course, same can be achieved in a single thread too, multi-threaded design seemed cleaner. Preemptive helps since two threads running in an infinite loop without sleep will not block each other- and I was just not sure if the argument for sleep was necessarily int or a float will do. That was clarified in this thread. Determinism of the order of a few millisecs should be ok for a system like this for most conceivable use cases