pxt-ev3/docs/reference/motors/motor/angle.md
Galen Nickel 88c58b4e76 First set of 'motors' topics (#305)
* Start of 'motors' topics

* Draft the 'motor motion' side doc

* Add / update more topics

* Last blast of edits

* Capture some more edits

* Put in movement and steering details
2018-02-06 19:43:50 -08:00

1.1 KiB

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 gets set back to 0. So, one and a half turns adds up to 540 degrees of total rotation but the motor only cares about the current angle from 0 degrees which is 180 degrees.

Returns

  • a number which is the current angle of rotation for the motor. The value returned is the number of degrees from 0 to 359.

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