Skip to content

Commit

Permalink
Add stretch boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
aliberts committed Sep 6, 2024
1 parent 64f0126 commit 4e531f0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lerobot/common/robot_devices/robots/factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import hydra
from omegaconf import DictConfig

from lerobot.common.robot_devices.robots.utils import Robot

def make_robot(cfg: DictConfig):

def make_robot(cfg: DictConfig) -> Robot:
robot = hydra.utils.instantiate(cfg)
return robot
43 changes: 43 additions & 0 deletions lerobot/common/robot_devices/robots/stretch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from stretch_body.gamepad_teleop import GamePadTeleop
from stretch_body.robot import Robot as Stretch


class LeRobotStretchTeleop(GamePadTeleop):
"""Wrapper of stretch_body.gamepad_teleop.GamePadTeleop"""

def __init__(self):
super().__init__()


class LeRobotStretch(Stretch):
"""Wrapper of stretch_body.robot.Robot"""

def __init__(self, teleoperate: bool = False, **kwargs):
super().__init__()
self.robot_type = "stretch"
self.is_connected = False
self.teleop = GamePadTeleop(robot_instance=False) if teleoperate else None

def connect(self):
self.is_connected = self.startup()

def run_calibration(self):
if not self.is_homed():
self.home()

def teleop_step(self, record_data=False):
if self.teleop is None:
raise ValueError
...

def capture_observation(self): ...

def send_action(self, action): ...

def disconnect(self):
self.stop()
if self.teleop is not None:
self.teleop.stop()

def __del__(self):
self.disconnect()
3 changes: 2 additions & 1 deletion lerobot/common/robot_devices/robots/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ def get_arm_id(name, arm_type):


class Robot(Protocol):
def init_teleop(self): ...
def connect(self): ...
def run_calibration(self): ...
def teleop_step(self, record_data=False): ...
def capture_observation(self): ...
def send_action(self, action): ...
def disconnect(self): ...
3 changes: 3 additions & 0 deletions lerobot/configs/robot/stretch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_target_: lerobot.common.robot_devices.robots.stretch.LeRobotStretch
robot_type: stretch
teleoperate: false
8 changes: 8 additions & 0 deletions lerobot/scripts/control_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
from lerobot.common.datasets.video_utils import encode_video_frames
from lerobot.common.policies.factory import make_policy
from lerobot.common.robot_devices.robots.factory import make_robot
from lerobot.common.robot_devices.robots.stretch import LeRobotStretch
from lerobot.common.robot_devices.robots.utils import Robot, get_arm_id
from lerobot.common.robot_devices.utils import busy_wait
from lerobot.common.utils.utils import get_safe_torch_device, init_hydra_config, init_logging, set_global_seed
Expand Down Expand Up @@ -242,6 +243,13 @@ def is_headless():


def calibrate(robot: Robot, arms: list[str] | None):
if isinstance(robot, LeRobotStretch):
if not robot.is_connected:
robot.connect()
if not robot.is_homed():
robot.home()
return

available_arms = []
for name in robot.follower_arms:
arm_id = get_arm_id(name, "follower")
Expand Down

0 comments on commit 4e531f0

Please sign in to comment.