VEX V5 Python API
Public Member Functions | List of all members
vex.Motor Class Reference

Inherits vex.Device.

Public Member Functions

def __init__ (self, index, gearSetting=GearSetting.RATIO18_1, reverse=False)
 Creates a new motor object on the port specified. More...
 
def set_reversed (self, isReversed)
 Use this function to reverse setting for the motor. 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)
 Return the timeout for the motor. More...
 
def did_timeout (self)
 Check if the last motor operation timed out. More...
 
def spin (self, direction, velocity=None, velocityUnits=VelocityUnits.PCT)
 Turns on the motor and spins it in a specified direction and velocity (if specified). More...
 
def spin_with_voltage (self, direction, voltage, voltageUnits=VoltageUnits.VOLT)
 Turns on the motor and spins it in a specified direction and a specified voltage. 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_to_position (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, direction, 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, direction, time, timeUnits=TimeUnits.SEC, velocity=None, velocityUnits=VelocityUnits.PCT)
 Turns on the motor and spins it for specified time 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_to_position (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, direction, 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)
 Checks to see if a spin_for/spin_to command is still in process, i.e. 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 a specified brake mode (or default mode if not specified). More...
 
def set_max_torque (self, value, torqueUnits=TorqueUnits.NM)
 Sets the max torque of the motor, in torque units. More...
 
def set_max_torque_percent (self, value, percentUnits=PercentUnits.PCT)
 Sets the max torque of the motor, in percent. More...
 
def set_max_torque_current (self, value, currentUnits=CurrentUnits.AMP)
 Sets the max torque of the motor, in terms of current. More...
 
def direction (self)
 Gets which direction the motor is spinning. 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, currentUnits=CurrentUnits.AMP)
 Gets the electrical current of the motor. More...
 
def voltage (self, voltageUnits=VoltageUnits.VOLT)
 Gets the electrical voltage being applied to the motor. More...
 
def power (self, powerUnits=PowerUnits.WATT)
 Gets the power of the motor. More...
 
def torque (self, torqueUnits=TorqueUnits.NM)
 Gets the torque of the motor. More...
 
def efficiency (self, percentUnits=PercentUnits.PCT)
 Gets the efficiency of the motor. More...
 
def temperature (self, temperatureUnits=TemperatureUnits.CELSIUS)
 Gets the temperature of the motor. More...
 
def type (self)
 Get the device type. More...
 
def installed (self)
 Gets the status of what is installed. More...
 
def value (self)
 

Constructor & Destructor Documentation

◆ __init__()

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

Creates a new motor object on the port specified.

Parameters
indexThe port index for this motor. The index is zero based.
gearSettingSets the gears setting for the new motor object.
reverseSets the reverse flag for the new motor object.

Member Function Documentation

◆ set_reversed()

def vex.Motor.set_reversed (   self,
  isReversed 
)

Use this function to reverse setting for the motor.

Parameters
isReversedIf set to true, the motor will spin in the reversed 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
velocitySet the amount of velocity that the motor should use.
velocityUnitsSet what the motor should treat the previous velocity value as.

◆ set_stopping()

def vex.Motor.set_stopping (   self,
  brakeType 
)

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

Parameters
brakeTypeThe stopping mode can be set to 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
valueThe value of what you want the motor's encoder to be set to.
rotationUnitsA rotational unit type that defines how the previous value should be treated as.

◆ 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 turn off.

Parameters
timeThe value of the time out expiration.
timeUnitsA time unit that defines how to treat the previous value.

◆ timeout()

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

Return the timeout for the motor.

◆ did_timeout()

def vex.Motor.did_timeout (   self)

Check if the last motor operation timed out.

Returns
True if the last operation timed out

◆ spin()

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

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

Parameters
directionSpin the motor forward by passing FWD, or spin the motor backward by passing REV.
velocitySet the amount of velocity that the motor should use. Optional.
velocityUnitsSet what the motor should treat the previous velocity value as. Optional.

◆ spin_with_voltage()

def vex.Motor.spin_with_voltage (   self,
  direction,
  voltage,
  voltageUnits = VoltageUnits.VOLT 
)

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

Parameters
directionThe direction to spin the motor.
voltageSets the amount of volts.
voltageUnitsThe measurement unit for the voltage value. Optional, default is volts.

◆ 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.

Parameters
rotationThe motor encoder's target rotation value
rotationUnitsA rotational unit type that defines how the previous value should be treated as.
velocitySet the amount of velocity that the motor should use.
velocityUnitsSet what the motor should treat the previous velocity value as.
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.
Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.

◆ spin_to_position()

