Skip to main content

rfx.drivers

Register and discover robot drivers via entry_points or explicit registration. Provides a unified interface for connecting to different robot platforms.
from rfx.drivers import register_driver, get_driver, list_drivers

# Register a custom driver
class MyRobotDriver:
    def connect(self, **kwargs):
        pass
    
    def disconnect(self):
        pass
    
    def is_connected(self) -> bool:
        return True
    
    def read_state(self) -> dict:
        return {"joint_positions": [0.0] * 6}
    
    def send_command(self, command: dict) -> None:
        pass
    
    @property
    def name(self) -> str:
        return "my_robot"
    
    @property
    def num_joints(self) -> int:
        return 6

register_driver("my_robot", MyRobotDriver)

# Get and use the driver
driver_cls = get_driver("my_robot")
driver = driver_cls()
driver.connect()
state = driver.read_state()

RobotDriver Protocol

Protocol that all robot drivers must implement.

Methods

connect

driver.connect(**kwargs: Any) -> None
Connect to the robot.
**kwargs
Any
Driver-specific connection parameters (e.g., IP address, serial port).

disconnect

driver.disconnect() -> None
Disconnect from the robot.

is_connected

driver.is_connected() -> bool
Check if the driver is currently connected.
return
bool
True if connected, False otherwise.

read_state

driver.read_state() -> dict[str, Any]
Read the current robot state.
return
dict[str, Any]
Dictionary containing robot state (e.g., joint positions, velocities, forces).

send_command

driver.send_command(command: dict[str, Any]) -> None
Send a command to the robot.
command
dict[str, Any]
required
Command dictionary (structure is driver-specific).

Properties

name
str
Human-readable name of the robot.
num_joints
int
Number of actuated joints on the robot.

register_driver

Register a driver factory by name.
from rfx.drivers import register_driver

register_driver("go2", Go2Driver)
register_driver("so_arm100", SO101Driver)

Function Signature

register_driver(
    name: str,
    factory: type
) -> None
name
str
required
Unique name for the driver.
factory
type
required
Driver class that implements the RobotDriver protocol.

get_driver

Get a registered driver factory by name.
from rfx.drivers import get_driver

driver_cls = get_driver("go2")
if driver_cls:
    driver = driver_cls()
    driver.connect(ip="192.168.1.100")

Function Signature

get_driver(name: str) -> type | None
name
str
required
Name of the driver to retrieve.
return
type | None
Driver class if found, None otherwise.

list_drivers

List all registered driver names.
from rfx.drivers import list_drivers

available = list_drivers()
print(f"Available drivers: {available}")
# Available drivers: ['go2', 'so_arm100', 'my_robot']

Function Signature

list_drivers() -> list[str]
return
list[str]
Sorted list of all registered driver names.

Auto-Discovery

Drivers can be automatically discovered via Python entry points. To make your driver discoverable, add this to your pyproject.toml:
[project.entry-points."rfx.drivers"]
my_robot = "my_package.drivers:MyRobotDriver"
Or in setup.py:
setup(
    name="my-robot-driver",
    entry_points={
        "rfx.drivers": [
            "my_robot = my_package.drivers:MyRobotDriver",
        ],
    },
)
The driver will be automatically registered when rfx.drivers is imported.

Build docs developers (and LLMs) love