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

Class Gear

source code

Class that represents the combination of two motors on an axis to perform a car-like movement.

Instance Methods
 
__init__(self, port1=MotorPort.A, port2=MotorPort.B)
Creates a gear instance with left motor plugged into port1, right motor plugged into port2 (defaults: port1 = MotorPort.A, port2 = MotorPort.B).
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
 
forward(self, duration=-1)
Starts the forward movement with current speed for the given duration (in ms).
source code
 
backward(self, duration=-1)
Same as forward(int duration), but moves in reverse direction.
source code
 
stop(self)
Stops the gear.
source code
 
moveTo(self, count, blocking=True)
Sets the rotation counter of both motors to zero and rotate the motors until the given count is reached.
source code
 
left(self, duration=-1)
Starts turning left with left motor rotating forward and right motor rotating backward at current speed.
source code
 
right(self, duration=-1)
Same as left, but turns to the right.
source code
 
leftArc(self, radius, duration=-1)
Starts turning to the left on an arc with given radius (in arbitrary units).
source code
 
rightArc(self, radius, duration=-1)
Starts turning to the right on an arc with given radius (in arbitrary units).
source code
 
getLeftMotor(self)
Returns the reference of motor 1 (left motor).
source code
 
getRightMotor(self)
Returns the reference of motor 2 (right motor).
source code
Method Details

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

forward(self, duration=-1)

source code 

Starts the forward movement with current speed for the given duration (in ms). For duration = -1 (default), the method returns, while the movement continues. Otherwise the method returns at the end of the given duration, but the movement continues for 200 ms. Then it stops unless another movement method call (forward, backward, left, right, leftArc, rightArc) is invoked within that time. In a consequence calling several movement methods one after the other will result a seamless movement without intermediate stops. (If motor is already rotating with same speed, returns immediately.)

stop(self)

source code 

Stops the gear. (If motor is already stopped, returns immediately.)

moveTo(self, count, blocking=True)

source code 

Sets the rotation counter of both motors to zero and rotate the motors until the given count is reached. If count is negative, the motors turn backwards. If blocking = True (default), the method returns blocks, until the count is reached; otherwise it returns immediately

left(self, duration=-1)

source code 

Starts turning left with left motor rotating forward and right motor rotating backward at current speed. For duration = -1 (default), the method returns, while the movement continues. Otherwise the method returns at the end of the given duration, but the movement continues for 200 ms. Then it stops unless another movement method call (forward, backward, left, right, leftArc, rightArc) is invoked within that time. In a consequence calling several movement methods one after the other will result a seamless movement without intermediate stops. (If gear is already turning left, returns immediately.)

leftArc(self, radius, duration=-1)

source code 

Starts turning to the left on an arc with given radius (in arbitrary units). If the radius is negative, turns left backwards. For duration = -1 (default), the method returns, while the movement continues. Otherwise the method returns at the end of the given duration, but the movement continues for 200 ms. Then it stops unless another movement method call (forward, backward, left, right, leftArc, rightArc) is invoked within that time. In a consequence calling several movement methods one after the other will result a seamless movement without intermediate stops. (If gear is already turning on a left arc with same radius, returns immediately.)

rightArc(self, radius, duration=-1)

source code 

Starts turning to the right on an arc with given radius (in arbitrary units). If the radius is negative, turns left backwards. For duration = -1 (default), the method returns, while the movement continues. Otherwise the method returns at the end of the given duration, but the movement continues for 200 ms. Then it stops unless another movement method call (forward, backward, left, right, leftArc, rightArc) is invoked within that time. In a consequence calling several movement methods one after the other will result a seamless movement without intermediate stops. (If gear is already turning on a left arc with same radius, returns immediately.)