ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
431 stars 145 forks source link

Read angle of the current motor #674

Closed JohnHZheng closed 4 years ago

JohnHZheng commented 5 years ago

We are now using Python 3. One question is that the LEGO EV3 MicroPython document has class Motor that read angle. The document reads: Methods for motors with rotation sensors angle() Get the rotation angle of the motor. Returns Motor angle. Return type angle: deg reset_angle(angle) Reset the accumulated rotation angle of the motor. Parameters angle (angle: deg) – Value to which the angle should be reset.

How do we get the same information using Python 3? Thank you

WasabiFan commented 5 years ago

Motor.position should do it. It returns encoder pulses, so you can divide by Motor.count_per_rot to get fractions of rotations.

If you want degrees:

my_motor.position * (360 / my_motor.count_per_rot)
JohnHZheng commented 5 years ago

thank you very much