Motion#

Introduction#

Motors control how parts of a robot move. Motors can be used to raise an arm, turn a claw, spin a wheel, or move another part of a build. Two motors can work together as a drivetrain to move and turn the whole robot.

Each motor is configured in the Devices window. Depending on the build, the names of the motors and directions can change. For example, the Competition Advanced 2.0 build has a motor named ArmMotor, with directions up and down. A custom robot may use different motor names or directions.

By default, forward spins a motor counterclockwise, and reverse spins a motor clockwise. If a motor is set to reverse in the Devices window, those directions will be switched.

A VEX GO Motor showing the forward direction indicated by a plus sign and an arrow indicating it is rotating left, or counterclockwise. A VEX GO Motor showing the reverse direction indicated by a minus sign and an arrow indicating it is rotating right, or clockwise.

There are many ways to code motors. Below is a list of all Motion blocks:

Actions — Stop and spin motors.

Settings — Adjust motor settings.

Values — Check motor status.

  • motor is done — Reports whether the motor is finished moving.

  • motor is spinning? — Reports whether the motor is spinning.

  • motor position — Reports the motor’s current position.

  • motor velocity — Reports how fast the motor is spinning, as a percentage from -100% to 100%.

  • motor current — Reports how much power the motor is using from the battery, as a percentage from 0% to 100%.

Actions#

spin motor#

The spin motor stack block spins a motor forward or reverse forever. The motor will continue to spin until it is given another action, like spinning in a different direction or stopping.

    spin [ArmMotor v] [up v]

Parameters

Description

motor

The motor to spin. Choose from the motors configured in the Devices window.

direction

The direction the motor spins. By default, the choices are forward and reverse. Direction choices can change depending on the motor’s configuration.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Raise the ArmMotor, then stop.]
  spin [ArmMotor v] [up v]
  wait [1] seconds
  stop [ArmMotor v]

spin motor for#

The spin motor for stack block spins a motor for a specific distance. The spin is relative to the current position of the motor. The project will wait until the motor is done spinning before the next block in the stack runs.

    spin [ArmMotor v] [up v] for [90] [degrees v] ▶

Parameters

Description

motor

The motor to spin. Choose from the motors configured in the Devices window.

direction

The direction the motor spins. By default, the choices are forward and reverse. Direction choices can change depending on the motor’s configuration.

distance

The distance the motor spins. Degrees use integers. Turns can use integers or decimals.

unit

The distance unit: degrees or turns.

and don’t wait

Select the arrow ( ▶ ) to expand the block to say and don’t wait, so the next block in the stack will run right away.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Raise and lower the ArmMotor.]
  spin [ArmMotor v] [up v] for [180] [degrees v] ▶
  wait [1] seconds
  spin [ArmMotor v] [down v] for [180] [degrees v] ▶

spin motor to position#

The spin motor to position stack block spins a motor to a specific position.

A motor’s position is how far it has spun, measured in degrees or turns. One turn is equal to 360 degrees. At the beginning of a project, the motor position is set to 0 degrees. The motor position can also be set using the set motor position block.

Position values are absolute. This means the direction of the spin depends on the motor’s current position.

    spin [ArmMotor v] to position (90) [degrees v] ▶

Parameters

Description

motor

The motor to spin. Choose from the motors configured in the Devices window.

position

The position value the motor will spin to. Degrees use integers. Turns can use integers or decimals.

unit

The position unit: degrees or turns.

and don’t wait

Select the arrow ( ▶ ) to expand the block to say and don’t wait, so the next block in the stack will run right away.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Return ArmMotor to 0 degrees after raising.]
  spin [ArmMotor v] [up v] for [180] [degrees v] ▶
  wait [1] seconds
  spin [ArmMotor v] to position [0] [degrees v] ▶

stop motor#

The stop motor stack block stops a motor from spinning.

    stop [ArmMotor v]

Parameters

Description

motor

The motor to stop. Choose from the motors configured in the Devices window.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Raise the ArmMotor.]
  spin [ArmMotor v] [up v]
  wait [1] seconds
  stop [ArmMotor v]

Settings#

set motor position#

A motor’s position is how far it has spun, measured in degrees or turns. One turn is equal to 360 degrees. The set motor position stack block changes the motor’s current position to a new value.

