Libraries.Robots.Spike.Motor Documentation

The motor is an external device that is connected to the hub through a port. It is a rotational device that can be attached to other objects to provide force.

Example Code

use Libraries.Robots.Spike.Motor
use Libraries.Robots.Spike.Port
Motor wheel
Port port
wheel:SetPort(port:A)
wheel:Run(360)

Inherits from: Libraries.Language.Object

Variables Table

VariablesDescription
integer SMART_COAST
integer COASTConstants for different braking modes
integer CLOCKWISEConstants for rotation directions
integer HOLD
integer SMART_BRAKEConstants for rotation directions
integer COUNTERCLOCKWISE
integer CONTINUE
integer SHORTEST_PATH
integer LONGEST_PATHReturns the port number of the motor
integer BRAKE

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)

GetAbsolutePosition()

Returns the absolute position of a motor

Return

integer:

Example

use Libraries.Robots.Spike.Motor
Motor wheel
integer currentAbsoluteWheelPosition = wheel:GetAbsolutePosition()

GetDutyCycle()

Returns the current duty cycle (pwm) of the motor

Return

integer: PWM, the pwm of the motor

Example

use Libraries.Robots.Spike.Motor
Motor wheel
integer currentPWM = wheel:GetDutyCyle()

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()

GetPort()

Returns the port number of the motor

Return

integer: Port number

Example

use Libraries.Robots.Spike.Motor
Motor wheel
integer wheelPort = wheel:GetPort()

GetRelativePosition()

Returns the relative position of a motor

Return

integer:

Example

use Libraries.Robots.Spike.Motor
Motor wheel
integer currentRelativeWheelPosition = wheel:GetRelativePosition()

GetVelocity()

Returns the velocity in degrees/second of the motor

Return

integer: Velocity, the velocity in degrees/second of the motor

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:Run(360)
integer currentVelocity = wheel:GetVelocity()

Run(integer velocity, integer acceleration)

Sets the velocity of the motor in degrees/sec by applying the provided acceleration. Ranges for velocity 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 velocity: The velocity to set the motor to in degrees/second
  • integer acceleration: The acceleration of the motor in degrees/sec^2

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:Run(90, 5000)

Run(integer velocity)

Sets the velocity of the motor in degrees/sec. Ranges for velocity vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050

Parameters

  • integer velocity: The velocity to set the motor to in degrees/second

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:Run(90)

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

Runs the motor for a certain number of degrees at the provided velocity with additional parameters. Ranges for velocity 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 degrees: The amount of degrees to run for
  • integer velocity: The velocity in degrees/second
  • integer brakingMode: The braking mode to use when stopping the motor
  • integer acceleration: The acceleration of the motor in degrees/sec^2
  • integer deceleration: The deceleration of the motor in degrees/sec^2

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:RunForDegrees(720, 90, wheel:BRAKE, 5000, 5000)

RunForDegrees(integer degrees, integer velocity)

Runs the motor for a certain number of degrees at the provided velocity. Ranges for velocity vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050

Parameters

  • integer degrees: The amount of degrees to run for
  • integer velocity: The velocity in degrees/second

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:RunForDegrees(720, 90)

RunForTime(integer time, integer velocity)

Runs the motor for a set amount of time at the provided velocity. Ranges for velocity vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050

Parameters

  • integer time: The amount of time to run for in milliseconds
  • integer velocity: The velocity in degrees/second

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:RunForTime(2000, 360)

RunForTime(integer time, integer velocity, integer brakingMode, integer acceleration, integer deceleration)

Runs the motor for a set amount of time at the provided velocity with additional parameters. Ranges for velocity 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 time: The amount of time to run for in milliseconds
  • integer velocity: The velocity in degrees/second
  • integer brakingMode: The braking mode to use when stopping the motor
  • integer acceleration: The acceleration of the motor in degrees/sec^2
  • integer deceleration: The deceleration of the motor in degrees/sec^2

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:RunForTime(2000, 360, wheel:BRAKE, 5000, 5000)

RunToAbsolutePosition(integer position, integer velocity, integer direction, integer brakingMode, integer acceleration, integer deceleration)

Turns the motor to a provided absolute position at the provided velocity with additional parameters. Ranges for velocity 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 Available directions, as Motor constants, are: CLOCKWISE, COUNTERCLOCKWISE, SHORTEST_PATH, LONGEST_PATH

Parameters

  • integer position: The absolute position to run to
  • integer velocity: The velocity in degrees/second
  • integer direction: The direction to turn the motor
  • integer brakingMode: The braking mode to use when stopping the motor
  • integer acceleration: The acceleration of the motor in degrees/sec^2
  • integer deceleration: The deceleration of the motor in degrees/sec^2

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:RunToAbsolutePosition(120, 360, wheel:SHORTEST_PATH, wheel:BRAKE, 5000, 5000)

RunToAbsolutePosition(integer position, integer velocity)

Turns the motor to a provided absolute position at the provided velocity. Ranges for velocity vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050

Parameters

  • integer position: The absolute position to run to
  • integer velocity: The velocity in degrees/second

Example


use Libraries.Robots.Spike.Motor
Motor wheel
wheel:RunToAbsolutePosition(1200, 360)

RunToRelativePosition(integer position, integer velocity, integer brakingMode, integer acceleration, integer deceleration)

Turns the motor to a position relative to current position. Ranges for velocity 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 position: The relative position to run to
  • integer velocity: The velocity in degrees/second
  • integer brakingMode: The braking mode to use when stopping the motor
  • integer acceleration: The acceleration of the motor in degrees/sec^2
  • integer deceleration: The deceleration of the motor in degrees/sec^2

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:RunToRelativePosition(360, 360, wheel:BRAKE, 5000, 5000)

RunToRelativePosition(integer position, integer velocity)

Turns the motor to a position relative to current position. Ranges for velocity vary per motor size as follows: Small motor: -660 to 660 Medium motor: -1110 to 1110 Large motor: -1050 to 1050

Parameters

  • integer position: The relative position to run to
  • integer velocity: The velocity in degrees/second

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:RunToRelativePosition(360, 360)

SetDutyCycle(integer pulseWidthModulation)

Starts a motor using a specific pulse width modulation

Parameters

  • integer pulseWidthModulation: The pwm from -10000 - 10000

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:SetDutyCycle(5000)

SetPort(integer port)

Sets the port number of the motor object

Parameters

  • integer port: The port (A through F, or 0 through 5) the motor is attached to

Example

use Libraries.Robots.Spike.Motor
use Libraries.Robots.Spike.Port
Motor wheel
Port port
wheel:SetPort(port:A)

SetRelativePosition(integer position)

Changes the position used as an offset for RunToRelativePosition()

Parameters

  • integer position: The relative position to use

Example

use Libraries.Robots.Spike.Motor
Motor wheel
wheel:SetRelativePosition(90)

Stop()

Stops the motor from running

Example

use Libraries.Robots.Spike.Motor
use Libraries.Robots.Spike.Hub
Motor wheel
Hub hb
wheel:Run(360)
hb:Sleep(1000)
wheel:Stop()

Stop(integer brakingMode)

Stops the motor from running with the provided braking mode Available braking modes 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.Motor
use Libraries.Robots.Spike.Hub
Motor wheel
Hub hb
wheel:Run(360)
hb:Sleep(1000)
wheel:Stop(wheel:BRAKE)