Motor

Package: Libraries.Robots.Spike · Inherits from: Libraries.Language.Object

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)

Variables

  • integer CONTINUE
  • integer CLOCKWISE: Constants for rotation directions
  • integer SHORTEST_PATH
  • integer BRAKE
  • integer COUNTERCLOCKWISE
  • integer COAST: Constants for different braking modes
  • integer SMART_COAST
  • integer LONGEST_PATH: Returns the port number of the motor
  • integer SMART_BRAKE: Constants for rotation directions
  • integer HOLD

Actions

GetAbsolutePosition()

Returns the absolute position of a motor

Returns

integer

Example

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

GetDutyCycle()

Returns the current duty cycle (pwm) of the motor

Returns

integer: PWM, the pwm of the motor

Example

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

GetPort()

Returns the port number of the motor

Returns

integer: Port number

Example

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

GetRelativePosition()

Returns the relative position of a motor

Returns

integer

Example

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

GetVelocity()

Returns the velocity in degrees/second of the motor

Returns

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

  • velocity integer: The velocity to set the motor to in degrees/second
  • acceleration integer: 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

  • velocity integer: 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

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

  • degrees integer: The amount of degrees to run for
  • velocity integer: 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

  • time integer: The amount of time to run for in milliseconds
  • velocity integer: 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

  • time integer: The amount of time to run for in milliseconds
  • velocity integer: The velocity in degrees/second
  • brakingMode integer: The braking mode to use when stopping the motor
  • acceleration integer: The acceleration of the motor in degrees/sec^2
  • deceleration integer: 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

  • position integer: The absolute position to run to
  • velocity integer: The velocity in degrees/second
  • direction integer: The direction to turn the motor
  • brakingMode integer: The braking mode to use when stopping the motor
  • acceleration integer: The acceleration of the motor in degrees/sec^2
  • deceleration integer: 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

  • position integer: The absolute position to run to
  • velocity integer: 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

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

  • position integer: The relative position to run to
  • velocity integer: 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

  • pulseWidthModulation integer: 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

  • port integer: 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

  • position integer: 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

  • brakingMode integer: 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)

Inherited Actions

3 actions from Libraries.Language.Object