Service_SPIKE.Motor

Motor

Example

// Initialize the Motor
var motor = new serviceSPIKE.Motor("A")

Methods

inner get_speed() → {number}

Get current speed of the motor

Returns:
number -

speed of motor [-100 to 100]

inner get_position() → {number}

Get current position of the motor. The position may differ by a little margin from the position to which a motor ran with run_to_position()

Returns:
number -

position of motor [0 to 359]

inner get_degrees_counted() → {number}

Get current degrees counted of the motor

Returns:
number -

counted degrees of the motor [any number]

inner get_power() → {number}

Get the power of the motor

Returns:
number -

motor power

inner get_default_speed() → {number}

Get the default speed of this motor

Returns:
number -

motor default speed [-100 to 100]

inner set_default_speed(speed)

Set the default speed for this motor

Parameters:
Name Type Description
speed number

[-100 to 100]

inner set_stall_detection(boolean)

Turns stall detection on or off. Stall detection senses when a motor has been blocked and can’t move. If stall detection has been enabled and a motor is blocked, the motor will be powered off after two seconds and the current motor command will be interrupted. If stall detection has been disabled, the motor will keep trying to run and programs will “get stuck” until the motor is no longer blocked.

Parameters:
Name Type Description
boolean boolean

true if to detect stall, false otherwise

inner run_to_degrees_counted(degrees, speed, callbackopt)

Runs the motor until the number of degrees counted is equal to the value that has been specified by the "degrees" parameter.

Parameters:
Name Type Attributes Description
degrees integer

any number

speed integer

[0 to 100]

callback any <optional>

(optional callback) callback param: "stalled" or "done"

inner start_at_power(power)

Start the motor at some power

Parameters:
Name Type Description
power integer

[-100 to 100]

inner start(speed)

Start the motor at some speed

Parameters:
Name Type Description
speed integer

[-100 to 100]

inner run_for_seconds(seconds, speed, callbackopt)

Run the motor for some seconds

Parameters:
Name Type Attributes Default Description
seconds integer
speed integer

[-100 to 100]

callback function <optional>
=undefined

Parameters:"stalled" or "done"

Example
motor.run_for_seconds(10, 100, function() {
     console.log("motor just ran for 10 seconds");
})

inner run_for_degrees(degrees, speed, callbackopt)

Run the motor for some degrees

Parameters:
Name Type Attributes Default Description
degrees integer
speed integer

[-100 to 100]

callback function <optional>
=undefined

Parameters:"stalled" or "done" motor.run_for_degrees(720, 100, function () { console.log("motor just ran for 720 degrees"); })

inner stop()

Stop the motor