Motor#
To make Motor commands appear in VEXcode V5, a Motor must be configured in the Devices window.
For more information, refer to these articles:
motor.spin()#
The motor.spin(direction, velocity, units)
command spins the motor using the provided arguments.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
direction |
A valid DirectionType. |
velocity |
Optional. Spin the motor using this velocity. The default velocity set by |
units |
Optional. A valid VelocityUnit or |
Returns: None.
# Spin motor forward for 2 seconds.
motor1.spin(FORWARD)
wait(2, SECOND)
# Stop spinning.
motor1.stop()
motor.spin_to_position()#
The motor.spin_to_position(rotation, units, velocity, units_v, wait)
command is used to spin a motor to an absolute position using the provided arguments.
This function can be a waiting or non-waiting command depending on if the wait
parameter is used.
Parameters |
Description |
---|---|
rotation |
The position to spin the motor to. |
units |
Optional. A valid RotationUnits. The default is |
velocity |
Optional. The velocity with which the motor will spin. The default velocity set by |
units_v |
Optional. A valid VelocityUnits. The default is |
wait |
Optional. Determines whether the command will block subsequent commands ( |
Returns: None.
# Spin motor to 180 degrees
motor1.spin_to_position(180)
motor.spin_for()#
The motor.spin_for(direction, value, units, velocity, units_v, wait)
command spins the motor to a relative position using the provided arguments.
This can be a waiting or non-waiting command 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 RotationUnits. The default is |
velocity |
Optional. The velocity with which the motor will spin. The default velocity set by |
units_v |
Optional. A valid VelocityUnits. The default is |
wait |
Optional. Determines whether the command will block subsequent commands ( |
Returns: None.
motor.stop()#
The motor.stop(mode)
command is used to stop a motor.
This is a non-waiting command and allows the next command to run without delay.
Returns: None.
# Spin motor forward for 2 seconds.
motor1.spin(FORWARD)
wait(2, SECOND)
# Stop spinning.
motor1.stop()
motor.set_velocity()#
The motor.set_velocity(value, units)
command sets the default velocity for the motor.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
value |
The new velocity. |
units |
Optional. A valid VelocityUnits. The default is |
Returns: None.
motor.set_reversed()#
The motor.set_reversed(value)
command sets the motor direction to be reversed.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
value |
Boolean value to set the direction reversed or not. |
Returns: None.
motor.set_stopping()#
The motor.set_stopping(mode)
command sets the stopping mode of the motor.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
mode |
A valid BrakeType. The default is |
Returns: None.
# Set the motor to stop with a brake.
motor_1.set_stopping(BRAKE)
motor.reset_position()#
The motor.reset_position()
command resets the motor position to 0.
This is a non-waiting command and allows the next command to run without delay.
Returns: None.
motor.set_position()#
The motor.set_position(value, units)
command sets the current position of the motor.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
value |
The new position. |
units |
Optional. A valid RotationUnit. The default is |
Returns: None.
motor.set_timeout()#
The motor.set_timeout(value, units)
command sets the timeout value used by the motor.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
value |
The new timeout. |
units |
Optional. A valid TimeUnit. The default is |
Returns: None.
# Set the motor timeout to 5 seconds.
motor_1.set_timeout(5000, MSEC)
motor.get_timeout()#
The motor.get_timeout()
command returns the current value of motor timeout.
This is a non-waiting command and allows the next command to run without delay.
Returns: The current timeout value.
motor.is_spinning()#
The motor.is_spinning()
command returns if the motor is currently spinning.
This is a non-waiting command and allows the next command to run without delay.
Returns: True
if the motor is currently spinning. False
if it is not.
motor.is_done()#
The motor.is_done()
command returns if the motor has completed its movement.
This is a non-waiting command and allows the next command to run without delay.
Returns: True
if the motor has completed its movement. False
if it has not.
motor.set_max_torque()#
The motor.set_max_torque(value, units)
command sets the maximum torque the motor will use.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
value |
The new maximum torque to use. |
units |
A valid TorqueUnit, |
Returns: None.
# set maximum torque to 2 Newton Meters
motor1.set_max_torque(2, TorqueUnits.NM)
motor.direction()#
The motor.direction()
command returns the current direction the motor is spinning in.
This is a non-waiting command and allows the next command to run without delay.
Returns: The current DirectionType the motor is spinning in.
motor.position()#
The motor.position(units)
command returns the position of the motor.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
units |
Optional. A valid RotationUnit. The default is |
Returns: The current position of the motor in the specified units.
motor.velocity()#
The motor.velocity(units)
command returns the velocity of the motor.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
units |
Optional. A valid VelocityUnit. The default is |
Returns: The current velocity of the motor in the specified units.
motor.current()#
The motor.current(units)
command returns the current the motor is using.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
units |
Optional. The only valid unit for current is |
Returns: The current being drawn by the motor in the specified units.
motor.power()#
The motor.power(units)
command returns the power the motor is providing.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
units |
Optional. The only valid unit for power is |
Returns: The power being consumed by the motor in the specified units.
motor.torque()#
The motor.torque(units)
command returns the torque the motor is providing.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
units |
Optional. A valid TorqueUnit. The default is |
Returns: The torque being generated by the motor in the specified units.
motor.efficiency()#
The motor.efficiency(units)
command returns the efficiency of the motor.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
units |
Optional. The only valid unit for efficiency is |
Returns: The efficiency of the motor as a percent.
motor.temperature()#
The motor.temperature(units)
command returns the temperature of the motor.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
units |
Optional. A valid TemperatureUnits. The default is |
Returns: The temperature of the motor in the specified units.
motor.command()#
The motor.command(units)
command returns the last velocity sent to the motor.
This is a non-waiting command and allows the next command to run without delay.
Parameters |
Description |
---|---|
units |
Optional. A valid VelocityUnit. The default is |
Returns: The motor command velocity in the specified units.
motor.installed()#
The motor.installed()
command checks for device connection.
This is a non-waiting command and allows the next command to run without delay.
Returns: True or False.
# Check if the motor is installed.
is_installed = motor_1.installed()
motor.timestamp()#
The motor.timestamp()
command requests the timestamp of the last received status packet.
This is a non-waiting command and allows the next command to run without delay.
Returns: Timestamp of the last status packet in milliseconds.
# Get the timestamp of the last received status packet from the motor.
timestamp = motor_1.timestamp()