def vex.Motor.spin_to_position (   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.

Same as spinTo.

Parameters
rotationThe motor encoder's target rotation value
rotationUnitsA rotational unit type that defines how the previous value should be treated as.
velocitySet the amount of velocity that the motor should use.
velocityUnitsSet what the motor should treat the previous velocity value as.
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.
Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.

◆ spin_for()

def vex.Motor.spin_for (   self,
  direction,
  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.

Parameters
directionDirection to spin in, vex.DirectionType.FWD or REV.
rotationThe motor encoder's target rotation value
rotationUnitsA rotational unit type that defines how the previous value should be treated as.
velocitySet the amount of velocity that the motor should use.
velocityUnitsSet what the motor should treat the previous velocity value as.
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.
Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.

◆ spin_for_time()

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

Turns on the motor and spins it for specified time at a specified velocity.

Parameters
directionDirection to spin in, vex.DirectionType.FWD or REV.
timeThe value of time that the motor should spin for.
timeUnitsA time unit that defines how to treat the previous value.
velocitySet the amount of velocity that the motor should use.
velocityUnitsSet what the motor should treat the previous velocity value as.

◆ 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
rotationThis is the motor encoder's target rotation value
rotationUnitsThis is a rotational unit type that defines how the previous value should be treated as.
velocitySet the amount of velocity that the motor should use.
velocityUnitsSet what the motor should treat the previous velocity value as.

◆ start_spin_to_position()

def vex.Motor.start_spin_to_position (   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.

Same as startSpinTo

Parameters
rotationThis is the motor encoder's target rotation value
rotationUnitsThis is a rotational unit type that defines how the previous value should be treated as.
velocitySet the amount of velocity that the motor should use.
velocityUnitsSet what the motor should treat the previous velocity value as.

◆ start_spin_for()

def vex.Motor.start_spin_for (   self,
  direction,
  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
directionDirection to spin in, vex.DirectionType.FWD or REV.
rotationThis is the motor encoder's target rotation value
rotationUnitsThis is a rotational unit type that defines how the previous value should be treated as.
velocitySet the amount of velocity that the motor should use.
velocityUnitsSet what the motor should treat the previous velocity value as.

◆ is_spinning()

def vex.Motor.is_spinning (   self)

Checks to see if a spin_for/spin_to command is still in process, i.e.

the motor is still rotating and hasn't yet reached its target position.

Returns
Returns a true Boolean if the motor is on and is running. Returns a false Boolean if the motor is off or braking.

◆ is_done()

def vex.Motor.is_done (   self)

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

Returns
If the function returns true, then the motor is done with the action.

◆ stop()

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

Stops the motor using a specified brake mode (or default mode if not specified).

◆ set_max_torque()

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

Sets the max torque of the motor, in torque units.

Parameters
valueThe value that the motor's max torque should be set to.
torqueUnitstorque units, default Nm

◆ set_max_torque_percent()

def vex.Motor.set_max_torque_percent (   self,
  value,
  percentUnits = PercentUnits.PCT 
)

Sets the max torque of the motor, in percent.

Parameters
valueThe value that the motor's max torque should be set to.
percentUnitspercent units (percent).

◆ set_max_torque_current()

def vex.Motor.set_max_torque_current (   self,
  value,
  currentUnits = CurrentUnits.AMP 
)

Sets the max torque of the motor, in terms of current.

Parameters
valueThe value that the motor's max torque should be set to.
currentUnitscurrent units (amps).

◆ direction()

def vex.Motor.direction (   self)

Gets which direction the motor is spinning.

Returns
Returns an integer that represents the direction that the motor is spinning.

◆ rotation()

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

Gets the current rotation of the motor's encoder.

Parameters
rotationUnitsDefines what the unity type of the value of rotation that is returned.
Returns
Returns a double that represents the current rotation of the motor in the units defined in the parameter.

◆ velocity()

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

Gets the current velocity of the motor.

Parameters
velocityUnitsDefines the unit type of the velocity value returned.
Returns
Returns a double that represents the current velocity of the motor in the units defined in the parameter.

◆ current()

def vex.Motor.current (   self,
  currentUnits = CurrentUnits.AMP 
)

Gets the electrical current of the motor.

Parameters
currentUnitsDefines the unit type of the electrical current value that is returned.
Returns
Returns a double that represents the electrical current of the motor in the units defined in the parameter.

◆ voltage()

def vex.Motor.voltage (   self,
  voltageUnits = VoltageUnits.VOLT 
)

Gets the electrical voltage being applied to the motor.

Parameters
voltageUnitsThe measurement unit for the voltage.
Returns
Returns a the electrical voltage of the motor in the units defined in the parameter.

◆ power()

def vex.Motor.power (   self,
  powerUnits = PowerUnits.WATT 
)

Gets the power of the motor.

Parameters
powerUnits
Returns
Returns a double that represents the power of the motor in the units defined in the parameter.

◆ torque()

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

Gets the torque of the motor.

Parameters
torqueUnitsDefines the unit type of torque to be returned.
Returns
Returns a double that represents the torque of the motor in the units defined in the parameter.

◆ efficiency()

def vex.Motor.efficiency (   self,
  percentUnits = PercentUnits.PCT 
)

Gets the efficiency of the motor.

Parameters
percentUnitsDefines the unit type of the efficiency value to be returned.
Returns
Returns the efficiency of the motor in the units defined in the parameter.

◆ temperature()

def vex.Motor.temperature (   self,
  temperatureUnits = TemperatureUnits.CELSIUS 
)

Gets the temperature of the motor.

Parameters
temperatureUnitsDefines the unit type of the temperature value to be returned. Default Celsius.
Returns
Returns the temperature of the motor in the units defined in the parameter.

◆ type()

def vex.Device.type (   self)
inherited

Get the device type.

Returns
V5DeviceType enum value

◆ installed()

def vex.Device.installed (   self)
inherited

Gets the status of what is installed.

Returns
Returns a true Boolean if the triport is installed. Returns a false Boolean if the triport is not installed.

◆ value()

def vex.Device.value (   self)
inherited