Module Motor :: Class Motor
[frames] | no frames]

Class Motor

source code

Class that represents a EV3LargeRegulatedMotors or a NXTRegulatedMotor. Support for the wheel encoder that acts like a rotation counter with resolution of 720 counts per 360 degrees rotation.

Instance Methods
 
__init__(self, port)
Creates a motor instance at given motor port (MotorPort.A, MotorPort.B, MotorPort.C, MotorPort.D).
source code
 
getPortId(self)
Returns the port number [0..3].
source code
 
getPortLabel(self)
Returns the port label ("A", "B", "C", "D").
source code
 
forward(self)
Starts the forward rotation with current speed.
source code
 
backward(self)
Starts the backward rotation with current speed.
source code
 
stop(self)
Stops the motor.
source code
 
setSpeed(self, speed)
Sets the speed to the given value (arbitrary units).
source code
 
getSpeed(self)
Returns the current speed (arbitrary units).
source code
 
resetMotorCount(self)
Resets the rotation count to zero.
source code
 
getMotorCount(self)
Returns the current rotation count.
source code
 
rotateTo(self, count, blocking=True)
Sets the rotation counter to zero and rotates the motor until the given count is reached.
source code
 
continueTo(self, count, blocking=True)
Same as rotateTo(count, blocking), but the rotation counter is not set to zero.
source code
 
continueRelativeTo(self, count, blocking=True)
Same as rotateTo(int count), but the rotation counter is not set to zero.
source code
Method Details

__init__(self, port)
(Constructor)

source code 

Creates a motor instance at given motor port (MotorPort.A, MotorPort.B, MotorPort.C, MotorPort.D). The rotation count is set to zero.

forward(self)

source code 

Starts the forward rotation with current speed. Method returns, while the rotation continues. (If motor is already rotating, returns immediately.) The rotation counter continues to be increased from its start value.

backward(self)

source code 

Starts the backward rotation with current speed. Method returns, while the rotation continues. (If motor is already rotating, returns immediately.) The rotation counter continues to be decreased from its start value.

setSpeed(self, speed)

source code 

Sets the speed to the given value (arbitrary units). The speed will be changed to the new value at the next movement call only.

Parameters:
  • speed - the speed 0..100

rotateTo(self, count, blocking=True)

source code 

Sets the rotation counter to zero and rotates the motor until the given count is reached. If count is negative, the motor turns backwards. If blocking = True (default), the method blocks until the count is reached and the motor stops. Keep in mind that the motor will overrun the given count, because its inertia. The amount depends of its speed.

continueTo(self, count, blocking=True)

source code 

Same as rotateTo(count, blocking), but the rotation counter is not set to zero. The given count is the absolute value of the rotation counter to be reached. If the current count is higher than the count to reach, the motor turns backward. Keep in mind that the motor will overrun the given count, because its inertia. The amount depends of its speed.

continueRelativeTo(self, count, blocking=True)

source code 

Same as rotateTo(int count), but the rotation counter is not set to zero. The given count is the relative increasement/decreasement from the current value of the rotation counter. For count < 0 the motor turns backward.