Motor
This file contains procedures to control EV3 or Powered Up motors.
Constants
The motor module.
Source: lib/modules/motor.whl, line: 10
Module calls to control the motors.
Source: lib/modules/motor.whl, line: 13
MOTOR_SET_TYPE | 0 |
MOTOR_SET_SPEED | 1 |
MOTOR_SET_BRAKE | 2 |
MOTOR_GET_TYPE | 3 |
MOTOR_RESET | 4 |
MOTOR_REVERSE | 5 |
MOTOR_MOVE_TO | 6 |
MOTOR_MOVE_TO_BITS | 7 |
MOTOR_ON | 8 |
MOTOR_TIME_ON | 9 |
MOTOR_STOP | 10 |
MOTOR_READ | 11 |
MOTOR_READY | 12 |
MOTOR_READY_BITS | 13 |
MOTOR_THRESHOLD | 14 |
Motor types.
Source: lib/modules/motor.whl, line: 30
MOTOR_MEDIUM | 7 |
MOTOR_LARGE | 8 |
The motor outputs, OUTPUT_E and OUTPUT_F can only be used for Spike.
Source: lib/modules/motor.whl, line: 34
OUTPUT_A | 0 |
OUTPUT_B | 1 |
OUTPUT_C | 2 |
OUTPUT_D | 3 |
OUTPUT_E | 4 |
OUTPUT_F | 5 |
Bits to identify the motor combinations for ready or to move multiple motors to a given position.
Source: lib/modules/motor.whl, line: 42
MOTOR_BITS_A | 0b0001 |
MOTOR_BITS_B | 0b0010 |
MOTOR_BITS_AB | 0b0011 |
MOTOR_BITS_C | 0b0100 |
MOTOR_BITS_AC | 0b0101 |
MOTOR_BITS_BC | 0b0110 |
MOTOR_BITS_ABC | 0b0111 |
MOTOR_BITS_D | 0b1000 |
MOTOR_BITS_AD | 0b1001 |
MOTOR_BITS_BD | 0b1010 |
MOTOR_BITS_ABD | 0b1011 |
MOTOR_BITS_CD | 0b1100 |
MOTOR_BITS_ACD | 0b1101 |
MOTOR_BITS_BCD | 0b1110 |
MOTOR_BITS_ABCD | 0b1111 |
Brake or coast the motor.
Source: lib/modules/motor.whl, line: 59
MOTOR_COAST | 0 |
MOTOR_BRAKE | 1 |
Procedures
motorLayerSetType
Source: lib/modules/motor.whl, line: 63
Set the motor type.
proc motorLayerSetType(number layer, number id, number type)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
type | number | The type of motor: MOTOR_MEDIUM or MOTOR_LARGE. |
motorLayerSetSpeed
Source: lib/modules/motor.whl, line: 72
Set the motor speed.
proc motorLayerSetSpeed(number layer, number id, number speed)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
speed | number | The speed of the motor. The value must be between -100 and 100 where negative values mean a reverse direction. |
motorLayerSetBrake
Source: lib/modules/motor.whl, line: 81
Set the motor brake or coast: 0 = coast, 1 = brake. The default value is 1 (brake).
proc motorLayerSetBrake(number layer, number id, number brake)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
brake | number | |
motorLayerGetType
Source: lib/modules/motor.whl, line: 89
Get the connected motor type.
proc motorLayerGetType(number layer, number id)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorLayerReset
Source: lib/modules/motor.whl, line: 97
Reset the tacho count for the motor.
proc motorLayerReset(number layer, number id)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorLayerReverse
Source: lib/modules/motor.whl, line: 105
Reverse the motor move to direction.
proc motorLayerReverse(number layer, number id)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorLayerMoveTo
Source: lib/modules/motor.whl, line: 113
Move the motor to a given target angle.
proc motorLayerMoveTo(number layer, number id, number target)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
target | number | The target angle. |
motorLayerMoveToBits
Source: lib/modules/motor.whl, line: 122
Move the motors to a given target angle. This procedure is not implemented in the EV3 VM.
proc motorLayerMoveToBits(number layer, number bits, number target)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
bits | number | The motor bits, the first bit is motor A, the second motor B, etc. Checking motor A and C: 0b0101 |
target | number | The target angle. |
motorLayerOn
Source: lib/modules/motor.whl, line: 131
Turn the motor on.
proc motorLayerOn(number layer, number id)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorLayerTimeOn
Source: lib/modules/motor.whl, line: 139
Turn the motor on for a given time.
proc motorLayerTimeOn(number layer, number id, number time)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
time | number | Time in milliseconds. |
motorLayerStop
Source: lib/modules/motor.whl, line: 148
Stop the motor.
proc motorLayerStop(number layer, number id)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorLayerRead
Source: lib/modules/motor.whl, line: 156
Read a motor position.
proc motorLayerRead(number layer, number id)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
Return: The current motor position in degrees.
motorLayerReady
Source: lib/modules/motor.whl, line: 165
Check if a motor reached its target.
proc motorLayerReady(number layer, number id)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorLayerReadyBits
Source: lib/modules/motor.whl, line: 173
Check if one or more motors reached their target.
proc motorLayerReadyBits(number layer, number bits)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
bits | number | The motor bits, the first bit is motor A, the second motor B, etc. Checking motor A and C: 0b0101 |
motorLayerThreshold
Source: lib/modules/motor.whl, line: 181
Set the threshold for the motor to reach the given angle, this proc only applies to Powered Up.
proc motorLayerThreshold(number layer, number id, number threshold)
Parameters:
Name | Type | Description |
layer | number | The layer, the daisy chained device. 0 is the primary brick. |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
threshold | number | The threshold, if the difference in degrees between the motor target and position is less
than this value then the motor ready status returns TRUE. |
motorSetType
Source: lib/modules/motor.whl, line: 191
Set the motor type for the main device.
proc motorSetType(number id, number type)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
type | number | The type of motor: MOTOR_MEDIUM or MOTOR_LARGE. |
motorSetSpeed
Source: lib/modules/motor.whl, line: 198
Set the motor speed for the main device.
proc motorSetSpeed(number id, number speed)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
speed | number | The speed of the motor. The value must be between -100 and 100 where negative values mean a reverse direction. |
motorSetBrake
Source: lib/modules/motor.whl, line: 205
Set the motor brake or coast for the main device: 0 = coast, 1 = brake. The default value is 1 (brake).
proc motorSetBrake(number id, number brake)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
brake | number | |
motorGetType
Source: lib/modules/motor.whl, line: 211
Get the connected motor type.
proc motorGetType(number id)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
Return: The type of motor connected to the primary device.
motorReset
Source: lib/modules/motor.whl, line: 218
Reset the tacho count for the motor for the main device.
proc motorReset(number id)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorReverse
Source: lib/modules/motor.whl, line: 224
Reverse the motor move to direction.
proc motorReverse(number layer, number id)
Parameters:
Name | Type | Description |
layer | number | |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorMoveTo
Source: lib/modules/motor.whl, line: 230
Move the motor to a given target angle for the main device.
proc motorMoveTo(number id, number target)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
target | number | The target angle. |
motorMoveToBits
Source: lib/modules/motor.whl, line: 237
Move the motor to a given target angle. This procedure is not implemented in the EV3 VM.
proc motorMoveToBits(number bits, number target)
Parameters:
Name | Type | Description |
bits | number | The motor bits, the first bit is motor A, the second motor B, etc. Checking motor A and C: 0b0101 |
target | number | The target angle. |
motorTimeOn
Source: lib/modules/motor.whl, line: 244
Turn the motor of the main device on for a given time.
proc motorTimeOn(number id, number time)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
time | number | Time in milliseconds. |
motorStop
Source: lib/modules/motor.whl, line: 251
Stop the motor on the main device.
proc motorStop(number id)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorRead
Source: lib/modules/motor.whl, line: 257
Read a motor position on the main device.
proc motorRead(number id)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
Return: The current motor position in degrees.
motorReady
Source: lib/modules/motor.whl, line: 264
Check if a motor on the main device reached its target.
proc motorReady(number id)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
motorReadyBits
Source: lib/modules/motor.whl, line: 270
Check if one or more motors reached their target.
proc motorReadyBits(number bits)
Parameters:
Name | Type | Description |
bits | number | The motor bits, the first bit is motor A, the second motor B, etc. Checking motor A and C: 0b0101 |
motorThreshold
Source: lib/modules/motor.whl, line: 277
Set the threshold for the motor to reach the given angle, this proc only applies to Powered Up.
proc motorThreshold(number id, number threshold)
Parameters:
Name | Type | Description |
id | number | The output, the first output is 0. Constants: OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D. |
threshold | number | The threshold, if the difference in degrees between the motor target and position is less
than this value then the motor ready status returns TRUE. |
waitForMotors
Source: lib/modules/motor.whl, line: 285
Wait until the given motors have reached their targets.
proc waitForMotors(number bits)
Parameters:
Name | Type | Description |
bits | number | The motor bits, the first bit is motor A, the second motor B, etc. Checking motor A and C: 0b0101 |