I'm running a Python script that controls a robot, but I'm a bit confounded as to how to multithread the motor control function.
The issue is that the hardware is designed such that the motors won't move unless there are several sleeps in the motor-control function, because the hardware requires time to send the electrical signals to the motors. Because of these sleeps in the motor-control function, the entire program halts and stops reading in sensor data.
What I would like to do is know how to multithread/multiprocess the motor-control function once it is called, but once the program hits the call again in the following iteration of the loop, it checks if the motor-control is still running (i.e. it isn't done with the sleep). If it is still running, it simply skips over the motor-control call and continues on with looping, reading sensor data, and then checking again if the motor-control function is still running. Of course, if the motor-control function is no longer running, I would like for it to once again be called.
Basically, the whole program only requires two threads: one that runs the main program, and one that branches off and continuously re-runs one instance of the motor-control function every time the motor-control function has completed its execution.
I had tried using the concurrent.futures import but got messages saying it was not supported and I couldn't find any usages particular to the way I intend to use it.