EV3 - Motor Commands |
There are four motor ports on the EV3 labeled A, B, C, and D. Each motor is equipped with an integrated encoder that can be used to determine the current position of the motor. The encoders have 360 counts per single revolution of the motor. A count of 180 indicates that the motor has traveled half of a rotation. |
Command List |
voidsetMotorSpeed(tMotor nMotorIndex, int nSpeed) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | The function returns no value | void |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
nSpeed | Speed value that will be passed to the motor (-100 to +100). Zero is the value for stopping the motors | int |
Usage: | setMotorSpeed(nMotorIndex, speed); |
Code Example:
|
bool waitUntilMotorStop(tMotor nMotorIndex) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | Function returns a boolean value | bool |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
Usage: | waitUntilMotorStop(nMotorIndex); |
Code Example:
|
voidmoveMotorTarget(tMotor nMotorIndex) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | The function returns no value | void |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
nPosition | Target incremental value that the motor will travel to. | float |
nSpeed | Speed value that will be passed to the motor (-100 to +100). | int |
Usage: | moveMoterTarget(nMotorIndex, nPosition, nSpeed); |
Code Example:
|
voidsetMotorTarget(tMotor nMotorIndex, float nPosition, int nspeed) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | The function returns no value | void |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
nPosition | Target absolute value that the motor will travel to. | float |
nSpeed | Speed value that will be passed to the motor (-100 to +100). | int |
Usage: | setMotorTarget(nMotorIndex, nPosition, nSpeed); |
The port the motor (in servo mode) is plugged into to nMotorIndex.
The set distance to travel specified by nPosition.
The speed, which is specified by nSpeed.
Code Example:
|
floatgetMotorTarget(tMotor nMotorIndex) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | Functions returns a floating point decimal value. | float |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
Usage: | getMotorTarget(nMotorIndex); |
Code Example:
|
voidresetMotorEncoder(tMotor nMotorIndex) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | The function returns no value | void |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
Usage: | resetMotorEncoder(nMotorIndex); |
Code Example:
|
float getMotorEncoder(tMotor nMotorIndex) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | Function returns a floating point decimal value | float |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
Usage: | getMotorEncoder(nMotorIndex); |
Code Example:
|
intgetMotorSpeed(tMotor nMotorIndex) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | Functions returns an integer value. | int |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
Usage: | getMotorSpeed(nMotorIndex); |
Code Example:
|
voidsetMotorReversed(tMotor nMotorIndex, bool bReversed) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | The function returns no value. | void |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
bReversed | Flag set to 1 if a motor is reversed, 0 if it is not | bool |
Usage: | setMotorReversed(nMotorIndex, bReversed); |
Code Example:
|
boolgetServoEncoder(tMotor nMotorIndex) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | Functions returns a floating point decimal value. | float |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
Usage: | getMotorMoving(nMotorIndex) |
Code Example:
|
TMotorBrakeModes getMotorBrakeMode(tMotor nMotorIndex) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | Function returns the brake mode of the motor. | TMotorsBrakeModes |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
Usage: | getMotorBrakeMode(nMotorIndex); |
motorCoast = Coast Mode. Power is removed from the motor when a speed of 0 is applied which allows the motor coast.
motorBrake = Brake Mode. The motor is placed in a Brake mode which will resist rotation when a speed level of 0 is applied but will not return to the original position if the motor is rotated.
motorHold = Hold Mode. The motor is placed in a Hold mode which will resist rotation when a speed level of 0 is applied and will attempt to 'hold' its position by applying a counterforce to any rotational force applied to the motor.
Code Example:
|
voidsetMotorBrakeMode(tMotor nMotorIndex, TMotorBrakeModes modeSetting) | ||
---|---|---|
Parameter | Explanation | Data Type |
Return Type | The function returns no value. | void |
nMotorIndex | Port number that the motor is plugged into. | tMotor |
modeSetting | Flag representing which mode the motor is in (Coast, Brake, or Hold). | tMotorBrakeModes |
Usage: | setMotorBrakeMode(nMotorIndex, modeSetting); |
motorCoast = Coast Mode. Power is removed from the motor when a speed of 0 is applied which allows the motor coast.
motorBrake = Brake Mode. The motor is placed in a Brake mode which will resist rotation when a speed level of 0 is applied but will not return to the original position if the motor is rotated.
motorHold = Hold Mode. The motor is placed in a Hold mode which will resist rotation when a speed level of 0 is applied and will attempt to 'hold' its position by applying a counterforce to any rotational force applied to the motor.
Code Example:
|