VEX IQ Python API
Public Member Functions | List of all members
vex.Motor Class Reference
Inheritance diagram for vex.Motor:
vex.Device

Public Member Functions

def __init__ (self, index, reverse=False)
 
def set_reversed (self, is_reversed)
 Sets the motor mode to "reverse", which will make motor commands spin the motor in the opposite direction. More...
 
def set_velocity (self, velocity, velocityUnits=VelocityUnits.PCT)
 Sets the velocity of the motor based on the parameters set in the command. More...
 
def set_stopping (self, brakeType)
 Sets the stopping mode of the motor by passing a brake mode as a parameter. More...
 
def reset_rotation (self)
 Resets the motor's encoder to the value of zero. More...
 
def set_rotation (self, value, rotationUnits=RotationUnits.DEG)
 Sets the value of the motor's encoder to the value specified in the parameter. More...
 
def set_timeout (self, time, timeUnits=TimeUnits.SEC)
 Sets the timeout for the motor. More...
 
def timeout (self, timeUnits=TimeUnits.SEC)
 
def did_timeout (self)
 
def spin (self, dir, velocity=None, velocityUnits=VelocityUnits.PCT)
 Turns on the motor and spins it in a specified direction and a specified velocity. More...
 
def spin_to (self, rotation, rotationUnits=RotationUnits.DEG, velocity=None, velocityUnits=VelocityUnits.PCT, waitForCompletion=True)
 Turns on the motor and spins it to an absolute target rotation value at a specified velocity. More...
 
def spin_for (self, dir, rotation, rotationUnits=RotationUnits.DEG, velocity=None, velocityUnits=VelocityUnits.PCT, waitForCompletion=True)
 Turns on the motor and spins it to a relative target rotation value at a specified velocity. More...
 
def spin_for_time (self, dir, time, timeUnits=TimeUnits.SEC, velocity=None, velocityUnits=VelocityUnits.PCT)
 Turns on the motor and spins it to a relative target time value at a specified velocity. More...
 
def start_spin_to (self, rotation, rotationUnits=RotationUnits.DEG, velocity=None, velocityUnits=VelocityUnits.PCT)
 Starts spinning a motor to an absolute target rotation but does not wait for the motor to reach that target. More...
 
def start_spin_for (self, dir, rotation, rotationUnits=RotationUnits.DEG, velocity=None, velocityUnits=VelocityUnits.PCT)
 Starts spinning a motor to a relative target rotation but does not wait for the motor to reach that target. More...
 
def is_spinning (self)
 Determines if a spin_for/spin_to command is in progress. More...
 
def is_done (self)
 Determines if a spin_for/spin_to command has reached its target position. More...
 
def stop (self, brakeType=None)
 Stops the motor using the default brake mode. More...
 
def set_max_torque_percent (self, value)
 Sets the max torque of the motor as a percentage. More...
 
def set_max_torque (self, value, torqueUnits=TorqueUnits.NM)
 Sets the max torque of the motor. More...
 
def set_max_torque_current (self, value)
 Sets the max torque of the motor. More...
 
def rotation (self, rotationUnits=RotationUnits.DEG)
 Gets the current rotation of the motor's encoder. More...
 
def velocity (self, velocityUnits=VelocityUnits.PCT)
 Gets the current velocity of the motor. More...
 
def current (self)
 Gets the electrical current of the motor. More...
 

Detailed Description

 @brief Creates a new motor object on the port specified and sets the reversed flag.
 @param index The port index for this motor. The index is zero-based.
 @param reverse Sets the reverse flag for the new motor object.

Constructor & Destructor Documentation

◆ __init__()

def vex.Motor.__init__ (   self,
  index,
  reverse = False 
)

Member Function Documentation

◆ set_reversed()

def vex.Motor.set_reversed (   self,
  is_reversed 
)

Sets the motor mode to "reverse", which will make motor commands spin the motor in the opposite direction.

Parameters
is_reversedIf set to True, motor commands spin the motor in the opposite direction.

◆ set_velocity()

def vex.Motor.set_velocity (   self,
  velocity,
  velocityUnits = VelocityUnits.PCT 
)

Sets the velocity of the motor based on the parameters set in the command.

This command will not run the motor. Any subsequent call that does not contain a specified motor velocity will use this value.

Parameters
velocitySets the amount of velocity.
velocityUnitsThe measurement unit for the velocity, a VelocityUnits enum value.

◆ set_stopping()

def vex.Motor.set_stopping (   self,
  brakeType 
)

Sets the stopping mode of the motor by passing a brake mode as a parameter.

