Hakoniwa PDU communication library for Python
Project description
hakoniwa-pdu-python
Python PDU communication library for the Hakoniwa simulator. Provides a unified transport layer where RPC and Pub/Sub (topics) run seamlessly over WebSocket. For high-speed use cases, a Shared Memory (SHM) backend is also available. The architecture is extensible to Zenoh, enabling scalable and distributed systems. Binary โ JSON โ Python type conversion is built-in, reducing boilerplate to a minimum.
โจ Features
- Unified layer: RPC and Pub/Sub integrated on top of WebSocket
- Automatic type conversion: safely convert between binary, JSON, and Python types with offset definitions
- Transport flexibility: choose between WebSocket, Shared Memory (SHM), and extensible backends such as Zenoh
- Explicit & secure connections: WebSocket URIs (
ws://...) clearly define communication scope - Event-driven & polling support: register handlers or poll buffers as needed
- Ready-to-run samples: minimal examples for
Twist(topic) andAddTwoInts(RPC) included
๐ฆ Installation
pip install hakoniwa-pdu
pip show hakoniwa-pdu # check version
Environment Variables
Specify the directory containing .offset files for PDU conversion:
export HAKO_BINARY_PATH=/your/path/to/offset
Default path if unset:
/usr/local/lib/hakoniwa/hako_binary/offset
๐ Quick Start (3 commands)
Example 1: WebSocket Topic (
geometry_msgs/Twistpublish โ subscribe)
- Publisher (server)
python examples/topic/websocket/remote_publisher.py \
--uri ws://localhost:8080 \
--pdu-config examples/pdu_config.json \
--service-config examples/service.json
- Subscriber (client)
python examples/topic/websocket/remote_subscriber.py \
--uri ws://localhost:8080 \
--pdu-config examples/pdu_config.json \
--service-config examples/service.json
- Output
[INFO] Received Twist: linear.x=0 angular.z=0
[INFO] Received Twist: linear.x=1 angular.z=1
Example 2: WebSocket RPC (
AddTwoIntsservice)
- RPC Server
python examples/rpc/websocket/remote_rpc_server.py \
--uri ws://localhost:8080 \
--pdu-config examples/pdu_config.json \
--service-config examples/service.json
- RPC Client
python examples/rpc/websocket/remote_rpc_client.py \
--uri ws://localhost:8080 \
--pdu-config examples/pdu_config.json \
--service-config examples/service.json
- Output
Response: 3
๐ก Event-Driven PDU Handling
Server:
server_manager.register_handler_pdu_data(on_pdu)
def on_pdu(client_id, packet):
...
Client:
client_manager.register_handler_pdu_data(on_pdu)
def on_pdu(packet):
...
Polling via contains_buffer() / get_buffer() is also available.
๐ Project Structure
hakoniwa_pdu/
โโโ pdu_manager.py
โโโ impl/
โ โโโ icommunication_service.py
โ โโโ websocket_communication_service.py
โ โโโ websocket_server_communication_service.py
โ โโโ shm_communication_service.py
โ โโโ pdu_convertor.py
โ โโโ hako_binary/
โโโ rpc/
โ โโโ ipdu_service_manager.py
โ โโโ protocol_client.py
โ โโโ protocol_server.py
โ โโโ auto_wire.py
โ โโโ remote/
โ โโโ shm/
โโโ resources/
โ โโโ offset/
โโโ examples/
๐งญ Class Overview
PduManager
- Orchestrates PDU buffers and delegates to a transport (
ICommunicationService). - Direct I/O:
declare_pdu_for_read/writeโflush_pdu_raw_data()/read_pdu_raw_data(). - For RPC: extended via
rpc.IPduServiceManager(handlesregister_client,start_rpc_service, etc.).
Transport Implementations (impl/)
ICommunicationServicedefines the transport API.WebSocketCommunicationService/WebSocketServerCommunicationService: WebSocket backend (explicit URI-based connection, simple & secure).ShmCommunicationService: high-speed shared memory backend.- Pluggable design: additional transports (e.g., Zenoh) can be integrated without changing application code.
RPC Layer (rpc/)
IPduServiceManagerfamily provides RPC APIs (client/server).protocol_client.py/protocol_server.py: user-friendly helpers.auto_wire.py: auto-loads generated converters.remote/: WebSocket managers.shm/: SHM managers.
๐งฉ Class Diagram (Mermaid)
classDiagram
class PduManager
PduManager --> ICommunicationService : uses
PduManager --> CommunicationBuffer
PduManager --> PduConvertor
PduManager --> PduChannelConfig
class ICommunicationService {
<<interface>>
}
class WebSocketCommunicationService
class WebSocketServerCommunicationService
class ShmCommunicationService
ICommunicationService <|.. WebSocketCommunicationService
ICommunicationService <|.. WebSocketServerCommunicationService
ICommunicationService <|.. ShmCommunicationService
class IPduServiceManager {
<<abstract>>
}
PduManager <|-- IPduServiceManager
class IPduServiceClientManager
class IPduServiceServerManager
IPduServiceManager <|-- IPduServiceClientManager
IPduServiceManager <|-- IPduServiceServerManager
class RemotePduServiceBaseManager
RemotePduServiceBaseManager <|-- RemotePduServiceClientManager
RemotePduServiceBaseManager <|-- RemotePduServiceServerManager
IPduServiceManager <|-- RemotePduServiceBaseManager
class ShmPduServiceBaseManager
ShmPduServiceBaseManager <|-- ShmPduServiceClientManager
ShmPduServiceBaseManager <|-- ShmPduServiceServerManager
IPduServiceManager <|-- ShmPduServiceBaseManager
๐ Links
- ๐ GitHub: https://github.com/hakoniwalab/hakoniwa-pdu-python
- ๐ Hakoniwa Lab: https://hakoniwa-lab.net
๐ Documentation
For detailed API usage: โก๏ธ API Reference (api-doc.md)
๐ License
MIT License โ see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hakoniwa_pdu-1.1.6.tar.gz.
File metadata
- Download URL: hakoniwa_pdu-1.1.6.tar.gz
- Upload date:
- Size: 194.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18ad694ed3b2e67a7f7dc8bb62c26dcc2421f54a5ba66edc57ea8d4b82f5203d
|
|
| MD5 |
6b04fd0f4f87e730802a9ab8965bebea
|
|
| BLAKE2b-256 |
25305960c914309d244ca154b333d906ebdb709d776de041d3c225dbbaf3e450
|
File details
Details for the file hakoniwa_pdu-1.1.6-py3-none-any.whl.
File metadata
- Download URL: hakoniwa_pdu-1.1.6-py3-none-any.whl
- Upload date:
- Size: 558.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6df4a3f2ebf9eaec5ecdfa1adc246878e7800f7d09c9cc7e2dde3a264e4d7fe
|
|
| MD5 |
d134711b852935b55814aad3c0bc5c91
|
|
| BLAKE2b-256 |
cb02ee4dab6e774f75bf7ace8a29e08d2a3c2f02392531da69216566563318c8
|