How to rotate the motors to an exact angle Pro Preview

When we use the run_angle() command several times in the program, it's hard to follow how many rotations the motor has made in order to set it to the proper turning angle for it to reach its next target. Which is why we also have a command known as run_target.

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #1557
  • 11 Mar 2020

This command has 4 input parameters:

  1. The speed at which the motor turns;
  2. The angle which the motor has to reach;
  3. What type of brake the motor should use;
  4. Should the program wait for the command to complete its action or not.

With this command, you don't even need a positive or negative speed value. It will choose the proper direction on its own in order to reach the target angle.

Here's an example of how the robot can be programmed to turn one motor to 90 degrees with a speed of 360:

Motor(Port.B).run_angle(360, 90, Stop.COAST)

Here's the same example with a speed of -360:

Motor(Port.B).run_angle(-360, 90, Stop.COAST)

These two programs do the same thing! If this is the first line in the program and the motor is in starting position it will turn to 90 degrees in its positive direction regardless of whether the speed is 360 or -360. This is because the robot is programmed to understand that the angle will not increment if the motor moves in the opposite direction.

If the motor has turned to 200 degrees before one of these commands is called, the motor will turn backward by 110 degrees so it can reach its target of 90 degrees. This command measures the angle to which the motor is turned after the start of the program.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Python with LEGO Mindstorms EV3 - Level 1
  • 74
  • 28:18
  • 114
Image for Lesson 6 - Steering an Unmanned Vehicle
  • 3
  • 7
  • 5
  • 3d_rotation 1