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 |
|---|---|
|
A valid |
|
Optional. Spin the motor using this velocity. The default velocity set by |
|
Optional. A valid |
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 |
|---|---|
|
The position to spin the motor to. |
|
Optional. A valid |
|
Optional. The velocity with which the motor will spin. The default velocity set by |
|
Optional. A valid |
|
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 |
|---|---|
|
A valid |
|
The value for the motor to spin to. |
|
Optional. A valid |
|
Optional. The velocity with which the motor will spin. The default velocity set by |
|
Optional. A valid |
|
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 |
|---|---|
|
The new velocity. |
|
Optional. A valid |
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 |
|---|---|
|
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 |
|---|---|
|
A valid |
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 |
|---|---|
|
The new position. |
|
Optional. A valid |
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 |
|---|---|
|
The new timeout. |
|
Optional. A valid |
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 |
|---|---|
|
The new maximum torque to use. |
|
A valid |
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 |
|---|---|
|
Optional. A valid |
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 |
|---|---|
|
Optional. A valid |
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 |
|---|---|
|
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 |
|---|---|
|
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 |
|---|---|
|
Optional. A valid |
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 |
|---|---|
|
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 |
|---|---|
|
Optional. A valid |
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 |
|---|---|
|
Optional. A valid |
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()