|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
from lerobot.datasets.lerobot_dataset import LeRobotDataset
|
|
|
from lerobot.model.kinematics import RobotKinematics
|
|
|
from lerobot.processor import RobotAction, RobotObservation, RobotProcessorPipeline
|
|
|
from lerobot.processor.converters import (
|
|
|
robot_action_observation_to_transition,
|
|
|
transition_to_robot_action,
|
|
|
)
|
|
|
from lerobot.robots.so100_follower.config_so100_follower import SO100FollowerConfig
|
|
|
from lerobot.robots.so100_follower.robot_kinematic_processor import (
|
|
|
InverseKinematicsEEToJoints,
|
|
|
)
|
|
|
from lerobot.robots.so100_follower.so100_follower import SO100Follower
|
|
|
from lerobot.utils.constants import ACTION
|
|
|
from lerobot.utils.robot_utils import busy_wait
|
|
|
from lerobot.utils.utils import log_say
|
|
|
|
|
|
EPISODE_IDX = 0
|
|
|
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
|
|
|
|
|
|
|
|
robot_config = SO100FollowerConfig(
|
|
|
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", use_degrees=True
|
|
|
)
|
|
|
|
|
|
|
|
|
robot = SO100Follower(robot_config)
|
|
|
|
|
|
|
|
|
kinematics_solver = RobotKinematics(
|
|
|
urdf_path="./SO101/so101_new_calib.urdf",
|
|
|
target_frame_name="gripper_frame_link",
|
|
|
joint_names=list(robot.bus.motors.keys()),
|
|
|
)
|
|
|
|
|
|
|
|
|
robot_ee_to_joints_processor = RobotProcessorPipeline[tuple[RobotAction, RobotObservation], RobotAction](
|
|
|
steps=[
|
|
|
InverseKinematicsEEToJoints(
|
|
|
kinematics=kinematics_solver,
|
|
|
motor_names=list(robot.bus.motors.keys()),
|
|
|
initial_guess_current_joints=False,
|
|
|
),
|
|
|
],
|
|
|
to_transition=robot_action_observation_to_transition,
|
|
|
to_output=transition_to_robot_action,
|
|
|
)
|
|
|
|
|
|
|
|
|
dataset = LeRobotDataset(HF_REPO_ID, episodes=[EPISODE_IDX])
|
|
|
|
|
|
episode_frames = dataset.hf_dataset.filter(lambda x: x["episode_index"] == EPISODE_IDX)
|
|
|
actions = episode_frames.select_columns(ACTION)
|
|
|
|
|
|
|
|
|
robot.connect()
|
|
|
|
|
|
if not robot.is_connected:
|
|
|
raise ValueError("Robot is not connected!")
|
|
|
|
|
|
print("Starting replay loop...")
|
|
|
log_say(f"Replaying episode {EPISODE_IDX}")
|
|
|
for idx in range(len(episode_frames)):
|
|
|
t0 = time.perf_counter()
|
|
|
|
|
|
|
|
|
ee_action = {
|
|
|
name: float(actions[idx][ACTION][i]) for i, name in enumerate(dataset.features[ACTION]["names"])
|
|
|
}
|
|
|
|
|
|
|
|
|
robot_obs = robot.get_observation()
|
|
|
|
|
|
|
|
|
joint_action = robot_ee_to_joints_processor((ee_action, robot_obs))
|
|
|
|
|
|
|
|
|
_ = robot.send_action(joint_action)
|
|
|
|
|
|
busy_wait(1.0 / dataset.fps - (time.perf_counter() - t0))
|
|
|
|
|
|
|
|
|
robot.disconnect()
|
|
|
|