BrickPi controlling NXT motors as servos

Is there a way to use the BrickPi to control the NXT motor as a servo?

I’ve seen this thread, but has anything official been developed? Also, I prefer programming in Python for the BrickPi, but still please reply if there is a solution in other languages. Thanks for any help!

Good question. To answer your question yes there is. First let me give a little I do on the LEGO motors. You may know someone of this but I’d like to explain it to clear any confusion. In short they are continuous servos. This means they can turn in any direction indefinitely. Servos are basically motors with a bunch of gears and an encoder that tells the servos current position. With continuous servos they always start at position 0 or zero degrees. You should also use BP.offset_motor_encoder(BP.get_motor_encoder(port)) before moving the motor just to be sure. Anyways as stated previously it is at position zero. If I tell it to go to position 90 with BP.set_motor_position(port, 90)
That moves the motor to position 90. But what if you run it again? Try it. You’ll see that nothing happens because it is already at position 90. No if your offset the encoder again it and tell it to got to position 90 it will. However the proper way is just to tell it to go 180 degrees. Now try telling replacing the 90 with a zero. It should got backwards to the original position. Does this help? I would recommend reading the documentation​ for the BrickPi3. Just type pydoc brickpi3 in the terminal and use the arrow keys to skim through it. That will give you a general idea on what can be done with the BrickPi3. The documentation isn’t that long.

Please ask if you didn’t understamd​ my explanation.

1 Like

Thanks for the resource! But darn, I got the BrickPi+. While looking around again, I found some examples I missed in the examples folder for the BrickPi+ and I think I know how to use the motor encoders. This sensor example will measure the postion of the motor, and this sensor example can make your motors move using the motor encoders.

That’s ok. You can do all this on the BrickPi+! No worries.
for accessing the documentation its just pydoc brickpi
for moving the motor as a servo simply use motorRotateDegrees(power, degrees, port)
For more info on that function look at the sensor example:

To offset the encoder use BrickPi.offset_motor_encoder = BrickPi.encoder[port]