Motor#
Initializing the Motor Class#
The Motor
constructor creates a Motor object.
This constructor takes in three parameters at most.
Parameter |
Description |
---|---|
|
A valid Smart Port that the Motor is connected to. |
|
Optional. Sets the gear setting or Gear Ratio installed in the Motor, the default is 1.0. |
|
Optional. Sets whether the Motor’s spin should be reversed, the default is |
# Construct a Motor object named motor_1 in Port 1 on
# the IQ (2nd gen) Brain which has the reverse flag set to True.
motor_1 = Motor(Ports.PORT1, 1.0, True)
This motor_1
object will be used in all subsequent examples throughout this API documentation when referring to Motor class methods.
Class Methods#
spin()#
The spin(direction, velocity, units)
method is used to spin a Motor in the specified direction until a spin
or stop
method is used, or the project is stopped.
This is a non-blocking method and allows the next method to run without delay.
Parameters |
Description |
---|---|
direction |
A valid DirectionType. |
velocity |
Optional. The velocity at which the Motor will spin. The default velocity set by the |
units |
Optional. A valid VelocityUnit or |
Returns: None.
# Spin motor_1 forward.
motor_1.spin(FORWARD)
spin_to_position()#
The spin_to_position(rotation, units, velocity, units_v, wait)
method is used to spin a Motor to an absolute position using the provided arguments.
This method can be a blocking or non-blocking method depending on if the wait
parameter is set to True
.
Parameters |
Description |
---|---|
rotation |
The position to spin the Motor to. |
units |
Optional. A valid RotationUnit. The default is |
velocity |
Optional. The velocity with which the Motor will spin. The default velocity set by the |
units_v |
Optional. A valid VelocityUnit or |
wait |
Optional. Determines whether the method will block subsequent commands ( |
Returns: None.
# Spin motor_1 to the position 90 degrees at 100 RPM.
motor_1.spin_to_position(90, DEGREES, 100, RPM)
spin_for()#
The spin_for(direction, value, units, velocity, units_v, wait)
method is used to spin the Motor for a specific duration, rotations, or until a specific encoder value is reached. The position is relative to the current position of the Motor.
This can be a blocking or non-blocking method depending on if the wait
parameter is used.
Parameters |
Description |
---|---|
direction |
A valid DirectionType. |
value |
The value for the Motor to spin to. |
units |
Optional. A valid RotationUnit. The default is |
velocity |
Optional. The velocity with which the Motor will spin. The default velocity set by the |
units_v |
Optional. A valid VelocityUnit or |
wait |
Optional. Determines whether the method will block subsequent commands ( |
Returns: None.
# Spin motor_1 forward for 10 turns at 100 percent velocity.
motor_1.spin_for(FORWARD, 10, TURNS, 100, PERCENT)
stop()#
The stop(mode)
method is used to stop a Motor, setting them to 0 velocity and configuring the current stopping mode.
Parameters |
Description |
---|---|
mode |
Optional. A valid BrakeType. The default is |
Returns: None.
# Spin motor_1 forward for 2.5 seconds.
motor_1.spin(FORWARD)
wait(2.5, SECONDS)
# Stop motor_1 using the HOLD brake type.
motor_1.stop(HOLD)
set_velocity()#
The set_velocity(velocity, units)
method is used to set the default velocity for a Motor. This velocity setting will be used for subsequent calls to any motion functions if a specific velocity is not provided.
Parameters |
Description |
---|---|
velocity |
The new velocity to set for the Motor. |
units |
A valid VelocityUnit or |
Returns: None.
# Spin motor_1 forward at 75 percent velocity
motor_1.set_velocity(75, PERCENT)
motor_1.spin(FORWARD)
set_reversed()#
The set_reversed(value)
method sets the Motor direction to be reversed. This method works the same as setting the reverse
parameter to True
when constructing a Motor.
Parameters |
Description |
---|---|
value |
Boolean value to set the direction reversed or not. |
Returns: None.
set_stopping()#
The set_stopping(mode)
method is used to set the stopping mode for a Motor.
Parameters |
Description |
---|---|
mode |
A valid BrakeType. |
Returns: None.
reset_position()#
The reset_position()
method resets the Motor position to 0. The position that is returned by the motor_1.position()
method will be updated to 0.
Returns: None.
set_position()#
The set_position(value, units)
method is used to set the position of a Motor. The position that is returned by the position()
method will be updated to this new value.
Parameters |
Description |
---|---|
value |
The new position to set for the Motor. |
units |
A valid RotationUnit. |
Returns: None.
set_timeout()#
The set_timeout(value, units)
method is used to set the timeout for a Motor. The position that is returned by the get_timeout()
method will be updated to this new value.
Parameters |
Description |
---|---|
value |
The new timeout to set for the Motor. |
units |
Optional. A valid TimeUnit. The default is |
Returns: None.
get_timeout()#
The get_timeout()
method returns the current timeout for a Motor.
Returns: The current timeout value in milliseconds.
is_spinning()#
The is_spinning()
method returns the current status of the spin_to_position()
or spin_for()
commands. This method is used when False
has been passed as the wait parameter in either method.
Returns: True
if the Motor is still spinning. False
if the Motor has completed the move or a timeout has occurred.
is_done()#
The is_done()
method returns the current status of the spin_to_position()
or spin_for()
commands. This method is used when False
has been passed as the wait parameter in either method.
Returns: True
if the Motor is still spinning. False
if the Motor has completed the move or a timeout has occurred.
set_max_torque()#
The set_max_torque(value, units)
method is used to set the maximum torque for a Motor. The torque can be set as torque, current, or a percent of maximum torque.
Parameters |
Description |
---|---|
value |
The new maximum torque for a Motor. |
units |
A valid TorqueUnit, |
Returns: None.
direction()#
The direction()
method returns the current direction the Motor is spinning in.
Returns: The current DirectionType the Motor is spinning in.
position()#
The position(units)
method returns the current position of the Motor.
Parameters |
Description |
---|---|
units |
Optional. A valid RotationUnit. The default is |
Returns: The current position of the Motor in the specified units.
velocity()#
The velocity(units)
method returns the current velocity of the Motor.
Parameters |
Description |
---|---|
units |
Optional. A valid VelocityUnit. The default is |
Returns: The current velocity of the Motor in the specified units.
current()#
The current(units)
method returns the current being used by the Motor.
Parameters |
Description |
---|---|
units |
Optional. The only valid units for current are |
Returns: The current being drawn by the Motor in the specified units.
power()#
The power(units)
method returns the power being consumed by the Motor.
Parameters |
Description |
---|---|
units |
Optional. The only valid units for power are |
Returns: The power being consumed by the Motor in the specified units.
torque()#
The torque(units)
method returns the torque being generated by the Motor.
Parameters |
Description |
---|---|
units |
Optional. A valid TorqueUnit. The default is |
Returns: The torque being generated by the Motor in the specified units.
efficiency()#
The efficiency(units)
method returns the efficiency of the Motor.
Parameters |
Description |
---|---|
units |
Optional. The only valid unit for efficiency is |
Returns: The efficiency of the Motor as a percent.
temperature()#
The temperature(units)
method returns the temperature of the Motor.
Parameters |
Description |
---|---|
units |
Optional. A valid TemperatureUnit. The default is |
Returns: The temperature of the Motor in the specified units.
method()#
The method(units)
method returns the last velocity sent to the Motor.
Parameters |
Description |
---|---|
units |
Optional. A valid VelocityUnit. The default is |
Returns: The Motor method velocity in the specified units.
installed()#
The installed()
method returns if the Motor is connected to the IQ (2nd gen) Brain.
Returns: True
if the Motor is connected. False
if it is not.