Skip to main content

xrp-usb-controller

Library for controlling an XRP Robot over a USB connection

The repository provides a client-server architecture for controlling the XRP robot from a host computer (e.g., PC or SBC) over USB serial:

  • usb_control.py: MicroPython RPC server running on the robot's RP2040 microcontroller. It asynchronously listens on USB serial (sys.stdin) for commands and drives the motors, reads the ultrasonic rangefinder/IMU, controls servos, and toggles LEDs.
  • usb_controller.py: Host-side Python library providing the XRPController client class. It manages serial connectivity (/dev/ttyACM0), handshakes on connect, flushes stale buffers, and sends commands with automatic response handling.

Deploying the Controller to the Robot

  1. Install usb_control.py as the robot's boot script:
    # Copy usb_control.py to the Pico as main.py so it starts automatically
    mpremote cp usb_control.py :main.py
    
    # Soft-reboot the board to start the service
    mpremote reset
    
  2. Run the usb_controller.py script interactively to test connectivity:
    # Activate virtual environment
    source .venv/bin/activate
    
    # Launch the vision & navigation script
    python usb_controller.py
    

Using XRPController in Python Scripts

Import XRPController and use it as a context manager:

from xrp_usb_controller import XRPController

# Connects to /dev/ttyACM0 by default and performs a handshake
with XRPController() as bot:
    # 1. Check distance with ultrasonic rangefinder (returns cm as float, or None)
    distance = bot.read_rangefinder()
    print(f"Obstacle distance: {distance} cm")

    # 2. Drive motors (-1.0 to 1.0 effort for left and right wheels)
    bot.drive_effort(0.5, 0.5)

    # 3. Stop drivetrain motors
    bot.drive_stop()

    # 4. Control LEDs or servos
    bot.set_rgb(0, 255, 0)
    bot.set_servo(1, 90.0)

Testing this module

This module's tests are designed to be run with the robot connected. To run them, install the module locally and then run the test suite:

pip install -e .
python -m unittest tests/test_xrp_usb_controller.py -v

Troubleshooting

If you get a InvalidVersion exception, then the version of usb_control.py on the control board is too old for the controller. Update the code on the control board as documented above.

Metadata

Release files for xrp-usb-controller 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xrp-usb-controller 0.3.0
File Size Uploaded Provenance
xrp_usb_controller-0.3.0.tar.gz 46.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for xrp-usb-controller 0.3.0
File Interpreter ABI Platform
xrp_usb_controller-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 79.8 kB

Release files / xrp_usb_controller-0.3.0.tar.gz

Download URL xrp_usb_controller-0.3.0.tar.gz
Size 46.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c62114a2a65047eaa93c58aa36f4ae470db1f1fbfb3b5c88947c73febaf184c7
BLAKE2b-256 checksum
How to use checksums
a24202e73b73f6dc90a420fabe62f314ad4ba653a71fd50ccd71e24abb4e284a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / xrp_usb_controller-0.3.0-py3-none-any.whl

Download URL xrp_usb_controller-0.3.0-py3-none-any.whl
Size 33.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44992988153a7be70a9e5f262d34121f308ceb9bc1c54e5b04523d4c15852d36
BLAKE2b-256 checksum
How to use checksums
ef22839e7b033725795b8da6a7c20990dc77f432452302ea27d9da0eb35edf9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for xrp-usb-controller 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page