Motor#
Introduction#
The Motor category includes blocks that control the behavior of motors and motor groups in a VEX IQ (2nd generation) robot. These blocks allow you to spin motors forward or in reverse, move to specific positions, set and read encoder values, and control speed, torque, and timeout settings.
Below is a list of available blocks:
spin – Spins the selected motor or motor group indefinitely.
spin for – Spins a motor or group for a specific distance in degrees or turns.
spin to position – Spins a motor or group to a set position.
stop motor – Stops a specific motor or group from spinning.
set motor velocity – Sets the speed of a motor or motor group as a percentage.
set motor position – Sets the encoder value of a motor or motor group.
set motor stopping – Defines the stop behavior (brake, coast, or hold).
set motor max torque – Limits the maximum torque the motor can apply.
set motor timeout – Limits how long a motor block waits before giving up if movement is blocked.
spin#
The spin block spins a selected motor or motor group in a specified direction using the current motor velocity.
spin [Motor1 v] [forward v]
Parameters |
Description |
---|---|
motor |
The motor or motor group to spin, configured in the Devices window. |
direction |
The direction to spin, configured in the Devices window. By default this is:
|
Example
when started :: hat events
[Spin the motor forward, then stop.]
spin [Motor1 v] [forward v]
wait (1) seconds
stop [Motor1 v]
spin for#
The spin for block spins a selected motor or motor group for a specific amount of rotation using the current motor velocity, measured in degrees or turns.
spin [Motor1 v] [forward v] for (90) [degrees v] ▶
Parameters |
Description |
---|---|
motor |
The motor or motor group to spin, configured in the Devices window. |
direction |
The direction to spin, configured in the Devices window. By default this is:
|
distance |
The rotation amount, as an integer or decimal. |
unit |
The measurement unit, which can be one of the following:
|
expanding arrow |
By default, this is a waiting block, so the drivetrain will finish moving before running the next block. To make the drivetrain start moving and immediately run the next block right away, expand the block to say and don’t wait. |
Example
when started :: hat events
[Spin the motor forward once, then reset.]
spin [Motor1 v] [forward v] for (90) [degrees v] ▶
spin [Motor1 v] [reverse v] for (90) [degrees v] ▶
spin to position#
The spin to position block spins a motor or motor group to a specific absolute position using the current motor velocity and motor position.
spin [Motor1 v] to position (90) [degrees v] ▶
Parameters |
Description |
---|---|
motor |
The motor or motor group to spin, configured in the Devices window. |
position |
The target position to spin the motor or motor group to. |
unit |
The measurement unit, which can be one of the following:
|
expanding arrow |
By default, this is a waiting block, so the drivetrain will finish moving before running the next block. To make the drivetrain start moving and immediately run the next block right away, expand the block to say and don’t wait. |
Example
when started :: hat events
[Spin the motor, then put the motor at half of a rotation.]
spin [Motor1 v] [forward v]
wait (2) seconds
spin [Motor1 v] to position (180) [degrees v] ▶
stop motor#
The stop motor block immediately stops the selected motor or motor group.
stop [Motor1 v]
Parameters |
Description |
---|---|
motor |
The motor or motor group to stop, configured in the Devices window. |
Example
when started :: hat events
[Stop the motor after 1 second.]
spin [Motor1 v] [forward v]
wait (1) seconds
stop [Motor1 v]
set motor position#
The set motor position block sets a specific position value to a motor or motor group, which updates the encoder reading.
set [Motor1 v] position to (0) [degrees v]
Parameters |
Description |
---|---|
motor |
The motor or motor group to set the position of, configured in the Devices window. |
position |
The encoder position value to set. |
unit |
The measurement unit, which can be one of the following:
|
Example
when started :: hat events
[Spin the motor in reverse.]
set [Motor1 v] position to (180) [degrees v]
spin [Motor1 v] to position (0) [degrees v] ▶
set motor velocity#
The set motor velocity block sets the default spinning speed of a motor or motor group as a percentage for all subsequent Motor blocks in the project.
set [Motor1 v] velocity to (50) [% v]
Parameters |
Description |
---|---|
motor |
The motor or motor group to set the velocity of, configured in the Devices window. |
velocity |
Sets the default movement velocity from 0 to 100 as a percent. |
unit |
The measurement unit, which can be one of the following:
|
Example
when started :: hat events
[Spin forward at the default velocity.]
spin [Motor1 v] [forward v] for (90) [turns v] ▶
[Spin slower.]
set [Motor1 v] velocity to (20) [% v]
spin [Motor1 v] [reverse v] for (90) [turns v] ▶
[Spin faster.]
set [Motor1 v] velocity to (100) [% v]
spin [Motor1 v] [forward v] for (90) [turns v] ▶
set motor stopping#
The set motor stopping block sets how a motor or motor group behaves when it stops.
set [Motor1 v] stopping to [brake v]
Parameters |
Description |
---|---|
motor |
The motor or motor group to set the stopping behavior of, configured in the Devices window. |
stopping behavior |
Sets how the drivetrain stops, which can be one of the following:
|
Example
when started :: hat events
[Spin the motor, then coast to a stop.]
set [Motor1 v] velocity to (100) [% v]
set [Motor1 v] stopping to [coast v]
spin [Motor1 v] [forward v]
wait (2) seconds
stop [Motor1 v]
set motor max torque#
The set motor max torque block sets how much force a motor or motor group can exert.
set [Motor1 v] max torque to (50) %
Parameters |
Description |
---|---|
motor |
The motor or motor group to set the max torque of, configured in the Devices window. |
torque |
The maximum torque allowed, from 0 to 100 as a percent. |
Example
when started :: hat events
[Spin the motor at the default torque.]
spin [Motor1 v] to position (200) [degrees v] ▶
wait(0.5) seconds
[Spin at a lower torque.]
set [Motor1 v] max torque to (20) %
spin [Motor1 v] to position (0) [degrees v] ▶
wait (0.5) seconds
[Spin at the maximum torque.]
set [Motor1 v] max torque to (100) %
spin [Motor1 v] to position (200) [degrees v] ▶
set motor timeout#
The set motor timeout block sets a time limit for how long a Motor block will wait to reach its target. If the robot cannot complete the movement within the set time, it will stop automatically and continue with the next block.
Note: The Motor’s time limit is used to prevent Motor blocks that do not reach their target position from stopping the execution of other blocks in the stack.
set [Motor1 v] timeout to (1) seconds
Parameters |
Description |
---|---|
motor |
The motor or motor group to set the timeout of, configured in the Devices window. |
time |
The maximum number of seconds a Motor block will run before stopping and moving to the next block. |
Example
when started :: hat events
[Spin the motor forward for 1 second, then reset it.]
set [Motor1 v] timeout to (1) seconds
spin [Motor1 v] [forward v] for (5) [turns v] ▶
spin [Motor1 v] to position (0) [degrees v] ▶