Data collection
RoBits support kinesthetic teaching, teleoperation as well as scripted demonstrations. The easiest way is to start the robot app and toggle the “Kinesthetic Teaching” mode. Now you can move the robot arm to the desired position. Close the gripper using the “Gripper” toggle button. Press the “Add Waypoint” button to save the current pose of the robot as waypoints. Once you are done, press the “Save” button to serialize all current waypoints. You can restore the state with “Load” button. Press “Replay” button to execute the currently loaded waypoints. Make sure to complete the System and Robot setup and the Configuration instructions.
Note
More available soon
Collecting data is quite simple and can be done by using a with statement.
Given a robot instance and a output_path you can create a dataset with:
from robits.dataset.io.recorder import DatasetRecorder
from robits.dataset.io.writer import DatasetWriter
with DatasetWriter(output_path, DatasetRecorder(robot)):
print("Move robot")
See the robits.dataset.io.writer.DatasetWriter class for more details.
Scripted data collection
Here is an example on how collect proprioception data.
1#!/usr/bin/env python3
2
3import numpy as np
4
5import rich_click as click
6from click_prompt import filepath_option
7
8from robits.core.abc.control import control_types
9
10from robits.dataset.io.recorder import DatasetRecorder
11from robits.dataset.io.writer import DatasetWriter
12
13from robits.cli import cli_utils
14from robits.cli import cli_options
15
16
17@click.command
18@filepath_option(
19 "--output-path", default="/tmp/data/stack_blocks", help="Where to save the dataset."
20)
21@cli_options.robot()
22def cli(output_path, robot):
23
24 console = cli_utils.console
25 writer = DatasetWriter(output_path, DatasetRecorder(robot))
26
27 orientation_delta = np.array([0, -1, 0, 0])
28 position_delta = np.array([0, 0, 0.05])
29
30 console.rule("Moving robot to default pose")
31 robot.control.move_home()
32
33 console.rule("Starting data collection.")
34
35 with writer:
36
37 with robot.control(control_types.cartesian) as ctrl:
38
39 console.print("moving up.")
40 ctrl.update((position_delta, orientation_delta), relative=True)
41 console.print("moving down.")
42 ctrl.update((-position_delta, orientation_delta), relative=True)
43 console.print("closing gripper.")
44 robot.gripper.close()
45 console.print("moving up again.")
46 ctrl.update((position_delta, orientation_delta), relative=True)
47
48 console.rule("Done collecting data.")
49
50
51if __name__ == "__main__":
52 cli_utils.setup_cli()
53 cli()
Stack blocks
When interacting with the environment it is necessary to get a grasp pose. Specifying grasp points with an interactive gui is quite fast.
1#!/usr/bin/env python3
2
3import time
4import logging
5
6
7import open3d as o3d
8
9import rich_click as click
10from click_prompt import filepath_option
11
12from robits.core.abc.control import control_types
13
14from robits.utils import vision_utils
15from robits.dataset.io.recorder import DatasetRecorder
16from robits.dataset.io.writer import DatasetWriter
17
18from robits.sim.env_design import env_designer
19
20from robits.cli import cli_utils
21from robits.cli import cli_options
22
23logger = logging.getLogger(__name__)
24
25
26@click.command
27@filepath_option(
28 "--output-path", default="/tmp/data/stack_blocks", help="Where to save the ."
29)
30@cli_options.robot()
31def cli(output_path, robot):
32
33 env_designer.add_blocks()
34
35 console = cli_utils.console
36
37 console.rule("Starting")
38 console.print(
39 "Select two blocks with shift + left click. Use shift + right click to undo."
40 )
41
42 default_robot_orientation = [0, -1, 0, 0]
43
44 camera = robot.cameras[0]
45 recorder = DatasetRecorder(robot)
46 writer = DatasetWriter(output_path, recorder)
47
48 logger.info("Moving home.")
49 robot.control.move_home()
50 robot.gripper.open()
51
52 camera_data, _info = camera.get_camera_data()
53
54 pcd = vision_utils.depth_to_pcd(camera_data, camera, apply_extrinsics=True)
55
56 vis = o3d.visualization.VisualizerWithEditing()
57 vis.create_window(window_name="Select two blocks")
58 vis.add_geometry(pcd)
59 vis.run()
60 vis.destroy_window()
61
62 points = vis.get_picked_points()
63
64 if len(points) != 2:
65 console.print("Insufficient points selected")
66 return
67
68 with writer:
69
70 time.sleep(0.1)
71
72 with robot.control(control_types.cartesian) as ctrl:
73
74 target_point = pcd.points[points[0]].copy()
75 target_point[2] += 0.05
76 ctrl.update((target_point, default_robot_orientation))
77
78 target_point = pcd.points[points[0]].copy()
79 target_point[2] -= 0.01
80 ctrl.update((target_point, default_robot_orientation))
81 robot.gripper.close()
82
83 target_point = pcd.points[points[1]].copy()
84 target_point[2] += 0.15
85 ctrl.update((target_point, default_robot_orientation))
86
87 target_point = pcd.points[points[1]].copy()
88 target_point[2] += 0.05
89 ctrl.update((target_point, default_robot_orientation))
90 robot.gripper.open()
91
92 robot.control.move_home()
93
94 time.sleep(1)
95
96 console.rule("Done")
97
98
99if __name__ == "__main__":
100 cli_utils.setup_cli()
101 cli()