Libraries.Robots.Spike.MotorPair Documentation

A motor pair represents a grouping of two motors, which are external devices that connect to the hub on separate ports. Using a motor pair makes it easy to synchronize movements between two motors at the same time, such as the wheels on a car. Up to 3 different motor pairs are supported at one time (PAIR_1, PAIR_2, and PAIR_3).

Example Code

use Libraries.Robots.Spike.Port
use Libraries.Robots.Spike.MotorPair
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:Run(0, 360, 5400)

Inherits from: Libraries.Language.Object

Variables Table

VariablesDescription
integer PAIR_3Returns the pair of this MotorPair, either PAIR_1, PAIR_2, or PAIR_3
integer PAIR_2
integer PAIR_1

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetPair()

Returns the pair of this MotorPair, either PAIR_1, PAIR_2, or PAIR_3

Return

integer: pair number

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
integer wheelsPair = wheels:GetPair()

RemovePorts()

Removes a pairing for the two currently assigned motor ports

Example

use Libraries.Robots.Spike.MotorPair
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RemovePorts()
wheels:SetPorts(port:C, port:D)

Run(integer steering, integer velocity, integer acceleration)

Runs the motors for this motor pair with the provided steering, velocity, and acceleration values Velocity ranges vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050 Acceleration ranges from 0 to 10000

Parameters

  • integer steering: The steering value for the motor pair, in the range -100 to 100
  • integer velocity: The velocity of the motors in degrees/sec
  • integer acceleration: The acceleration of the motors in degrees/sec^2

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:Run(0, 360, 5400)

Run(integer steering)

Runs the motors for this motor pair with the provided steering amount

Parameters

  • integer steering: The steering value for the motor pair, in the range -100 to 100

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:Run(0)

RunForDegrees(integer steering, integer degrees)

Runs the motors for this motor pair with the provided steering value for the provided rotation, in degrees

Parameters

  • integer steering: The steering value for the motor pair, in the range -100 to 100
  • integer degrees: The number of degrees to rotate the motors

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RunForDegrees(0, 720)

RunForDegrees(integer steering, integer degrees, integer velocity, integer brakingMode, integer acceleration, integer deceleration)

Runs the motors for this motor pair a provided number of degrees with the provided values Velocity ranges vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050 Acceleration and deceleration range from 0 to 10000 Available braking modes, as Motor constants, are: COAST, BRAKE, HOLD, CONTINUE, SMART_COAST, or SMART_BRAKE

Parameters

  • integer steering: The steering value for the motor pair, in the range -100 to 100
  • integer degrees: The number of degrees to rotate the motors
  • integer velocity: The velocity of the motors in degrees/sec
  • integer brakingMode: The braking mode to use when stopping the motor
  • integer acceleration: The acceleration of the motors in degrees/sec^2
  • integer deceleration: The deceleration of the motors in degrees/sec^2

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Motor
use Libraries.Robots.Spike.Port
Port port
Motor motor
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RunForDegrees(0, 720, 360, motor:BRAKE, 5400, 5400)

RunForTime(integer steering, integer duration)

Runs the motors for this motor pair with the provided steering value for the provided duration, in milliseconds

Parameters

  • integer steering: The steering value for the motor pair, in the range -100 to 100
  • integer duration: The number of milliseconds to run the motors for

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RunForTime(0, 2000)

RunForTime(integer steering, integer duration, integer velocity, integer brakingMode, integer acceleration, integer deceleration)

Runs the motors for this motor pair for a given time, in milliseconds, with the provided values Velocity ranges vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050 Acceleration and deceleration range from 0 to 10000 Available braking modes, as Motor constants, are: COAST, BRAKE, HOLD, CONTINUE, SMART_COAST, or SMART_BRAKE

Parameters

  • integer steering: The steering value for the motor pair, in the range -100 to 100
  • integer duration: The number of milliseconds to run the motors for
  • integer velocity: The velocity of the motors in degrees/sec
  • integer brakingMode: The braking mode to use when stopping the motor
  • integer acceleration: The acceleration of the motors in degrees/sec^2
  • integer deceleration: The deceleration of the motors in degrees/sec^2

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Motor
use Libraries.Robots.Spike.Port
Port port
Motor motor
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RunForTime(0, 2000, 360, motor:BRAKE, 5400, 5400)

RunTank(integer leftVelocity, integer rightVelocity, integer acceleration)

Runs the left and right motors with the provided velocities and acceleration Velocity ranges vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050 Acceleration and deceleration range from 0 to 10000

