In this tutorial, you will learn how to rotate a motor to an exact angle using a simple command. This allows you to control your robot more precisely without tracking its previous movements. It’s especially useful when your program becomes longer and more complex.
To access the full video please subscribe to FLLCasts.com
- #2604
- 24 Mar 2026
To solve this tracking issue, we use a command that always moves the motor to a specific angle.
motor.run_to_absolute_position(port, position, velocity)
- port – which motor (e.g., port.A)
- position – the target angle (in degrees)
- velocity – speed in degrees per second
Example:
from hub import port import motor import runloop async def main(): motor.run_to_absolute_position(port.A, 90, 1000) runloop.run(main())
This program turns motor A to 90 degrees with a speed of 1000 deg/s. The direction of the motor is automatic. The robot chooses the direction in which the motor will reach its target angle fastest and turns it that way.
Chosing the direction
If you need to turn the motor in a specific direction, you can use the optional parameter for direction.
Example:
from hub import port import motor import runloop async def main(): motor.run_to_absolute_position(port.A, 90, 1000, direction = motor.CLOCKWISE) runloop.run(main())
This program turns motor A to 90 degrees with a speed of 1000 deg/s in the clockwise direction.
You can set the direction like in 4 different ways:
- motor.CLOCKWISE
- motor.COUNTERCLOCKWISE
- motor.SHORTEST_PATH
- motor.LONGEST_PATH