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 CONTINUEinteger CLOCKWISE: Constants for rotation directionsinteger SHORTEST_PATHinteger BRAKEinteger COUNTERCLOCKWISEinteger COAST: Constants for different braking modesinteger SMART_COASTinteger LONGEST_PATH: Returns the port number of the motorinteger SMART_BRAKE: Constants for rotation directionsinteger 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
velocityinteger: The velocity to set the motor to in degrees/secondaccelerationinteger: 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
velocityinteger: 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
degreesinteger: The amount of degrees to run forvelocityinteger: The velocity in degrees/secondbrakingModeinteger: The braking mode to use when stopping the motoraccelerationinteger: The acceleration of the motor in degrees/sec^2decelerationinteger: 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
degreesinteger: The amount of degrees to run forvelocityinteger: 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
timeinteger: The amount of time to run for in millisecondsvelocityinteger: 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
timeinteger: The amount of time to run for in millisecondsvelocityinteger: The velocity in degrees/secondbrakingModeinteger: The braking mode to use when stopping the motoraccelerationinteger: The acceleration of the motor in degrees/sec^2decelerationinteger: 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
positioninteger: The absolute position to run tovelocityinteger: The velocity in degrees/seconddirectioninteger: The direction to turn the motorbrakingModeinteger: The braking mode to use when stopping the motoraccelerationinteger: The acceleration of the motor in degrees/sec^2decelerationinteger: 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
positioninteger: The absolute position to run tovelocityinteger: 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
positioninteger: The relative position to run tovelocityinteger: The velocity in degrees/secondbrakingModeinteger: The braking mode to use when stopping the motoraccelerationinteger: The acceleration of the motor in degrees/sec^2decelerationinteger: 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
positioninteger: The relative position to run tovelocityinteger: 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
pulseWidthModulationinteger: 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
portinteger: 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
positioninteger: 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
brakingModeinteger: 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)