Motor Board API¶
The kit can control multiple motors simultaneously. One Motor Board can control up to two motors.
Accessing the Motor Board¶
The motor board can be accessed using the
motor_board property of
my_motor_board = r.motor_board
This board object has an array containing the motors connected to it,
which can be accessed as
motors. The Motor Board is labelled so you know which
motor is which.
Motor power is controlled using pulse-width modulation
(PWM). You set
the power with a fractional value between
1 is maximum speed in one direction,
-1 is maximum speed
in the other direction and
0 causes the motor to brake.
r.motor_board.motors.power = 1 r.motor_board.motors.power = -1
These values can also be read back:
r.motor_board.motors.power >>> 1 r.motor_board.motors.power >>> -1
Setting a value outside of the range
1 will raise an exception and your code will crash.
Sudden large changes in the motor speed setting
-1 etc.) will likely trigger the
over-current protection and your robot will shut down with a distinct beeping
noise and/or a red light next to the power board output that is powering
the motor board.
In addition to the numeric values, there are two special constants that
can be used:
COAST. In order to use these, they must
be imported from the
sbot module like so:
from sbot import BRAKE, COAST
BRAKE will stop the motors from turning, and thus stop your robot as
quick as possible.
BRAKE does the same as setting the power to
from sbot import BRAKE r.motor_board.motors.power = BRAKE
COAST will stop applying power to the motors. This will mean they
continue moving under the momentum they had before.
from sbot import COAST r.motor_board.motors.power = COAST