Skip to main content

An asyncio-focused library for webrtc robot control

Project description

RTCBot

PyPI npm Documentation Status Join the chat at https://gitter.im/rtcbot/community CircleCI

RTCBot's purpose is to provide a set of simple modules that help in developing remote-controlled robots in Python, with a focus on the Raspberry Pi.

The documentation includes tutorials that guide in developing your robot, starting from a basic connection between a Raspberry Pi and Browser, and encompass creating a video-streaming robot controlled entirely over a 4G mobile connection, all the way to a powerful system that offloads complex computation to a desktop PC in real-time.

All communication happens through WebRTC, using Python 3's asyncio and the wonderful aiortc library, meaning that your robot can be controlled with low latency both from the browser and through Python, even when it is not connected to your local network.

The library is explained piece by piece in the documentation.

See Documentation & Tutorials

Example

This example uses RTCBot to live stream a webcam to the browser. For details, please look at the tutorials.

from aiohttp import web
routes = web.RouteTableDef()

from rtcbot import RTCConnection, getRTCBotJS, CVCamera

camera = CVCamera()
# For this example, we use just one global connection
conn = RTCConnection()
conn.video.putSubscription(camera)

# Serve the RTCBot javascript library at /rtcbot.js
@routes.get("/rtcbot.js")
async def rtcbotjs(request):
    return web.Response(content_type="application/javascript", text=getRTCBotJS())

# This sets up the connection
@routes.post("/connect")
async def connect(request):
    clientOffer = await request.json()
    serverResponse = await conn.getLocalDescription(clientOffer)
    return web.json_response(serverResponse)

@routes.get("/")
async def index(request):
    return web.Response(
        content_type="text/html",
        text="""
    <html>
        <head>
            <title>RTCBot: Video</title>
            <script src="/rtcbot.js"></script>
        </head>
        <body style="text-align: center;padding-top: 30px;">
            <video autoplay playsinline></video> <audio autoplay></audio>
            <p>
            Open the browser's developer tools to see console messages (CTRL+SHIFT+C)
            </p>
            <script>
                var conn = new rtcbot.RTCConnection();

                conn.video.subscribe(function(stream) {
                    document.querySelector("video").srcObject = stream;
                });

                async function connect() {
                    let offer = await conn.getLocalDescription();

                    // POST the information to /connect
                    let response = await fetch("/connect", {
                        method: "POST",
                        cache: "no-cache",
                        body: JSON.stringify(offer)
                    });

                    await conn.setRemoteDescription(await response.json());

                    console.log("Ready!");
                }
                connect();

            </script>
        </body>
    </html>
    """)

async def cleanup(app):
    await conn.close()
    camera.close()

app = web.Application()
app.add_routes(routes)
app.on_shutdown.append(cleanup)
web.run_app(app)

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

rtcbot-0.0.5.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

rtcbot-0.0.5-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

Details for the file rtcbot-0.0.5.tar.gz.

File metadata

  • Download URL: rtcbot-0.0.5.tar.gz
  • Upload date:
  • Size: 29.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for rtcbot-0.0.5.tar.gz
Algorithm Hash digest
SHA256 0c7bff6d11bc45f28bf84df81d6ecb2e49bfc893bdb19ac3e2c823964f44b21f
MD5 664d150b5f4a1fa60e037a5d37f1385e
BLAKE2b-256 050aeb8e53650f0d1593ca478e510eecd84a2513260b8dd838acc28c68f9d824

See more details on using hashes here.

File details

Details for the file rtcbot-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: rtcbot-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 35.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for rtcbot-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 98cf6427e98e19944153125c94e7662e3121675e4d3d8be700f1da683cbd6c88
MD5 3d989b3e14c9fad0f0cc807e78e5f0af
BLAKE2b-256 71a57448957be0278bf0ca7a685daa9266b7cc68f78cb169c44b7bf23503c8ff

See more details on using hashes here.

Supported by

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