Skip to main content
The Robot class provides a standardized interface for interacting with physical robots in LeRobot. All robot implementations inherit from this abstract base class.

Class Definition

from lerobot.robots import Robot
Location: src/lerobot/robots/robot.py:30

Overview

The Robot class is an abstract base that defines the core interface for robot control in LeRobot. It handles:
  • Connection management (connect/disconnect)
  • Motor calibration
  • Observation retrieval
  • Action execution
  • Configuration management

Class Attributes

config_class
type[RobotConfig]
required
The configuration class expected for this robot type. Must be set in all subclasses.
name
str
required
The unique robot name used to identify this robot type. Must be set in all subclasses.

Constructor

def __init__(self, config: RobotConfig)
config
RobotConfig
required
Configuration object containing robot-specific settings including ID, calibration directory, and hardware parameters.

Abstract Properties

Subclasses must implement these properties:

observation_features

@property
@abc.abstractmethod
def observation_features(self) -> dict
observation_features
dict
A dictionary describing the structure and types of observations produced by the robot.Keys should match the structure returned by get_observation(). Values should be either:
  • The type of the value for simple values (e.g., float for joint position)
  • A tuple representing shape for array-type values (e.g., (height, width, channel) for images)
This property must be callable regardless of connection state.

action_features

@property
@abc.abstractmethod
def action_features(self) -> dict
action_features
dict
A dictionary describing the structure and types of actions expected by the robot.Keys should match the structure passed to send_action(). Values should be the type of the value (e.g., float for joint goal position).This property must be callable regardless of connection state.

is_connected

@property
@abc.abstractmethod
def is_connected(self) -> bool
is_connected
bool
Whether the robot is currently connected. If False, calling get_observation() or send_action() should raise an error.

is_calibrated

@property
@abc.abstractmethod
def is_calibrated(self) -> bool
is_calibrated
bool
Whether the robot is currently calibrated. Should always be True if calibration is not applicable.

Abstract Methods

Subclasses must implement these methods:

connect

@abc.abstractmethod
def connect(self, calibrate: bool = True) -> None
Establish communication with the robot.
calibrate
bool
default:"True"
If True, automatically calibrate the robot after connecting if it’s not calibrated or needs calibration.

calibrate

@abc.abstractmethod
def calibrate(self) -> None
Calibrate the robot if applicable. Should be a no-op if calibration is not needed. This method should collect necessary data (e.g., motor offsets) and update the calibration dictionary.

configure

@abc.abstractmethod
def configure(self) -> None
Apply any one-time or runtime configuration to the robot. May include setting motor parameters, control modes, or initial state.

get_observation

@abc.abstractmethod
def get_observation(self) -> RobotObservation
Retrieve the current observation from the robot.
RobotObservation
dict
A flat dictionary representing the robot’s current sensory state. Structure should match observation_features.

send_action

@abc.abstractmethod
def send_action(self, action: RobotAction) -> RobotAction
Send an action command to the robot.
action
RobotAction
required
Dictionary representing the desired action. Structure should match action_features.
RobotAction
dict
The action actually sent to the motors, potentially clipped or modified by safety limits.

disconnect

@abc.abstractmethod
def disconnect(self) -> None
Disconnect from the robot and perform any necessary cleanup.

Helper Methods

_load_calibration

def _load_calibration(self, fpath: Path | None = None) -> None
Load calibration data from a file.
fpath
Path | None
Optional path to calibration file. Defaults to self.calibration_fpath.

_save_calibration

def _save_calibration(self, fpath: Path | None = None) -> None
Save calibration data to a file.
fpath
Path | None
Optional path to save calibration file. Defaults to self.calibration_fpath.

Context Manager

The Robot class supports context manager protocol for automatic resource management:
with robot:
    observation = robot.get_observation()
    robot.send_action(action)
# Robot is automatically disconnected

Example Implementation

from lerobot.robots import Robot, RobotConfig
from dataclasses import dataclass

@dataclass
class MyRobotConfig(RobotConfig):
    type: str = "my_robot"
    port: str = "/dev/ttyUSB0"

class MyRobot(Robot):
    config_class = MyRobotConfig
    name = "my_robot"
    
    @property
    def observation_features(self) -> dict:
        return {
            "joint_positions": float,
            "camera": (480, 640, 3),
        }
    
    @property
    def action_features(self) -> dict:
        return {
            "joint_positions": float,
        }
    
    @property
    def is_connected(self) -> bool:
        return self._connected
    
    @property
    def is_calibrated(self) -> bool:
        return True
    
    def connect(self, calibrate: bool = True) -> None:
        # Connect to hardware
        self._connected = True
    
    def calibrate(self) -> None:
        pass  # No calibration needed
    
    def configure(self) -> None:
        # Configure motors
        pass
    
    def get_observation(self) -> dict:
        return {
            "joint_positions": 0.0,
            "camera": np.zeros((480, 640, 3)),
        }
    
    def send_action(self, action: dict) -> dict:
        # Send action to motors
        return action
    
    def disconnect(self) -> None:
        self._connected = False

Factory Function

Use the factory function to create robots from configuration:
from lerobot.robots import make_robot_from_config

config = MyRobotConfig(id="robot_1")
robot = make_robot_from_config(config)
Location: src/lerobot/robots/utils.py:25

See Also

Build docs developers (and LLMs) love