Motor Board API¶
The kit can control multiple motors simultaneously. One Motor Board can control up to two motors.
Accessing the Motor Board¶
If there is exactly one motor board attached to your robot, it can be accessed
motor_board property of the
my_motor_board = r.motor_board
If there is more than one motor board on your kit, you must use the
r.motor_board will cause an error. This is because
the kit doesn’t know which motor board you want to access.
Motor boards attached to your robot can be accessed under the
property of the
Robot. The boards are indexed by their serial number, which is written on the board.
my_motor_board = r.motor_boards["SRO-AAD-GBH"] my_other_motor_board = r.motor_boards["SR08U6"]
Controlling the 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.
my_motor_board.motors.power = 1 my_motor_board.motors.power = -1
These values can also be read back:
my_motor_board.motors.power >>> 1 my_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 my_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 my_motor_board.motors.power = COAST