Asynchronous rotation of motor? Don't wait

Hi there!

I’m using python to program my BrickPi.

I’m rotating the motor by 90 degrees by using set_motor_position(). After it’s finished I want to let the motor rotate freely, so I call BP.set_motor_power(BP.PORT_A, BP.MOTOR_FLOAT). The problem is that I have to wait with time.sleep(0.5) until the motor finishes the movement and in the meantime I can’t log or use it’s sensor value which would be really important for my use-case.

Is there a way to make the motor rotate asynchronously so in the meantime I can do other things in the program?

Thanks for the help!

1 Like


I am sure your problem has a reasonable solution buried in the libraries somewhere.

I’m not that much of an expert here, but I’ll ping both @cyclicalobsessive and @cleoqc, the two people who probably know more about these libraries than anyone else I know.

Hopefully they can she’d some light here.

(@jimrh: I try to leave the “non-GoPiGo3” questions to non-GoPiGo3 folk. )

@barnabash, you need to inspect all the motor methods in the There are several methods of commanding the motors to turn or to turn to a position, and there are methods to tell when the position is reached.

Thanks for the answers!

I am familiar with the motor methods but they were not covering this scenario.

I ended up using multithreading where I initiate the movement of the motor, then wait for half a second, then let it rotate freely again. In the meantime on the other thread I’m streaming the sensor value and logging it to the local file as well.

I used python’s built in threading

1 Like