Skip to main content

An implementation of the WPILib WebSocket protocol for Python

Project description

wpilib-ws-py

This library is an implementation of the WPILib simulation WebSocket, used for controlling non-frc hardware or simulation software using WPILib. The specification of this protocol is found here.

My own dive into the source code for the websocket, which has some undocumented information: https://github.com/AM2i9/wpilib-ws-py/payloads.md

Example Sever Usage:

from wpilib_ws import WPILibWsServer

server = WPILibWsServer()

# The on_message decorator will let you create handlers for message events.
# Optionally a device type can be entered to only handle messages for that
# specific device type. A list of device types and other hardware messages can
# be found here:
# https://github.com/wpilibsuite/allwpilib/blob/main/simulation/halsim_ws_core/doc/hardware_ws_api.md#hardware-messages


@server.on_message("PWM")
async def pwm_handler(message):
    payload = message.data
    print(f"Recieved PWM event: {payload}")
    # ...


@server.on_message("CANMotor")
async def can_motor_handler(message):
    payload = message.data
    print(f"Recieved CANMotor event: {payload}")
    # ...


# Optionally, a device name can be entered to `on_message()`:


@server.on_message("SimDevice", "SPARK MAX")
async def spark_max_handler(message):

    # SimDevices are arbitrary devices sent over the websocket, which can be
    # used by vendor libraries to be able to use their controllers in robot
    # simulation. For example, SPARK MAX and other REV controllers will not
    # show as CAN devices, but as SimDevices.

    payload = message.data
    print(f"Recieved update for SPARK MAX controller: {payload}")


@server.on_message("CANMotor", "Victor SPX")
async def victor_handler(message):
    payload = message.data
    print(f"Recieved update for Victor SPX controller: {payload}")


# The while_connected decorator is a loop that runs alongside the server, and
# can be used for periodic tasks, such as sending battery voltage, like below.
@server.while_connected()
async def while_connected():
    await server.send_payload(
        {"type": "RoboRIO", "device": "", "data": {">vin_voltage": 12.0}}
    )


server.run()

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

wpilib-ws-py-0.3.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

wpilib_ws_py-0.3.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file wpilib-ws-py-0.3.0.tar.gz.

File metadata

  • Download URL: wpilib-ws-py-0.3.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Linux/5.13.19-2-MANJARO

File hashes

Hashes for wpilib-ws-py-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1ca26adbd84945434afd3e87a70a18170e25c609761e7bf28532a1e34f7b71c9
MD5 11001c355096755e9aeadbdce98b8264
BLAKE2b-256 3515d10a5671fa9604299cfc5346d24ffa46314d7e58d11106596ff9133432ca

See more details on using hashes here.

File details

Details for the file wpilib_ws_py-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: wpilib_ws_py-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Linux/5.13.19-2-MANJARO

File hashes

Hashes for wpilib_ws_py-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e36fe820b7b5a0de6be48d5edf0ea3865f0d50b1bcdd52002c99f10a75793fce
MD5 5f2076a899fc64bf423d596ceea35bab
BLAKE2b-256 0eab72180a9e816970388b793ccc7a0575f979f5b1cb72b2afa964ab9291b5b6

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