В момента ресурсът е наличен само на английски

How to rotate a motor to an exact angle with LEGO SPIKE Pro Preview

In this tutorial, you will learn how to rotate a motor to an exact angle using a simple command. This helps you control your robot more precisely without keeping track of its previous movements. It is especially useful when your program becomes longer and more complex.

Необходимо е да се абонирате за FLLCasts.com, за да достъпите това видео

Абонирай се

  • #2604
  • 24 Mar 2026

To solve this tracking problem, we use a command that always moves the motor to a specific angle.

motor.run_to_absolute_position(port, position, velocity)
  • port – the motor to control (for example, port.A)
  • position – the target angle in degrees
  • velocity – the 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 at a speed of 1000 deg/s. The motor's direction is chosen automatically. The robot selects the direction that allows the motor to reach its target angle the fastest and rotates it that way.

Choosing the direction

If you need the motor to rotate in a specific direction, you can use the optional direction parameter.

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 at a speed of 1000 deg/s in the clockwise direction.

You can set the direction in four different ways:

  • motor.CLOCKWISE
  • motor.COUNTERCLOCKWISE
  • motor.SHORTEST_PATH
  • motor.LONGEST_PATH

Курсове и занятия включващи този Урок

Този Урок е използван в следните курсове и занятия.

Image for Level A: Python Foundations – Robotics with LEGO SPIKE Prime
  • 46
  • 4:32
  • 78
Image for Lesson 6 - Steering an Unmanned Vehicle
  • 2
  • 7
  • 15
  • 3d_rotation 1