🚋Streaming
One strong advantage of using ROAR_PY is that it supports streaming standard RoarPySensor
/ RoarPyActor
/ RoarPyWorld
objects over websocket or any other protocols that you wish to implement.
To support streaming for non-official implementations of the ROAR_PY interface, you simply need to add a few annotations to your implementation code and you can spin up a ROAR_PY remote server quickly. Let's get started!
All annotation methods can be imported from roar_py_interface
package
Streaming requires data to be passed between remote server and clients, and therefore usually requires the control code to support multi-threading.
ROAR_PY makes this simple by not requiring your code to support multi-threading natively, but just asking you to annotate methods that can only be called one thread at a time with @roar_py_thread_sync
.
Do not worry about dead-locking because ROAR_PY's streaming service uses a reentrant lock.
To share a world with different clients, the server needs to know which actors belongs to which client, therefore you need to annotate methods that creates new actors / sensors with @roar_py_append_item
and methods that removes actors / sensors with @roar_py_remove_item
in any implementation of RoarPyWorld
.
If you want to stream custom sensor datas, your custom data should be annotated with @serde
, @dataclass
, and @remote_support_sensor_data_register
. Annotating with @serde
and @dataclass
tells the Python interpreter that the sensor data class is a data class that can be serialized, and @remote_support_sensor_data_register
tells ROAR_PY's streaming service that this type of data is supported for streaming. The sensor data class should also extend RoarPyRemoteSupportedSensorData
.
Refer to official sensor data types for examples on how to write streaming supported data types. You may also override to_data(...)
method and create a new static method with signature from_data_custom(data: bytes, scheme: RoarPyRemoteSupportedSensorSerializationScheme)
to support custom serialization flows without using the default pyserde
Last updated