UPDATE: two ball dataset
Browse files
dataset/multi_bb/multi_bb_2025-11-18_20-08-18.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7450a9cdabff9537081a228e37eefcb3a29469ed9ff32aa562148160718e5eaf
|
| 3 |
+
size 63591971
|
dataset/multi_bb/multi_bb_2025-11-18_20-08-18_metadata.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d53710d0992110467de164e14be85f1307ab9cf3dac3d84df4ae428e6e0970b2
|
| 3 |
+
size 478
|
multi_bb_collect.py
CHANGED
|
@@ -16,6 +16,7 @@ from dataset import TrajectoryBuffer
|
|
| 16 |
class Config:
|
| 17 |
"""Configuration for the multi-ball-in-bottle environment."""
|
| 18 |
|
|
|
|
| 19 |
bottle_length: float = 0.10 # x dimension (m)
|
| 20 |
bottle_width: float = 0.10 # y dimension (m)
|
| 21 |
bottle_height: float = 0.50 # z dimension (m)
|
|
@@ -60,7 +61,7 @@ class BottleMultiBallEnv:
|
|
| 60 |
# Cache indices for qpos/qvel blocks of each ball
|
| 61 |
self.ball_qpos_idx = []
|
| 62 |
self.ball_qvel_idx = []
|
| 63 |
-
for i in range(1,
|
| 64 |
name = f"ball{i}_free"
|
| 65 |
self.ball_qpos_idx.append(
|
| 66 |
self.model.jnt_qposadr[mujoco.mj_name2id(self.model, mujoco.mjtObj.mjOBJ_JOINT, name)]
|
|
@@ -97,7 +98,7 @@ class BottleMultiBallEnv:
|
|
| 97 |
<geom name="wall_yp" type="box" pos="0 {half_wid + t/2} {h/2}" size="{half_len} {t/2} {h/2}" rgba="0.7 0.7 0.7 1"/>
|
| 98 |
<geom name="wall_yn" type="box" pos="0 -{half_wid + t/2} {h/2}" size="{half_len} {t/2} {h/2}" rgba="0.7 0.7 0.7 1"/>
|
| 99 |
<!-- Balls (each as a root body because free joints must be root-level) -->
|
| 100 |
-
{"".join([self._ball_body_xml(i, ball_rad) for i in range(1,
|
| 101 |
<camera name="bottle_cam" pos="0 0 {h}" quat="0 -1 0 0" fovy="60"/>
|
| 102 |
</worldbody>
|
| 103 |
<asset>
|
|
@@ -124,7 +125,7 @@ class BottleMultiBallEnv:
|
|
| 124 |
positions = self._sample_initial_positions()
|
| 125 |
velocities = self._sample_initial_velocities()
|
| 126 |
|
| 127 |
-
for i in range(
|
| 128 |
qpos_idx = self.ball_qpos_idx[i]
|
| 129 |
qvel_idx = self.ball_qvel_idx[i]
|
| 130 |
pos = positions[i]
|
|
@@ -143,7 +144,7 @@ class BottleMultiBallEnv:
|
|
| 143 |
positions = []
|
| 144 |
margin = c.ball_radius * 2.5
|
| 145 |
tries = 0
|
| 146 |
-
while len(positions) <
|
| 147 |
x = self.rng.uniform(-c.bottle_length / 2 + margin, c.bottle_length / 2 - margin)
|
| 148 |
y = self.rng.uniform(-c.bottle_width / 2 + margin, c.bottle_width / 2 - margin)
|
| 149 |
z = self.rng.uniform(c.min_z, c.max_z)
|
|
@@ -157,8 +158,8 @@ class BottleMultiBallEnv:
|
|
| 157 |
|
| 158 |
def _sample_initial_velocities(self) -> np.ndarray:
|
| 159 |
c = self.config
|
| 160 |
-
speeds = self.rng.uniform(0.0, c.max_xy_speed, size=(
|
| 161 |
-
angles = self.rng.uniform(0.0, 2 * np.pi, size=(
|
| 162 |
vx = speeds * np.cos(angles)
|
| 163 |
vy = speeds * np.sin(angles)
|
| 164 |
vz = np.zeros_like(vx)
|
|
@@ -172,7 +173,7 @@ class BottleMultiBallEnv:
|
|
| 172 |
# Collect positions and velocities for four balls
|
| 173 |
pos_list: List[np.ndarray] = []
|
| 174 |
vel_list: List[np.ndarray] = []
|
| 175 |
-
for i in range(
|
| 176 |
qpos_idx = self.ball_qpos_idx[i]
|
| 177 |
qvel_idx = self.ball_qvel_idx[i]
|
| 178 |
pos_list.append(self.data.qpos[qpos_idx : qpos_idx + 3].copy())
|
|
@@ -265,6 +266,7 @@ def parse_args():
|
|
| 265 |
parser.add_argument("--headless", action="store_true", help="Disable on-screen rendering")
|
| 266 |
parser.add_argument("--realtime", action="store_true", help="Sleep to match real time")
|
| 267 |
parser.add_argument("--demo", action="store_true", help="Run a short demo instead of full collection")
|
|
|
|
| 268 |
return parser.parse_args()
|
| 269 |
|
| 270 |
|
|
@@ -272,7 +274,7 @@ def main():
|
|
| 272 |
args = parse_args()
|
| 273 |
np.random.seed(args.seed)
|
| 274 |
|
| 275 |
-
config = Config()
|
| 276 |
env = BottleMultiBallEnv(headless=args.headless, config=config, seed=args.seed)
|
| 277 |
|
| 278 |
try:
|
|
|
|
| 16 |
class Config:
|
| 17 |
"""Configuration for the multi-ball-in-bottle environment."""
|
| 18 |
|
| 19 |
+
num_balls: int = 4
|
| 20 |
bottle_length: float = 0.10 # x dimension (m)
|
| 21 |
bottle_width: float = 0.10 # y dimension (m)
|
| 22 |
bottle_height: float = 0.50 # z dimension (m)
|
|
|
|
| 61 |
# Cache indices for qpos/qvel blocks of each ball
|
| 62 |
self.ball_qpos_idx = []
|
| 63 |
self.ball_qvel_idx = []
|
| 64 |
+
for i in range(1, self.config.num_balls + 1):
|
| 65 |
name = f"ball{i}_free"
|
| 66 |
self.ball_qpos_idx.append(
|
| 67 |
self.model.jnt_qposadr[mujoco.mj_name2id(self.model, mujoco.mjtObj.mjOBJ_JOINT, name)]
|
|
|
|
| 98 |
<geom name="wall_yp" type="box" pos="0 {half_wid + t/2} {h/2}" size="{half_len} {t/2} {h/2}" rgba="0.7 0.7 0.7 1"/>
|
| 99 |
<geom name="wall_yn" type="box" pos="0 -{half_wid + t/2} {h/2}" size="{half_len} {t/2} {h/2}" rgba="0.7 0.7 0.7 1"/>
|
| 100 |
<!-- Balls (each as a root body because free joints must be root-level) -->
|
| 101 |
+
{"".join([self._ball_body_xml(i, ball_rad) for i in range(1, self.config.num_balls + 1)])}
|
| 102 |
<camera name="bottle_cam" pos="0 0 {h}" quat="0 -1 0 0" fovy="60"/>
|
| 103 |
</worldbody>
|
| 104 |
<asset>
|
|
|
|
| 125 |
positions = self._sample_initial_positions()
|
| 126 |
velocities = self._sample_initial_velocities()
|
| 127 |
|
| 128 |
+
for i in range(self.config.num_balls):
|
| 129 |
qpos_idx = self.ball_qpos_idx[i]
|
| 130 |
qvel_idx = self.ball_qvel_idx[i]
|
| 131 |
pos = positions[i]
|
|
|
|
| 144 |
positions = []
|
| 145 |
margin = c.ball_radius * 2.5
|
| 146 |
tries = 0
|
| 147 |
+
while len(positions) < c.num_balls:
|
| 148 |
x = self.rng.uniform(-c.bottle_length / 2 + margin, c.bottle_length / 2 - margin)
|
| 149 |
y = self.rng.uniform(-c.bottle_width / 2 + margin, c.bottle_width / 2 - margin)
|
| 150 |
z = self.rng.uniform(c.min_z, c.max_z)
|
|
|
|
| 158 |
|
| 159 |
def _sample_initial_velocities(self) -> np.ndarray:
|
| 160 |
c = self.config
|
| 161 |
+
speeds = self.rng.uniform(0.0, c.max_xy_speed, size=(c.num_balls,))
|
| 162 |
+
angles = self.rng.uniform(0.0, 2 * np.pi, size=(c.num_balls,))
|
| 163 |
vx = speeds * np.cos(angles)
|
| 164 |
vy = speeds * np.sin(angles)
|
| 165 |
vz = np.zeros_like(vx)
|
|
|
|
| 173 |
# Collect positions and velocities for four balls
|
| 174 |
pos_list: List[np.ndarray] = []
|
| 175 |
vel_list: List[np.ndarray] = []
|
| 176 |
+
for i in range(self.config.num_balls):
|
| 177 |
qpos_idx = self.ball_qpos_idx[i]
|
| 178 |
qvel_idx = self.ball_qvel_idx[i]
|
| 179 |
pos_list.append(self.data.qpos[qpos_idx : qpos_idx + 3].copy())
|
|
|
|
| 266 |
parser.add_argument("--headless", action="store_true", help="Disable on-screen rendering")
|
| 267 |
parser.add_argument("--realtime", action="store_true", help="Sleep to match real time")
|
| 268 |
parser.add_argument("--demo", action="store_true", help="Run a short demo instead of full collection")
|
| 269 |
+
parser.add_argument("--num_balls", type=int, default=2, help="Number of balls in the bottle")
|
| 270 |
return parser.parse_args()
|
| 271 |
|
| 272 |
|
|
|
|
| 274 |
args = parse_args()
|
| 275 |
np.random.seed(args.seed)
|
| 276 |
|
| 277 |
+
config = Config(num_balls=args.num_balls)
|
| 278 |
env = BottleMultiBallEnv(headless=args.headless, config=config, seed=args.seed)
|
| 279 |
|
| 280 |
try:
|