(note this will stop the motor if it's spinning)

Parameters
brakeTypeThe stopping mode can be set to BrakeType.COAST, BRAKE, or HOLD.

◆ reset_rotation()

def vex.Motor.reset_rotation (   self)

Resets the motor's encoder to the value of zero.

◆ set_rotation()

def vex.Motor.set_rotation (   self,
  value,
  rotationUnits = RotationUnits.DEG 
)

Sets the value of the motor's encoder to the value specified in the parameter.

Parameters
valueSets the amount of rotation.
rotationUnitsThe measurement unit for the rotation, a RotationUnits enum value.

◆ set_timeout()

def vex.Motor.set_timeout (   self,
  time,
  timeUnits = TimeUnits.SEC 
)

Sets the timeout for the motor.

If the motor does not reach its commanded position prior to the completion of the timeout, the motor will stop.

Parameters
timeSets the amount of time.
timeUnitsThe measurement unit for the time, a TimeUnits enum value.

◆ timeout()

def vex.Motor.timeout (   self,
  timeUnits = TimeUnits.SEC 
)
Returns
Returns a timeout in given time units

◆ did_timeout()

def vex.Motor.did_timeout (   self)
Returns
True if the last motor operation timed out

◆ spin()

def vex.Motor.spin (   self,
  dir,
  velocity = None,
  velocityUnits = VelocityUnits.PCT 
)

Turns on the motor and spins it in a specified direction and a specified velocity.

Parameters
dirThe direction to spin the motor, DirectionType enum value.
velocitySets the amount of velocity.
velocityUnitsThe measurement unit for the velocity, a VelocityUnits enum value.

◆ spin_to()

def vex.Motor.spin_to (   self,
  rotation,
  rotationUnits = RotationUnits.DEG,
  velocity = None,
  velocityUnits = VelocityUnits.PCT,
  waitForCompletion = True 
)

Turns on the motor and spins it to an absolute target rotation value at a specified velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
rotationSets the amount of rotation.
rotationUnitsThe measurement unit for the rotation value.
velocitySets the amount of velocity.
velocityUnitsThe measurement unit for the velocity value.
waitForCompletion(Optional) If True, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

◆ spin_for()

def vex.Motor.spin_for (   self,
  dir,
  rotation,
  rotationUnits = RotationUnits.DEG,
  velocity = None,
  velocityUnits = VelocityUnits.PCT,
  waitForCompletion = True 
)

Turns on the motor and spins it to a relative target rotation value at a specified velocity.

Returns
True if motor has reached the target rotation value, False otherwise.
Parameters
dirdirection to spin in, a DirectionType enum value or None.
rotationSets the amount of rotation.
rotationUnitsThe measurement unit for the rotation value.
velocitySets the amount of velocity.
velocityUnitsThe measurement unit for the velocity value.
waitForCompletion(Optional) If true, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

◆ spin_for_time()

def vex.Motor.spin_for_time (   self,
  dir,
  time,
  timeUnits = TimeUnits.SEC,
  velocity = None,
  velocityUnits = VelocityUnits.PCT 
)

Turns on the motor and spins it to a relative target time value at a specified velocity.

Parameters
dirdirection to spin in, a DirectionType enum value or None.
timeSets the amount of time.
timeUnitsThe measurement unit for the time value.
velocitySets the amount of velocity.
velocityUnitsThe measurement unit for the velocity value.

◆ start_spin_to()

def vex.Motor.start_spin_to (   self,
  rotation,
  rotationUnits = RotationUnits.DEG,
  velocity = None,
  velocityUnits = VelocityUnits.PCT 
)

Starts spinning a motor to an absolute target rotation but does not wait for the motor to reach that target.

Parameters
rotationSets the amount of rotation.
rotationUnitsThe measurement unit for the rotation value.
velocitySets the amount of velocity.
velocityUnitsThe measurement unit for the velocity value.

◆ start_spin_for()

def vex.Motor.start_spin_for (   self,
  dir,
  rotation,
  rotationUnits = RotationUnits.DEG,
  velocity = None,
  velocityUnits = VelocityUnits.PCT 
)

Starts spinning a motor to a relative target rotation but does not wait for the motor to reach that target.

Parameters
dirdirection to spin in, a DirectionType enum value or None.
rotationSets the amount of rotation.
rotationUnitsThe measurement unit for the rotation value.
velocitySets the amount of velocity.
velocityUnitsThe measurement unit for the velocity value.

◆ is_spinning()

def vex.Motor.is_spinning (   self)

Determines if a spin_for/spin_to command is in progress.

Returns
True if the motor is on and is rotating to a target, False if the motor is done rotating to a target.

◆ is_done()

def vex.Motor.is_done (   self)

Determines if a spin_for/spin_to command has reached its target position.

Returns
False if the motor is on and is rotating to a target, True if the motor is done rotating to a target.

◆ stop()

def vex.Motor.stop (   self,
  brakeType = None 
)

Stops the motor using the default brake mode.

Parameters
brakeTypeThe brake mode can be set to BrakeType.COAST, BRAKE, or HOLD.

◆ set_max_torque_percent()

def vex.Motor.set_max_torque_percent (   self,
  value 
)

Sets the max torque of the motor as a percentage.

Parameters
valueSets the amount of torque (0 to 100%)

◆ set_max_torque()

def vex.Motor.set_max_torque (   self,
  value,
  torqueUnits = TorqueUnits.NM 
)

Sets the max torque of the motor.

Parameters
valueSets the amount of torque (max 0.414 Nm)
torqueUnitsThe measurement unit for the torque value.

◆ set_max_torque_current()

def vex.Motor.set_max_torque_current (   self,
  value 
)

Sets the max torque of the motor.

Parameters
valueSets the amount of torque in Amps (max 1.2A)

◆ rotation()

def vex.Motor.rotation (   self,
  rotationUnits = RotationUnits.DEG 
)

Gets the current rotation of the motor's encoder.

Returns
a float that represents the current rotation of the motor in the units defined in the parameter.
Parameters
rotationUnitsThe measurement unit for the rotation.

◆ velocity()

def vex.Motor.velocity (   self,
  velocityUnits = VelocityUnits.PCT 
)

Gets the current velocity of the motor.

Returns
a float that represents the current velocity of the motor in the units defined in the parameter.
Parameters
velocityUnitsThe measurement unit for the velocity.

◆ current()

def vex.Motor.current (   self)

Gets the electrical current of the motor.

Returns
a float that represents the electrical current of the motor in Amps.