KevsRobots Learning Platform
42% Percent Complete
By Kevin McAleer, 2 Minutes
BurgerBot has a nice Python Library that controls the robotic vehicle, which includes motors and sensors, such as a distance sensor, line sensor and a servo for the pen.
This library uses the Pimoroni flavoured MicroPython.
The following libraries are required for the BurgerBot to function properly (and they are all inlcuded in the Pimoroni MicroPython):
motor and pico_motor_shim from the motor module.REVERSED_DIR from the pimoroni module.Servo from the servo module.connect_to_wifi, logging, access_point, dns, server, and redirect from the phew module.gc and Pin from the machine module.The BurgerBot class contains the following methods:
| Method | Description |
|---|---|
__init__() |
Initializes the BurgerBot class with a list of motors, MOTOR_PINS, and sets the __speed variable to 0. |
line_detected() -> bool |
Returns a boolean value indicating whether a line has been detected by the line sensor. |
pen_middle() |
Moves the pen servo to the middle position. |
pen_down() |
Moves the pen servo to the down position. |
pen_up() |
Moves the pen servo to the up position. |
forward(duration) |
Drives the motors forward, the βdurationβ is optional and moves for the time specified |
turnleft(duration) |
Turns the motors left, the βdurationβ is optional and moves for the time specified |
turnright(duration) |
Turns the motors right, the βdurationβ is optional and moves for the time specified |
stop() |
Stops the motors. |
left_motor(speed) |
Sets the speed of the left motor to the provided value. |
right_motor(speed) |
Sets the speed of the right motor to the provided value. |
speed() -> float |
Returns the current speed of the motors. |
speed(value) |
Sets the speed of the motors to the provided value. |
The BurgerBot also contains the following variables:
motors: a list of two Motor objects representing the left and right motors.pen_servo: a Servo object representing the pen servo.line_sensor: a Pin object representing the line sensor pin.
You can use the arrows β β on your keyboard to navigate between lessons.
Comments