Parameters

  • integer leftVelocity: The velocity of the left motor in degrees/sec
  • integer rightVelocity: The velocity of the left motor in degrees/sec
  • integer acceleration: The acceleration of the motors in degrees/sec^2

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RunTank(360, 360, 5400)

RunTankForDegrees(integer leftVelocity, integer rightVelocity, integer degrees, integer brakingMode, integer acceleration, integer deceleration)

Runs the left and right motors for the given degrees with the provided values Velocity ranges vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050 Acceleration and deceleration range from 0 to 10000 Available braking modes, as Motor constants, are: COAST, BRAKE, HOLD, CONTINUE, SMART_COAST, or SMART_BRAKE

Parameters

  • integer leftVelocity: The velocity of the left motor in degrees/sec
  • integer rightVelocity: The velocity of the left motor in degrees/sec
  • integer degrees: The number of degrees to turn each motor
  • integer brakingMode: The braking mode to use when stopping the motor
  • integer acceleration: The acceleration of the motors in degrees/sec^2
  • integer deceleration: The deceleration of the motors in degrees/sec^2

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Motor
use Libraries.Robots.Spike.Port
Port port
Motor motor
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RunTankForDegrees(360, 360, 720, motor:BRAKE, 5400, 5400)

RunTankForDegrees(integer leftVelocity, integer rightVelocity, integer degrees)

Runs the left and right motors for the given degrees with the provided velocities Velocity ranges vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050

Parameters

  • integer leftVelocity: The velocity of the left motor in degrees/sec
  • integer rightVelocity: The velocity of the left motor in degrees/sec
  • integer degrees: The number of degrees to turn each motor

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RunTankForDegrees(360, 360, 720)

RunTankForTime(integer leftVelocity, integer rightVelocity, integer duration, integer brakingMode, integer acceleration, integer deceleration)

Runs the left and right motors for the given time, in milliseconds, with the provided values Velocity ranges vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050 Acceleration and deceleration range from 0 to 10000 Available braking modes, as Motor constants, are: COAST, BRAKE, HOLD, CONTINUE, SMART_COAST, or SMART_BRAKE

Parameters

  • integer leftVelocity: The velocity of the left motor in degrees/sec
  • integer rightVelocity: The velocity of the left motor in degrees/sec
  • integer duration: The number of milliseconds to run the motors for
  • integer brakingMode: The braking mode to use when stopping the motor
  • integer acceleration: The acceleration of the motors in degrees/sec^2
  • integer deceleration: The deceleration of the motors in degrees/sec^2

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Motor
use Libraries.Robots.Spike.Port
Port port
Motor motor
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RunTankForTime(360, 360, 2000, motor:BRAKE, 5400, 5400)

RunTankForTime(integer leftVelocity, integer rightVelocity, integer duration)

Runs the left and right motors for the given time, in milliseconds, with the provided velocities Velocity ranges vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050

Parameters

  • integer leftVelocity: The velocity of the left motor in degrees/sec
  • integer rightVelocity: The velocity of the left motor in degrees/sec
  • integer duration: The number of milliseconds to run the motors for

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:RunTankForTime(360, 360, 2000)

SetPair(integer pair)

Set the pair for this MotorPair to either PAIR_1, PAIR_2, or PAIR_3

Parameters

  • integer pair: The pair to set this MotorPair to (either PAIR_1, PAIR_2, or PAIR_3)

Example

use Libraries.Robots.Spike.MotorPair
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)

SetPorts(integer leftMotorPort, integer rightMotorPort)

Registers the currently set pair to two motor ports

Parameters

  • integer leftMotorPort: The port (A-F) to use for the left motor
  • integer rightMotorPort: The port (A-F) to use for the right motor

Example

use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)

Stop()

Stops the motor pair from running with the default braking mode

Example

use Libraries.Robots.Spike.Hub
use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Port
Hub hb
Port port
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:Run(0)
hb:Sleep(1000)
wheels:Stop()

Stop(integer brakingMode)

Stops the motor pair from running with the provided braking mode Available braking modes, as Motor constants, are: COAST, BRAKE, HOLD, CONTINUE, SMART_COAST, or SMART_BRAKE

Parameters

  • integer brakingMode: The braking mode to use when stopping the motor

Example

use Libraries.Robots.Spike.Hub
use Libraries.Robots.Spike.MotorPair
use Libraries.Robots.Spike.Motor
use Libraries.Robots.Spike.Port
Hub hb
Port port
Motor motor
MotorPair wheels
wheels:SetPair(wheels:PAIR_1)
wheels:SetPorts(port:A, port:B)
wheels:Run(0)
hb:Sleep(1000)
wheels:Stop(motor:BRAKE)