-
Notifications
You must be signed in to change notification settings - Fork 0
Add depth support #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
0d6cf32
09a8c1c
7e67607
0e67f68
c7a0ba4
2404e64
7e3534b
7f8c720
b9e82c0
735a190
c88b5f2
9c3c6f4
08eef48
ce60a31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| import os | ||
| import shutil | ||
|
|
||
| import transforms3d as t3d | ||
| import numpy as np | ||
| from scipy.spatial.transform import Rotation as R | ||
| from alignit.robots.xarm import Xarm | ||
| from alignit.utils.zhou import se3_sixd | ||
| import argparse # Added for command line arguments | ||
stojicnnnn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import draccus | ||
| from alignit.config import RecordConfig | ||
|
||
| from alignit.robots.xarmsim import XarmSim | ||
| from datasets import ( | ||
| Dataset, | ||
| Features, | ||
|
|
@@ -14,13 +19,6 @@ | |
| concatenate_datasets, | ||
| ) | ||
|
|
||
| from alignit.robots.xarmsim import XarmSim | ||
| from alignit.robots.xarm import Xarm | ||
| from alignit.utils.zhou import se3_sixd | ||
| import draccus | ||
| from alignit.config import RecordConfig | ||
|
|
||
|
|
||
| def generate_spiral_trajectory(start_pose, cfg): | ||
| """Generate spiral trajectory using configuration parameters.""" | ||
| trajectory = [] | ||
|
|
@@ -76,13 +74,12 @@ def generate_spiral_trajectory(start_pose, cfg): | |
|
|
||
| return trajectory | ||
|
|
||
|
|
||
| @draccus.wrap() | ||
| def main(cfg: RecordConfig): | ||
| """Record alignment dataset using configuration parameters.""" | ||
| robot = XarmSim() | ||
| features = Features( | ||
| {"images": Sequence(Image()), "action": Sequence(Value("float32"))} | ||
| {"images": Sequence(Image()), "action": Sequence(Value("float32")), "depth": Sequence(Image())} | ||
| ) | ||
|
|
||
| for episode in range(cfg.episodes): | ||
|
|
@@ -91,35 +88,36 @@ def main(cfg: RecordConfig): | |
| robot.servo_to_pose(pose_alignment_target, lin_tol=0.015, ang_tol=0.015) | ||
|
|
||
| robot.servo_to_pose( | ||
| pose_alignment_target, | ||
| lin_tol=cfg.lin_tol_alignment, | ||
| ang_tol=cfg.ang_tol_alignment, | ||
| pose_alignment_target, | ||
stojicnnnn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| lin_tol=cfg.lin_tol_alignment, | ||
| ang_tol=cfg.ang_tol_alignment, | ||
| ) | ||
|
|
||
| trajectory = generate_spiral_trajectory(pose_start, cfg.trajectory) | ||
|
|
||
|
|
||
| print(f"Generated trajectory with {len(trajectory)} poses for episode {episode+1}",flush=True) | ||
| frames = [] | ||
| for pose in trajectory: | ||
| robot.servo_to_pose( | ||
| pose, lin_tol=cfg.lin_tol_trajectory, ang_tol=cfg.ang_tol_trajectory | ||
| ) | ||
| current_pose = robot.pose() | ||
|
|
||
| action_pose = np.linalg.inv(current_pose) @ pose_alignment_target | ||
| action_sixd = se3_sixd(action_pose) | ||
|
|
||
| observation = robot.get_observation() | ||
| frame = { | ||
| "images": [observation["camera.rgb"].copy()], | ||
| "action": action_sixd, | ||
| } | ||
| frames.append(frame) | ||
|
|
||
| robot.servo_to_pose( | ||
| pose, lin_tol=cfg.lin_tol_trajectory, ang_tol=cfg.ang_tol_trajectory | ||
| ) | ||
| current_pose = robot.pose() | ||
|
|
||
| action_pose = np.linalg.inv(current_pose) @ pose_alignment_target | ||
| action_sixd = se3_sixd(action_pose) | ||
|
|
||
| observation = robot.get_observation() | ||
| frame = { | ||
| "images": [observation["camera.rgb"].copy()], | ||
| "action": action_sixd, | ||
| "depth": [observation["camera.rgb.depth"].copy()], | ||
| } | ||
| frames.append(frame) | ||
| print(f"Episode {episode+1} completed with {len(frames)} frames.") | ||
|
|
||
| episode_dataset = Dataset.from_list(frames, features=features) | ||
| if episode == 0: | ||
| combined_dataset = episode_dataset | ||
| print("Writing do dataset to disk for the first time.") | ||
| else: | ||
| previous_dataset = load_from_disk(cfg.dataset.path) | ||
| previous_dataset = previous_dataset.cast(features) | ||
|
|
@@ -131,9 +129,10 @@ def main(cfg: RecordConfig): | |
| if os.path.exists(cfg.dataset.path): | ||
| shutil.rmtree(cfg.dataset.path) | ||
| shutil.move(temp_path, cfg.dataset.path) | ||
| print(f"Saved dataset to {cfg.dataset.path}") | ||
|
|
||
| robot.disconnect() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| main() | ||
Uh oh!
There was an error while loading. Please reload this page.