Skip to main content

Unified Python library for controlling BonicBot via BLE and WebSocket Bridge

Project description

BonicBot Python Library

PyPI version Python versions License: MIT

A unified Python library for controlling the BonicBot humanoid robot. This library provides a single interface to control the robot's hardware directly via Bluetooth Low Energy (BLE) and high-level Android app features via a WebSocket Bridge.

Key Features

  • Unified Controller: One class (BonicBotController) handles everything.
  • Low Latency BLE: Direct hardware control (servos, motors, sensors, LED matrix) over BLE binary protocol.
  • App Bridge: Easy access to Android-specific features:
    • Text-to-Speech (TTS): Make the robot speak.
    • Sequences: Play, pause, and manage complex movement sequences.
    • Camera: Start MJPEG streams and capture snapshots.
  • Type Safety: Full use of Python type hints and dataclasses for robot state.
  • Async Foundation: Built on bleak and websockets for modern, non-blocking performance.

Installation

pip install bonicbot

Dependencies

  • bleak: For BLE communication.
  • websockets: For communication with the BonicBot Android App.

Quick Start

Basic Hardware Control (BLE)

To control the robot's hardware (servos, wheels, LEDs), you only need the robot's BLE device name.

from bonicbot import BonicBotController

# Connect via BLE only
bot = BonicBotController(device_name="BonicBot-S1")

if bot.connect():
    # Move the head
    bot.control_head(pan=30, tilt=-10)
    
    # Move the robot base
    bot.move_forward(speed=150, duration=2)
    
    # Control the LED matrix
    bot.set_display_text("HELLO")
    
    bot.close()

Full Control (BLE + App Features)

To use features like TTS or Camera, provide the IP address of the Android device running the BonicBot app.

from bonicbot import BonicBotController

# Connect via BLE and WebSocket Bridge
bot = BonicBotController(device_name="BonicBot-S1", ws_host="192.168.1.100")

if bot.connect():
    # Hardware (BLE)
    bot.move_forward(speed=100)
    
    # App Features (WebSocket)
    bot.speak("Hello! I am ready to assist you.")
    bot.play_sequence("Wave")
    
    # Capture a snapshot from the camera
    image = bot.capture_image()
    if image:
        with open("snapshot.jpg", "wb") as f:
            f.write(image.data)
            
    bot.close()

Advanced Usage

Reading Sensors

The robot streams battery and distance data back to the controller.

def on_battery(data):
    print(f"Battery: {data['soc']}% ({data['voltage']}V)")

bot.start_battery_stream(callback=on_battery)
# The callback will be triggered whenever new data arrives over BLE.

Hand Gestures

Control 6 servos per hand simultaneously using HandCommand.

from bonicbot.controllers.models import HandCommand

# Open right gripper and lift arm
bot.control_right_hand(gripper=90, elbow=-45, shoulder_pitch=90)

API Reference

BonicBotController(device_name, ws_host=None, ws_port=8080)

  • connect(): Establish BLE and WebSocket connections.
  • close(): Disconnect all services.

Hardware Control (BLE)

  • move_forward / backward / turn_left / right(speed, duration)
  • control_servo(servo_id, angle, speed, acceleration)
  • control_head(pan, tilt, mode, speed)
  • control_right_hand / left_hand(**kwargs)
  • set_display_text / color / animation / pixel / frame(...)
  • read_battery() / read_distance(): Request a single update.
  • start_battery_stream / start_distance_stream(interval, callback)

App Bridge (WebSocket)

  • speak(text): Android TTS.
  • get_sequences(): Returns list of available sequences on the app.
  • play_sequence(name, seq_id): Triggers a sequence.
  • stop_sequence() / pause_sequence() / resume_sequence()
  • jump_to_step(step_index)
  • start_camera_stream() / stop_camera_stream()
  • capture_image(): Returns a CapturedImage object (JPEG).

Contributing

See CONTRIBUTING.md for details on how to get started with development.

License

MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bonicbot-3.0.0.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bonicbot-3.0.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file bonicbot-3.0.0.tar.gz.

File metadata

  • Download URL: bonicbot-3.0.0.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for bonicbot-3.0.0.tar.gz
Algorithm Hash digest
SHA256 c4c8b2adc8f6d9c830cb5c8e3eac7f69ce1f0e8ba1c1213c29ae151d8b5ec3cf
MD5 09dd20c8686a8731d9c4cd15ad37a71e
BLAKE2b-256 a7b2a62721ea7d4faa4b395c75a1e17a5f08e38d48c5b545f223ee38d93da590

See more details on using hashes here.

File details

Details for the file bonicbot-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: bonicbot-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for bonicbot-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa968a50181e5b3ab3dd134f46683a0317b4bc044fd9d3dd6d059be8d1be30d6
MD5 37f35be25cfd4b5fe3bfa32a1c998321
BLAKE2b-256 47a109af9522e10e8a90d6d18060cac20a272a887a3d3b0b15bbbd6fe11297a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page