Motor

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. The motor library has various functions that can set the port of the motor, control the motor to run for some specified parameters, and get some data abour the motor. Ranges for velocity vary per motor size as follows: Small motor: -660 to 660, Medium motor: -1110 to 1110, Large motor: -1050 to 1050

GetPort()

Returns

integer
Returns the port number of the motor

Parameters

None

Example

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

SetPort(integer port)

Returns

None

Parameters

  1. 1.integerport

    The port (0 through 5) the motor is attached to and what port number the motor object will be set to

Example

1 2 3 use Libraries.Robots.Spike.Motor Motor wheel wheel:SetPort(0)

GetDutyCycle()

Returns

integer
Returns the current duty cycle (pwm) of the motor

Parameters

None

Example

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

SetDutyCycle(integer pulseWidthModulation)

Returns

None

Parameters

  1. 1.integerpulseWidthModulation

    The pulse width modulation, from -10000 - 10000, that will be used to start this motor with

Example

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

GetRelativePosition()

Returns

integer
Returns the relative position of a motor

Parameters

None

Example

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

SetRelativePosition(integer position)

Returns

None

Parameters

  1. 1.integerposition

    The relative position that will be used to change the position used as an offset for RunToRelativePosition()

Example

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

GetAbsolutePosition()

Returns

integer
Returns the relative position of a motor

Parameters

None

Example

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

Run(integer velocity)

Returns

None

Parameters

  1. 1.integervelocity

    The velocity, in degrees per second, that the motor will be started with.

Example

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

RunForTime(integer time, integer velocity)

Returns

None

Parameters

  1. 1.integertime

    The time, in miliseconds, that the motor will run for with the given velocity.

  2. 2.integervelocity

    The velocity, in degrees per second, that the motor will be started with.

Example

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

RunToDegrees(integer degrees, integer velocity)

Returns

None

Parameters

  1. 1.integerdegrees

    The degrees that the motor will run for with the given velocity.

  2. 2.integervelocity

    The velocity, in degrees per second, that the motor will be started with.

Example

1 2 3 use Libraries.Robots.Spike.Motor Motor wheel wheel:RunToDegrees(720, 90)

RunToRelativePosition(integer position, integer velocity)

Returns

None

Parameters

  1. 1.integerposition

    The position that the motor will use to turn to relative to the current position.

  2. 2.integervelocity

    The velocity, in degrees per second, that the motor will be started with.

Example

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

RunToAbsolutePosition(integer position, integer velocity)

Returns

None

Parameters

  1. 1.integerposition

    The absolute position that the motor will use to turn to.

  2. 2.integervelocity

    The velocity, in degrees per second, that the motor will be started with.

Example

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

Stop()

Returns

None
Is used to stop the motor from running.

Parameters

None

Example

1 2 3 4 5 6 7 use Libraries.Robots.Spike.Motor use Libraries.Robots.Spike.Hub Motor wheel Hub hb wheel:Run(360) hb:Sleep(1000) wheel:Stop()

GetVelocity(integer position, integer velocity)

Returns

integer
Returns the velocity in degrees/second of the motor

Parameters

None

Example

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