pxt-ev3/docs/reference/motors/motor/angle.md
Galen Nickel d8589ea98c Discussion note for gyro precsion (#317)
* Discussion note for gyro precsion

* Wrong sig
2018-02-08 15:06:08 -08:00

1016 B

angle

Get the current angle of the motor's rotation in degrees.

motors.largeA.angle()

When a motor is started for the first time, or after a reset, it's angle of rotation starts at 0 degrees. A complete rotation (a turn in a full circle) is 360 degrees. At 360 degrees, the motor angle doesn't go back to 0 but keeps counting in degrees. So, one and a half turns adds up to 540 degrees of total rotation.

Returns

  • a number which is the current angle of rotation for the motor.

Example

Reset the motor connected to port A and run it for for 2 seconds at a speed of 45. Stop and get the current angle of rotation.

let motorAngle = 0;
motors.largeA.reset()
motors.largeA.setSpeed(45)
loops.pause(2000)
motors.largeA.stop()
motorAngle = motors.largeA.angle()

See also

tacho, speed, reset, clear counts