Maqueen Plus V2 MicroPython Documentation

website·Indexed 30 days ago

https://gbsl-informatik.github.io/maqueen-plus-v2-mpy/

API reference and examples for the Maqueen Plus V2 robot using MicroPython. Includes documentation for motor control (motor_run), LED management (led_red, led_rgb), line tracking (line_sensor), ultrasonic distance sensing (ultrasonic), and compass heading (mq_heading). Supports versions 1.0.0, 2.0.0, 2.0.1, 2.0.2, and Next.

Tokens
19.9K
Snippets
183
Records
195
Agent score
68%

What's inside Maqueen Plus V2

  1. Overview of Maqueen Plus V2 MicroPython Library

    The Maqueen Plus V2 library allows developers to program the Maqueen Plus V2 robot (by dfrobot) using MicroPython on a Micro:Bit. The library provides a high-level interface to control the robot's motors, sensors, and LEDs, making it suitable for both beginners and advanced users.
  2. Install Maqueen Plus V2.0 MicroPython library

    To use the Maqueen Plus V2.0 library with MicroPython on a Micro:bit, use the online IDE at https://python.microbit.org/v/3. Copy the maqueen.py library file into your project folder to import and use its functions in your main.py.
    from microbit import *
    from maqueen import *
    
    motor_run(Motor.LEFT, 100)
    sleep(1000)
    motor_run(Motor.ALL, 100)
    sleep(1000)
    motor_stop(Motor.ALL)
  3. Migrate LineSensor constants to v2.0.0

    In version 2.0.0, the LineSensor constants were renamed for better editor autocompletion. Additionally, SENSOR_ALL was removed and replaced by a dedicated function.
    # Old constants -> New constants
    # SENSOR_L1 -> L1
    # SENSOR_L2 -> L2
    # SENSOR_M  -> M
    # SENSOR_R1 -> R1
    # SENSOR_R2 -> R2
    
    # Instead of SENSOR_ALL, use:
    line_sensor_all()
  4. Calibrate Maqueen Plus V2.0 motors for straight driving

    Because motors may not be perfectly identical, motor_calibration allows you to set correction factors for specific speeds. The function takes a list of tuples (speed, correction_factor), where speed is between 0-255 and the factor is a value > 0. The system linearly interpolates between these points to ensure the robot drives straight. To reset calibration, pass an empty list [].
    from maqueen import *
    
    # Calibrate left motor with two measurement points
    # (Speed 25 with factor 1.3, Speed 200 with factor 1.2)
    motor_calibration(Motor.LEFT, [(25, 1.3), (200, 1.2)])
    
    # Example with multiple interpolation points
    motor_calibration(
        Motor.LEFT,
        [
            (25, 1.3),
            (50, 1.2),
            (100, 1.4),
            (200, 1.0)
        ]
    )
    
    # Reset calibration for both motors
    motor_calibration(Motor.LEFT, [])
    motor_calibration(Motor.RIGHT, [])
  5. Install Maqueen Plus V2.0 MicroPython library

    To use the Maqueen Plus V2.0 library with MicroPython on a Micro:bit, use the online IDE at https://python.microbit.org/v/3. Copy the maqueen.py library file into your project folder to make it available for import in your main.py script.
    from microbit import *
    from maqueen import *
    
    motor_run(Motor.LEFT, 100)
    sleep(1000)
    motor_run(Motor.ALL, 100)
    sleep(1000)
    motor_stop(Motor.ALL)
  6. Migrate LineSensor API to v2.0.0

    In version 2.0.0, the LineSensor constants were renamed for better editor autocompletion. SENSOR_ALL was removed and replaced by a dedicated function.

    Constant Changes:

    • SENSOR_L1 → L1
    • SENSOR_L2 → L2
    • SENSOR_M → M
    • SENSOR_R1 → R1
    • SENSOR_R2 → R2

    Function Changes:

    • Use line_sensor_all() instead of SENSOR_ALL to get values for all sensors.
  7. Calibrate Maqueen Plus V2 motors for straight driving

    Because motors may not be perfectly identical, motor_calibration allows you to set correction factors for specific speeds to ensure the robot drives straight. The calibration takes a list of tuples containing (speed, correction_factor). The speed must be between 0 and 255, and the correction factor must be > 0. The system linearly interpolates between the provided data points. To reset calibration, pass an empty list [].
    from maqueen import *
    
    # Set calibration for the left motor: at speed 25 use factor 1.3, at speed 200 use factor 1.2
    motor_calibration(Motor.LEFT, [(25, 1.3), (200, 1.2)])
    
    # Example with multiple interpolation points
    motor_calibration(
        Motor.LEFT,
        [
            (25, 1.3),
            (50, 1.2),
            (100, 1.4),
            (200, 1.0)
        ]
    )
    
    # Reset calibration for both motors
    motor_calibration(Motor.LEFT, [])
    motor_calibration(Motor.RIGHT, [])
  8. Migrate LineSensor constants to v2.0.0

    In version 2.0.0, the LineSensor constants were renamed for better editor autocompletion. Additionally, SENSOR_ALL was removed in favor of the line_sensor_all() function.

    Changes:

    • SENSOR_L1 $ ightarrow$ L1
    • SENSOR_L2 $ ightarrow$ L2
    • SENSOR_M $ ightarrow$ M
    • SENSOR_R1 $ ightarrow$ R1
    • SENSOR_R2 $ ightarrow$ R2
    • SENSOR_ALL $ ightarrow$ Use line_sensor_all()
  9. Calibrate Maqueen Plus V2 motors for straight driving

    Because motors may not be identical, motor_calibration(motor, calibration) allows you to set correction factors that are linearly interpolated based on speed. The calibration parameter is a list of tuples containing (speed, correction_factor), where speed is 0-255 and the factor is a value > 0. To reset calibration, pass an empty list [].
    # Set calibration for the left motor with two measurement points
    motor_calibration(Motor.LEFT, [(25, 1.3), (200, 1.2)])
    
    # Set multiple calibration points for linear interpolation
    motor_calibration(
        Motor.LEFT,
        [
            (25, 1.3),
            (50, 1.2),
            (100, 1.4),
            (200, 1.0)
        ]
    )
    
    # Reset calibration
    motor_calibration(Motor.LEFT, [])
    motor_calibration(Motor.RIGHT, [])
  10. Install Maqueen Plus V2.0 library for MicroPython

    To use the Maqueen Plus V2.0 library with a Micro:bit, use the MicroPython online IDE (https://python.microbit.org/v/3). Copy the maqueen.py library file into your project folder so it can be imported into your main.py script.
    from microbit import *
    from maqueen import *
    
    motor_run(Motor.LEFT, 100)
    sleep(1000)
    motor_run(Motor.ALL, 100)
    sleep(1000)
    motor_stop(Motor.ALL)