Motor#
Introduction#
The IQ Smart Motor can spin, hold position, and control velocity and torque with precision. It can be used individually or as part of a motor group.
For the examples below, the configured motor will be named motor_1, and the configured motor group will be named motor_group_1. They will be used in all subsequent examples throughout this API documentation when referring to Motor and MotorGroup class methods.
Below is a list of all methods:
Actions – Control the movement of motors.
spin– Spins a motor or motor group in a specified direction indefinitely.spin_for– Spins a motor or motor group for a specified distance.spin_to_position– Spins a motor to an absolute position.stop– Stops a motor or motor group with configurable behavior.
Mutators – Change the motor’s different attributes.
set_velocity– Sets the default velocity for the motor or motor group.set_max_torque– Sets the maximum torque for a motor or motor group.set_position– Sets the motor or motor group’s position to a specific value.set_stopping– Sets the stop behavior (brake, coast, or hold).set_timeout– Limits how long a motor function waits before giving up if movement is blocked.set_reversed– Sets only a motor to have its direction be reversed.reset_position– Sets only a motor’s position to 0.
Getters – Return data from motors.
position– Returns a motor or motor group’s current position.velocity– Returns a motor or motor group’s current velocity.current– Returns the current being used by a motor or motor group.is_done– Returns whether a motor or motor group is currently not spinning.is_spinning– Returns whether a motor or motor group is currently spinning.direction– Returns the spin direction of a motor or motor group.power– Returns the amount of power being used by a motor or motor group.torque– Returns the torque generated by a motor or motor group.efficiency– Returns the efficiency of a motor or motor group.temperature– Returns the temperature of a motor or motor group.count– Returns the amount of motors in a motor group.get_timeout– Returns only a motor’s current timeout duration.
Constructors – Manually initialize and configure motors and motor groups.
Motor– Creates a motor.MotorGroup– Creates a motor group.
Actions#
spin#
spin spins a motor or motor group in the specified direction indefinitely.
Usage:
motor_1.spin(direction, velocity, units)
Parameters |
Description |
|---|---|
|
The direction in which to spin the motor or motor group:
|
|
Optional. The velocity at which the motor or motor group will spin as a float or integer. If the velocity is not specified, the default velocity is 50%. |
|
Optional. The unit that represents the velocity:
|
# Spin the motor forward, then stop
motor_1.spin(FORWARD)
wait(1, SECONDS)
motor_1.stop()
spin_for#
spin_for spins a motor or motor group in a specified direction for a set distance relative to its current position.
Usage:
motor_1.spin_for(direction, angle, units, velocity, units_v, wait)
Parameters |
Description |
|---|---|
|
The direction in which to spin the motor or motor group:
|
|
The amount of degrees the motor or motor group will spin as a float or integer. |
|
Optional. The unit that represents the rotational value:
|
|
Optional. The velocity at which the motor or motor group will spin as a float or integer. If the velocity is not specified, the default velocity is 50%. |
|
Optional. The unit that represents the velocity:
|
|
Optional.
|
# Spin the motor forward, then put it
# at 90 degrees
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.spin_to_position(90, DEGREES)
# Spin the motor and different
# velocities
# Using default velocity
motor_1.spin_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Spin slower
motor_1.spin_for(REVERSE, 150, MM, 20, PERCENT)
wait(1, SECONDS)
# Spin faster
motor_1.spin_for(FORWARD, 150, MM, 100, PERCENT)
spin_to_position#
spin_to_position spins a motor and motor group to an absolute position.
Usage:
motor_1.spin_to_position(rotation, units, velocity, units_v, wait)
Parameters |
Description |
|---|---|
|
The position to spin the motor or motor group to as a float or integer. |
|
The unit that represents the rotational value:
|
|
Optional. The velocity at which the motor or motor group will spin as a float or integer. If the velocity is not specified, the default velocity is 50%. |
|
Optional. The unit that represents the velocity:
|
|
Optional.
|
# Spin the motor forward, then
# put it at 90 degrees
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.spin_to_position(90, DEGREES)
# Spin forward then quickly reverse
# to 0 degrees
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.spin_to_position(0, DEGREES, 100, PERCENT, wait=True)
stop#
stop stops a motor or motor group.
Usage:
motor_1.stop(mode)
Parameters |
Description |
|---|---|
|
Optional. How the motor or motor group will stop:
|
# Spin the motor forward, then stop
motor_1.spin(FORWARD)
wait(1, SECONDS)
motor_1.stop()
# Spin the motor and coast to a stop
motor_1.set_velocity(100, PERCENT)
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.stop(COAST)
Mutators#
set_velocity#
set_velocity sets the default velocity for a motor or motor group. This velocity setting will be used for subsequent calls to any motor functions if a specific velocity is not provided.
Usage:
motor_1.set_velocity(velocity, units)
Parameters |
Description |
|---|---|
|
The velocity at which the motor or motor group will spin as a float or integer. |
|
Optional. The unit that represents the velocity:
|
# Spin the motor and
# different velocities
# Using default velocity
motor_1.spin_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Spin slower
motor_1.set_velocity(20, PERCENT)
motor_1.spin_for(REVERSE, 150, MM)
wait(1, SECONDS)
# Spin faster
motor_1.set_velocity(100, PERCENT)
motor_1.spin_for(FORWARD, 150, MM)
set_max_torque#
set_max_torque sets the maximum torque for a motor or motor group. The torque can be set as torque, current, or a percent of maximum torque.
Usage:
motor_1.set_max_torque(value, units)
Parameters |
Description |
|---|---|
|
The new maximum torque for a motor or motor group as a float or integer. |
|
The unit that represents the torque:
|
# Spin the motor at different
# torque values
# Default
motor_1.spin_to_position(45, DEGREES)
# Spin at a lower torque
motor_1.set_max_torque(20, PERCENT)
motor_1.spin_to_position(0, DEGREES)
# Spin at te max torque
motor_1.set_max_torque(100, PERCENT)
motor_1.spin_to_position(45, DEGREES)
set_position#
set_position sets the position of a motor or motor group.
Usage:
motor_1.set_position(position, units)
Parameters |
Description |
|---|---|
|
The new position as an integer. |
|
The unit that represents the rotational value:
|
# Position the motor at the
# new 0 degrees
motor_1.set_position(180, DEGREES)
motor_1.spin_to_position(0)
set_stopping#
set_stopping sets the stopping mode for a motor or motor group.
Usage:
motor_1.set_stopping(mode)
Parameters |
Description |
|---|---|
|
How the motor or motor group will stop:
|
# Spin the motor and coast to a stop
motor_1.set_velocity(100, PERCENT)
motor_1.set_stopping(COAST)
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.stop()
set_timeout#
set_timeout sets a time limit for how long a motor function will wait to reach its target. If the motor or motor group cannot complete the movement within the set time, it will stop automatically and continue with the next function.
Note: The motor or motor group’s time limit is used to prevent motor functions that do not reach their target position from stopping the execution of the rest of the project.
Usage:
motor_1.set_timeout(value, units)
Parameters |
Description |
|---|---|
|
The maximum number of seconds a motor function will run before stopping and moving to the next function as an integer or float. |
|
Optional. The unit that represents the time:
|
# Set a 0.5 second timeout for motor actions
motor_1.set_timeout(0.5, SECONDS)
# Try a long move that will time out early
motor_1.spin_for(FORWARD, 2, TURNS)
motor_1.spin_to_position(0, DEGREES)
set_reversed#
set_reversed sets the motor to be reversed. This method works the same as setting the reverse parameter to True when constructing a Motor.
Note: This method will only work with a motor and not a motor group.
Usage:
motor_1.set_reversed(value)
Parameters |
Description |
|---|---|
|
Boolean value to set the direction reversed or not:
|
# Change the reverse direction while spinning
motor_1.spin_for(FORWARD, 45)
motor_1.set_reversed(True)
motor_1.spin_for(FORWARD, 45)
reset_position#
reset_position sets the motor or motor group’s position to 0.
Usage:
motor_1.reset_position()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Spin to 360 degrees, then reset the encoder
motor_1.spin_to_position(360, DEGREES)
motor_1.reset_position()
# Move again to 90 degrees from new zero point
motor_1.spin_to_position(90, DEGREES)
Getters#
position#
position returns the current position of a motor or motor group as an integer or as a float.
Usage:
motor_1.position(units)
Parameters |
Description |
|---|---|
|
Optional. The unit that represents the rotational value:
|
# Spin the motor and display the
# ending position
motor_1.spin(FORWARD)
wait(1, SECONDS)
motor_1.stop()
brain.screen.print(motor_1.position())
velocity#
velocity returns the current velocity of a motor or motor group as an integer or as a float.
Usage:
motor_1.velocity(units)
Parameters |
Description |
|---|---|
|
Optional. The unit that represents the velocity:
|
current#
current returns the current of the motor or motor group in amps.
Usage:
motor_1.current(units)
Parameters |
Description |
|---|---|
|
Optional. The unit that represents the current:
|
is_done#
is_done returns a Boolean indicating whether a motor or motor group is not currently spinning.
True– The motor or motor group is not spinning.False– The motor or motor group is spinning.
Usage:
motor_1.is_done()
Parameters |
Description |
|---|---|
This method has no parameters. |
is_spinning#
is_spinning returns a Boolean indicating whether a motor or motor group is currently spinning.
True– The motor or motor group is spinning.False– The motor or motor group is not spinning.
Usage:
motor_1.is_spinning()
Parameters |
Description |
|---|---|
This method has no parameters. |
direction#
direction returns the current direction a motor or motor group is spinning in.
FORWARDREVERSE
Usage:
motor_1.direction()
Parameters |
Description |
|---|---|
This method has no parameters. |
power#
power returns the power that the motor is using in watts.
Usage:
motor_1.power()
Parameters |
Description |
|---|---|
This method has no parameters. |
torque#
torque returns the current torque of the motor.
Usage:
motor_1.torque(units)
Parameters |
Description |
|---|---|
|
The unit that represents the torque:
|
efficiency#
efficiency returns the current efficiency of the motor in percent.
Usage:
motor_1.efficiency()
Parameters |
Description |
|---|---|
This method has no parameters. |
temperature#
temperature returns the current temperature of the motor.
Usage:
motor_1.temperature(units)
Parameters |
Description |
|---|---|
|
Optional. The units that represent the temperature:
|
count#
count returns the number of motors in a motor group as an integer.
Note: This method will only work with a motor group and not a motor.
Usage:
motor_group_1.count()
Parameters |
Description |
|---|---|
This method has no parameters. |
get_timeout#
get_timeout returns the current timeout for a motor in milliseconds.
Note: This method will only work with a motor and not a motor group.
Usage:
motor_1.get_timeout()
Parameters |
Description |
|---|---|
This method has no parameters. |
Constructors#
Constructors are used to manually create Motor and MotorGroup objects, which are necessary for configuring a motor or motor group outside of VEXcode.
Motor#
Motor creates a motor.
Usage:
motor_1 = Motor(port, gears, reverse)
Parameter |
Description |
|---|---|
|
Which Smart Port that the motor is connected to as |
|
Optional. The motor’s gear ratio:
|
|
Optional. Sets whether the motor’s spin should be reversed.
|
# Create a reversed motor
motor_1 = Motor(Ports.PORT1, 1.0, True)
Motor Group#
MotorGroup creates a motor group.
Usage:
motor_group_1 = MotorGroup(motors)
Parameter |
Description |
|---|---|
|
The names of previously created |
# Create two motors
motor_group_1_motor_a = Motor(Ports.PORT1, False)
motor_group_1_motor_b = Motor(Ports.PORT6, True)
# Create a motor group with those motors
motor_group_1 = MotorGroup(motor_group_1_motor_a, motor_group_1_motor_b)