For example, if a motor has spun to 180 degrees, setting the position to 0 degrees will reset that position from 180 to 0 degrees. Then the motor can spin to positions based on that new value.

    set [ArmMotor v] position to (0) [degrees v]

Parameters

Description

motor

The motor to set the position for. Choose from the motors configured in the Devices window.

position

The position value to set for the motor. Degrees use integers. Turns can use integers or decimals.

unit

The position unit: degrees or turns.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Return ArmMotor to 0 degrees after raising.]
  set [ArmMotor v] position to [0] [degrees v]
  spin [ArmMotor v] [up v] for [180] [degrees v] ▶
  wait [1] seconds
  spin [ArmMotor v] to position [0] [degrees v] ▶

set motor velocity#

The set motor velocity stack block tells a motor how fast to spin. A higher percentage makes the motor spin faster and a lower percentage makes the motor spin slower.

Every project begins with each motor spinning at 50% velocity by default.

Note: A higher velocity makes the motor spin faster, but it may be less precise. A lower velocity makes the motor spin slower, but it can be more precise.

    set [ArmMotor v] velocity to [50] %

Parameters

Description

motor

The motor to set the velocity for. Choose from the motors configured in the Devices window.

velocity

The velocity to spin with from 0% to 100%.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Move the ArmMotor at different velocities.]
  spin [ArmMotor v] [up v] for [180] [degrees v] ▶
  wait [1] seconds
  [Move slow.]
  set [ArmMotor v] velocity to [20] %
  spin [ArmMotor v] [down v] for [180] [degrees v] ▶
  wait [1] seconds
  [Move fast.]  
  set [ArmMotor v] velocity to [100] %
  spin [ArmMotor v] [up v] for [180] [degrees v] ▶

set motor stopping#

The set motor stopping stack block sets how a motor will stop moving: by braking, coasting, or holding.

    set [ArmMotor v] stopping to [brake v]

Parameters

Description

motor

The motor to set the stopping behavior for. Choose from the motors configured in the Devices window.

stopping behavior

How the motor will stop:

  • brake — Stops immediately.
  • coast — Slows to a stop.
  • hold — Stops immediately and holds the motor’s position.

For example, if a Competition Advanced 2.0 build is used and ArmMotor is set to hold, the motor will hold the arm at its current position until another arm movement happens. This means the motor will work against gravity to keep the arm in the air if the motor was stopped with the arm raised.

If this block is not used, the motor will use brake when stopping.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Move the ArmMotor, then coast to a stop.]
  set [ArmMotor v] velocity to [20] %
  set [ArmMotor v] stopping to [coast v]
  spin [ArmMotor v] [up v]
  wait [1] seconds
  stop [ArmMotor v]

set motor max torque#

Torque is a turning force. It shows how hard a motor can push or pull when it spins.

The set motor max torque stack block sets the most torque a motor is allowed to use.

A higher percentage lets the motor push harder, like when lifting a heavy object. A lower percentage limits how hard the motor can push. This can help protect the robot if the motor gets stuck or reaches the end of how far it can move.

Every project begins with each motor’s torque at 50% by default.

    set [ArmMotor v] max torque to (50)%

Parameters

Description

motor

The motor to set the max torque for. Choose from the motors configured in the Devices window.

torque

The max torque the motor can use from 0% to 100%.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Move the ArmMotor at different torques.]
  spin [ArmMotor v] [up v] for [180] [degrees v] ▶
  wait [1] seconds
  [Move with less torque.]
  set [ArmMotor v] max torque to [20] %
  spin [ArmMotor v] [down v] for [180] [degrees v] ▶
  wait [1] seconds
  [Move with maximum torque.]  
  set [ArmMotor v] max torque to [100] %
  spin [ArmMotor v] [up v] for [180] [degrees v] ▶

set motor timeout#

The set motor timeout stack block sets how many seconds a motor will try to finish a movement. If the motor cannot finish in that time, it will stop trying and move on to the next block in the stack. This keeps the motor from getting stuck on a movement.

    set [ArmMotor v] timeout to (1) seconds

Parameters

Description

motor

The motor to set the timeout for. Choose from the motors configured in the Devices window.

time

