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 Constructor#

A V5 Motor can be instantiated in different ways using one of the following constructors:

  • motor Motor1 = motor(int32_t index, bool reverse);

    • index = the SmartPort the Motor is connected to.

    • reverse = a boolean to keep or reverse the direction the motor spins.

  • motor Motor1 = motor(int32_t index, gearSetting gears);

    • index = the SmartPort the Motor is connected to.

    • gears = the gear ratio of the Motor Cartridge.

  • motor Motor1 = motor(int32_t index, gearSetting gears, bool reverse);

    • index = the SmartPort the Motor is connected to.

    • gears = the gear ratio of the Motor Cartridge.

    • reverse = a boolean to keep or reverse the direction the motor spins.

// Construct a V5 Motor that runs in reverse.
motor Motor1 = motor(PORT1, true);

// Construct a V5 Motor with a 6:1 Turbo Gear Cartridge.
motor Motor1 = motor(PORT1, ratio6_1);

// Construct a V5 Motor with a 36:1 Torque Gear Cartridge
// that runs in reverse.
motor Motor1 = motor(PORT1, ratio36_1, true);

Motor.spin()#

The Motor.spin(direction, velocity, units) command is used to spin a Motor in the specified direction forever, until another motion command is used, or the project is stopped.

To use this command, replace Motor with the desired Motor, for example: armMotor.spin(direction, velocity, units).

This is a non-waiting function and allows the next command 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 Motor.setVelocity() command will be used.

units

Optional. A valid velocityUnit. The default is rpm.

Returns: None.

// Spin Motor forward.
Motor1.spin(forward);

Motor.spinToPosition()#

The Motor.spinToPosition(rotation, units, velocity, units_v, wait) command is used to spin a Motor to an absolute position using the provided arguments.

To use this command, replace Motor with the desired Motor, for example: armMotor.spinToPosition(rotation, units, velocity, units_v, wait).

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 rotationUnit. The default is degrees.

velocity

Optional. The velocity with which the Motor will spin. The default velocity set by the Motor.setVelocity() command will be used.

units_v

Optional. A valid velocityUnit. The default is rpm.

wait

Optional. Determines whether the command will block subsequent commands (wait=true) or allow immediate execution (wait=false). If unspecified, the default for The wait parameter is wait=true.

Returns: None.

// Spin Motor to 180 degrees.
Motor1.spinToPosition(180);

Motor.spinFor()#

The Motor.spinFor(direction, value, units, velocity, units_v, wait) command 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.

To use this command, replace Motor with the desired Motor, for example: armMotor.spinFor(direction, value, units, velocity, units_v, wait).

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 rotationUnit. The default is degrees.

velocity

Optional. The velocity with which the Motor will spin. The default velocity set by the Motor.setVelocity() command will be used.

units_v

Optional. A valid velocityUnit. The default is rpm.

wait

Optional. Determines whether the command will block subsequent commands (wait=true) or allow immediate execution (wait=false). If unspecified, the default for The wait parameter is wait=true.

Returns: None.

// Spin 180 degrees from the current position.
Motor1.spinFor(forward, 180);

Motor.stop()#

The Motor.stop(mode) command is used to stop a Motor, setting them to 0 velocity and configuring the current stopping mode.

To use this command, replace Motor with the desired Motor, for example: armMotor.stop(mode).

This is a non-waiting command and allows the next command to run without delay.

Parameters

Description

mode

Optional. A valid brakeType. The default is coast, unless previously changed using the Motor.setStopping() command.

Returns: None.

// Stop the Motor.
Motor.stop();

Motor.setVelocity()#

The Motor.setVelocity(velocity, units) command 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.

To use this command, replace Motor with the desired Motor, for example: armMotor.setVelocity(velocity, units).

This is a non-waiting command and allows the next command to run without delay.

Parameters

Description

velocity

The new velocity to set for the Motor.

units

Optional. A valid velocityUnit. The default is rpm.

Returns: None.

Motor.setReversed()#

