Motors and Motor Groups#
Introduction#
Motors and motor groups control how parts of a robot move. A motor controls one configured Smart Motor, while a motor group controls two configured Smart Motors together so they move in tandem. Motors and motor groups 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. 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.
There are many ways to code motors and motor groups. Below is a list of all Motors and Motor Groups blocks:
Actions — Stop and spin motors and motor groups.
spin motor — Spins a motor or motor group forward or reverse forever.
spin motor for — Spins a motor or motor group for a specific distance.
spin motor to position — Spins a motor or motor group to a specific position.
stop motor — Stops a motor or motor group from spinning.
Settings — Adjust motor and motor group settings.
set motor position — Changes the motor or motor group’s current position to a new value.
set motor velocity — Tells a motor or motor group how fast to spin.
set motor stopping — Sets how a motor or motor group will stop moving: by braking, coasting, or holding.
set motor max torque — Sets how hard a motor or motor group is allowed to push while spinning.
set motor timeout — Sets how many seconds a motor or motor group will try to finish a movement.
Values — Check motor and motor group status.
motor is done — Reports whether the motor or motor group is finished moving.
motor is spinning — Reports whether the motor or motor group is spinning.
motor position — Reports the motor or motor group’s current position.
motor velocity — Reports how fast the motor or motor group is spinning.
motor current — Reports how much electrical current the motor or motor group is using.
Actions#
spin motor#
The spin motor stack block spins a motor or motor group forward or reverse forever. The motor or motor group will continue to spin until it is given another action, like spinning in a different direction or stopping.
spin [Motor1 v] [forward v]
Parameters |
Description |
|---|---|
motor |
The motor or motor group to spin. Choose from the motors configured in the Devices window. |
direction |
The direction the motor or motor group spins. By default, the choices are forward and reverse. Direction choices can change depending on the motor’s configuration. |
Example
when started
[Spin the motor forward, then stop.]
spin [Motor1 v] [forward v]
wait (1) seconds
stop [Motor1 v]
spin motor for#
The spin motor for stack block spins a motor or motor group for a specific distance. The spin is relative to the current position of the motor or motor group. The project will wait until the motor or motor group is done spinning before the next block in the stack runs.
spin [Motor1 v] [forward v] for (90) [degrees v] ▶
Parameters |
Description |
|---|---|
motor |
The motor or motor group to spin. Choose from the motors configured in the Devices window. |
direction |
The direction the motor or motor group spins. By default, the choices are forward and reverse. Direction choices can change depending on the motor’s configuration. |
distance |
The distance the motor or motor group 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
[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 motor to position#
The spin motor to position stack block spins a motor or motor group to a specific position.
A motor or motor group’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 or motor group’s current position.
spin [Motor1 v] to position (90) [degrees v] ▶
Parameters |
Description |
|---|---|
motor |
The motor or motor group to spin. Choose from the motors configured in the Devices window. |
position |
The position value the motor or motor group 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
[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 stack block immediately stops the selected motor or motor group.
stop [Motor1 v]
Parameters |
Description |
|---|---|
motor |
The motor or motor group to stop. Choose from the motors configured in the Devices window. |
Example
when started
[Stop the motor after 1 second.]
spin [Motor1 v] [forward v]
wait (1) seconds
stop [Motor1 v]
Settings#
set motor position#
A motor or motor group’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 or motor group’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 [Motor1 v] position to (0) [degrees v]
Parameters |
Description |
|---|---|
motor |
The motor or motor group to set the position of. Choose from the motors configured in the Devices window. |
position |
The position value to set for the motor or motor group. Degrees use integers. Turns can use integers or decimals. |
unit |
The position unit: degrees or turns. |
Example
when started
[Spin the motor to the new 0 position.]
set [Motor1 v] position to [180] [degrees v]
spin [Motor1 v] to position [0] [degrees v] ▶
set motor velocity#
The set motor velocity stack block tells a motor or motor group how fast to spin. A higher percentage makes the motor or motor group spin faster and a lower percentage makes the motor or motor group 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 [Motor1 v] velocity to (50) [% v]
Parameters |
Description |
|---|---|
motor |
The motor or motor group to set the velocity of. Choose from the motors configured in the Devices window. |
velocity |
The speed the motor or motor group will spin at. Percent uses integers from 0% to 100%. RPM uses integers from 0 to 127. |
unit |
The velocity unit: % or rpm (revolutions per minute). |
Example
when started
[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 stack block sets how a motor or motor group will stop moving: by braking, coasting, or holding.
set [Motor1 v] stopping to [brake v]
Parameters |
Description |
|---|---|
motor |
The motor or motor group to set the stopping behavior of. Choose from the motors configured in the Devices window. |
stopping behavior |
How the motor or motor group will stop:
|
If this block is not used, the motor will use brake when stopping.
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 or motor group is allowed to use.
A higher percentage lets the motor or motor group push harder, like when lifting a heavy object. A lower percentage limits how hard the motor or motor group 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 [Motor1 v] max torque to [50] %
Parameters |
Description |
|---|---|
motor |
The motor or motor group to set the max torque of. Choose from the motors configured in the Devices window. |
torque |
The max torque the motor or motor group can use from 0% to 100%. |
Example
when started
[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 stack block sets how many seconds a motor or motor group will try to finish a movement. If the motor or motor group cannot finish in that time, it will stop trying and move on to the next block in the stack. This keeps the motor or motor group from getting stuck on a movement.
set [Motor1 v] timeout to (1) seconds
Parameters |
Description |
|---|---|
motor |
The motor or motor group to set the timeout of. Choose from the motors configured in the Devices window. |
time |
The number of seconds the motor or motor group can try to finish a movement. This can be a whole number or a decimal. |
Example
when started
[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] ▶
Values#
motor is done#
The motor is done Boolean block reports whether the motor or motor group is finished moving. This can be used to control the timing of other behaviors based on the motor or motor group’s movement.
True — The motor or motor group is finished moving.
False — The motor or motor group 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.
<[Motor1 v] is done?>
Parameters |
Description |
|---|---|
motor |
The motor or motor group to report whether it is finished moving. Choose from the motors configured in the Devices window. |
Example
when started
[Drive forward until the motor is done spinning.]
spin [Motor1 v] [forward v] for (200) [degrees v] ◀ and don't wait
forever
if <[Motor1 v] is done?> then
stop driving
else
drive [forward v]
motor is spinning#
The motor is spinning Boolean block reports whether the motor or motor group is spinning. This can be used to control the timing of other behaviors based on the motor or motor group’s movement.
True — The motor or motor group is spinning.
False — The motor or motor group 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.
<[Motor1 v] is spinning?>
Parameters |
Description |
|---|---|
motor |
The motor or motor group to report whether it is spinning. Choose from the motors configured in the Devices window. |
Example
when started
[Move forward while the motor is spinning.]
spin [Motor1 v] [forward v] for (200) [degrees v] ◀ and don't wait
while <[Motor1 v] is spinning?>
drive [forward v]
end
stop driving
motor position#
A motor or motor group’s position is how far it has spun, measured in degrees or turns. One turn is equal to 360 degrees. The motor position reporter block reports the motor or motor group’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.
([Motor1 v] position in [degrees v])
Parameters |
Description |
|---|---|
motor |
The motor or motor group 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
[Display the motor's position after spinning.]
print ([Motor1 v] position in [degrees v]) on [Brain v] ◀ and set cursor to next row
spin [Motor1 v] [forward v]
wait (1) seconds
print ([Motor1 v] position in [degrees v]) on [Brain v] ▶
stop [Motor1 v]
motor velocity#
The motor velocity reporter block reports how fast the motor or motor group is spinning, as a percentage from -100% to 100% or as revolutions per minute (rpm) from -127 to 127.
([Motor1 v] velocity in [% v])
Parameters |
Description |
|---|---|
motor |
The motor or motor group to report the velocity of. Choose from the motors configured in the Devices window. |
unit |
The unit to report the motor velocity in: % or rpm (revolutions per minute). |
Example
when started
[Display the motor's velocity from spinning.]
print ([Motor1 v] velocity in [rpm v]) on [Brain v] ◀ and set cursor to next row
spin [Motor1 v] [forward v]
wait (1) seconds
print ([Motor1 v] velocity in [rpm v]) on [Brain v] ▶
stop [Motor1 v]
motor current#
The motor current reporter block reports how much electrical current the selected motor or motor group is using, measured in amps from 0.0 to 1.2 A. Current is the amount of electricity flowing through the motor or motor group.
A higher current value means the motor or motor group is using more electrical current. This can happen when the motor or motor group is lifting something heavy, pushing against an object, or trying to move when it is stuck.
This can be used to check if the motor or motor group is struggling during a movement. If current stays high, the motor may get warmer or use power less efficiently.
([Motor1 v] current in [amps v])
Parameters |
Description |
|---|---|
motor |
The motor or motor group to report the current of. Choose from the motors configured in the Devices window. |
unit |
The unit to report current in: amps. |
Example
when started
[Display the motor's current from spinning.]
set print precision to [0.01 v] on [Brain v]
print ([Motor1 v] current in [amps v]) on [Brain v] ◀ and set cursor to next row
spin [Motor1 v] [forward v]
wait (1) seconds
print ([Motor1 v] current in [amps v]) on [Brain v] ▶
stop [Motor1 v]