The number of seconds the motor can try to finish a movement. This can be a whole number or a decimal.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Move ArmMotor as far as possible for 1 second before resetting.]
  set [ArmMotor v] position to [0] [degrees v]
  set [ArmMotor v] timeout to [1] seconds
  spin [ArmMotor v] [up v] for [180] [degrees v] ▶
  spin [ArmMotor v] to position [0] [degrees v] ▶

Values#

motor is done?#

The motor is done Boolean block reports whether the motor is finished moving. This can be used to control the timing of other behaviors based on the motor’s movement.

  • True — The motor is finished moving.

  • False — The motor is still moving.

This block works together with the following Motion blocks that have the and don’t wait parameter: spin motor for and spin motor to position.

    <[ArmMotor v] is done?>

Parameters

Description

motor

The motor to report whether it is finished moving. Choose from the motors configured in the Devices window.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Turn the Eye Sensor's light on while ArmMotor is moving.]
  spin [ArmMotor v] [up v] for [180] [degrees v] ◀ and don't wait
  wait [0.1] seconds
  forever
  if <[ArmMotor v] is done?> then
  set eye light [off v]
  else
  set eye light [on v]

motor is spinning?#

The motor is spinning? Boolean block reports whether the motor is spinning. This can be used to control the timing of other behaviors based on the motor’s movement.

  • True — The motor is spinning.

  • False — The motor is not spinning.

This block works together with the following Motion blocks that have the and don’t wait parameter: spin motor for and spin motor to position.

    <[ArmMotor v] is spinning?>

Parameters

Description

motor

The motor to report whether it is spinning. Choose from the motors configured in the Devices window.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Turn the Eye Sensor's light on while ArmMotor is moving.]
  spin [ArmMotor v] [up v] for [180] [degrees v] ◀ and don't wait
  wait [0.1] seconds
  forever
  if <[ArmMotor v] is spinning?> then
  set eye light [on v]
  else
  set eye light [off v]

motor position#

A motor’s position is how far it has spun, measured in degrees or turns. The motor position reporter block reports the motor’s current position.

At the beginning of a project, the motor position is set to 0 degrees. If the motor spins one full turn forward, the position will be 360 degrees or 1 turn. If the motor spins the other direction, the position will be negative.

    ([ArmMotor v] position in [degrees v] :: custom-motion)

Parameters

Description

motor

The motor to report the position of. Choose from the motors configured in the Devices window.

unit

The unit to report the motor position in: degrees or turns.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Display how far the ArmMotor moves after one second.]
  set [ArmMotor v] position to [0] [degrees v]
  print [Start: ] ▶
  print ([ArmMotor v] position in [degrees v] :: custom-motion) ▶
  set cursor to next row
  spin [ArmMotor v] [up v]
  wait [1] seconds
  stop [ArmMotor v]
  print [After: ] ▶
  print ([ArmMotor v] position in [degrees v] :: custom-motion) ▶

motor velocity#

The motor velocity reporter block reports how fast the motor is spinning, as a percentage from -100% to 100%.

A positive value means the motor is spinning forward. A negative value means the motor is spinning in reverse.

    ([ArmMotor v] velocity in %)

Parameters

Description

motor

The motor to report the velocity of. Choose from the motors configured in the Devices window.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Display the ArmMotor's velocity when it moves.]
  print [Resting: ] ▶
  print ([ArmMotor v] velocity in %) ▶
  set cursor to next row
  spin [ArmMotor v] [up v]
  wait [1] seconds
  print [Moving: ] ▶
  print ([ArmMotor v] velocity in %) ▶
  stop [ArmMotor v]

motor current#

The motor current reporter block reports how much power the motor is using from the battery, as a percentage from 0% to 100%.

A higher current value means the motor is using more power. This can happen when the motor is lifting something heavy, pushing against an object, or trying to move when it is stuck.

    ([ArmMotor v] current in %)

Parameters

Description

motor

The motor to report the current of. Choose from the motors configured in the Devices window.

Example

  when started :: hat events
  [Build Used: Competition Advanced 2.0]
  [Display the motor's current when it moves.]
  print [Resting: ] ▶
  print ([ArmMotor v] current in %) ▶
  set cursor to next row
  spin [ArmMotor v] [up v]
  wait [1] seconds
  print [Moving: ] ▶
  print ([ArmMotor v] current in %) ▶
  stop [ArmMotor v]