The Motor.setReversed(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.setStopping()#

The Motor.setStopping(mode) command is used to set the stopping mode for a Motor.

To use this command, replace Motor with the desired Motor, for example: armMotor.setStopping(mode).

This is a non-waiting command and allows the next command to run without delay.

Parameters

Description

mode

Optional. A valid brakeType. The default is coast, unless previously changed using the Motor.setStopping() command.

Returns: None.

Motor.resetPosition()#

The Motor.resetPosition() 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.setPosition()#

The Motor.setPosition(value, units) command is used to set the position of a Motor. The position that is returned by the Motor.position() function will be updated to this new value.

To use this command, replace Motor with the desired Motor, for example: armMotor.setPosition(value, units).

This is a non-waiting command and allows the next command to run without delay.

Parameters

Description

value

The new position to set for the Motor.

units

Optional. A valid rotationUnit. The default is degrees, unless previously changed using the Motor.setPosition() command.

Returns: None.

Motor.setTimeout()#

The Motor.setTimeout(value, units) command is used to set the timeout for a Motor. The position that is returned by the Motor.getTimeout() function will be updated to this new value.

To use this command, replace Motor with the desired Motor, for example: armMotor.setTimeout(value, units).

This is a non-waiting command and allows the next command to run without delay.

Parameters

Description

value

The new timeout to set for the Motor.

units

Optional. A valid timeUnit. The default is msec. unless previously changed using the Motor.setTimeout() command.

Returns: None.

Motor.getTimeout()#

The Motor.getTimeout() command returns the current timeout for a Motor.

To use this command, replace Motor with the desired Motor, for example: armMotor.getTimeout().

This is a non-waiting command and allows the next command to run without delay.

Returns: The current timeout value in milliseconds.

Motor.isSpinning()#

The Motor.isSpinning() 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.isDone()#

The Motor.isDone() 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.setMaxTorque()#

The Motor.setMaxTorque(value, units) command is used to set the maximum torque for a Motor. The torque can be set as torque, current, or a percent of maximum torque.

To use this command, replace Motor with the desired Motor, for example: armMotor.setMaxTorque(value, units).

This is a non-waiting command and allows the next command to run without delay.

Parameters

Description

value

The new maximum torque for a Motor.

units

A valid torqueUnit, amp, or percent.

Returns: None.

// Set maximum torque to 2 Newton Meters.
Motor1.set_max_torque(2, Nm);

Motor.convertVelocity()#

The Motor.convertVelocity(velocity, units, unitsout) command converts the velocity in the given units to specified units based on the Motor gearing.

To use this command, replace Motor with the desired Motor, for example: armMotor.convertVelocity(velocity, units, unitsout).

This is a non-waiting command and allows the next command to run without delay.

Parameters

Description

velocity

The velocity to convert.

units

A valid velocityUnit for the velocity value.

unitsout

Optional. A valid velocityUnit for the returned velocity. The default is rpm.

Returns: Returns the velocity converted to velocity in the specified units.

Motor.getMotorCartridge()#

The Motor.getMotorCartridge() command returns the gear cartridge setting for the Motor.

To use this command, replace Motor with the desired Motor, for example: armMotor.getMotorCartridge().

This is a non-waiting command and allows the next command to run without delay.

Returns: The gear cartridge setting of the Motor.

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 that the Motor is spinning in.

Motor.position()#

The Motor.position(units) command returns the current 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 degrees.

Returns: The current position of the Motor in the specified units.

Motor.velocity()#

The Motor.velocity(units) command returns the current 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 rpm.

Returns: The current velocity of the Motor in the specified units.

Motor.current()#

The Motor.current(units) command returns the current being used by 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 current is amp.

Returns: The current being drawn by the Motor in the specified units.

Motor.power()#

The Motor.power(units) command returns the power being consumed by 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 power is watt.

Returns: The power being consumed by the Motor in the specified units.

Motor.torque()#

The Motor.torque(units) command returns the torque being generated by the Motor.

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

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

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 temperatureUnit. The default is celsius.

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

Returns: The Motor command velocity in the specified units.

Motor.installed()#

The Motor.installed() command checks if the Motor is connected.

This is a non-waiting command and allows the next command to run without delay.

Returns: True if the Motor is connected. False if it is not.

Motor.value()#

The Motor.value() command returns the value of the Motor.

This is a non-waiting command and allows the next command to run without delay.

Returns: An integer representing the value of the Motor.