Skip to content

Commit 02dc9d0

Browse files
author
erampone
committed
sample target pose around object pose in pushing
1 parent faade57 commit 02dc9d0

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

pybullet_robot_envs/envs/icub_envs/icub_push_gym_env.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self,
3434
control_orientation=0,
3535
obj_name=get_objects_list()[1],
3636
obj_pose_rnd_std=0,
37-
tg_pose_rnd_std=0,
37+
tg_pose_rnd_std=0.2,
3838
renders=False,
3939
max_steps=2000,
4040
reward_type=1):
@@ -134,17 +134,17 @@ def reset(self):
134134
for _ in range(100):
135135
p.stepSimulation()
136136

137-
self._tg_pose = self._sample_pose()
137+
world_obs, _ = self._world.get_observation()
138+
self._tg_pose = self._sample_pose(world_obs[:3])
138139

140+
self._robot.debug_gui()
141+
self._world.debug_gui()
142+
self.debug_gui()
139143

140144
# Let the world run for a bit
141145
for _ in range(100):
142146
p.stepSimulation()
143147

144-
self._robot.debug_gui()
145-
self._world.debug_gui()
146-
self.debug_gui()
147-
148148
robot_obs, _ = self._robot.get_observation()
149149
world_obs, _ = self._world.get_observation()
150150

@@ -332,32 +332,35 @@ def _compute_reward(self):
332332

333333
return reward
334334

335-
def _sample_pose(self):
335+
def _sample_pose(self, obj_pos):
336336

337337
# ws_lim = self._ws_lim
338338
x_min = self._world._ws_lim[0][0] + 0.064668
339339
x_max = self._world._ws_lim[0][1] - 0.05
340340

341-
px = x_min + 0.2 * (x_max - x_min)
342-
py = self._world._ws_lim[1][0] + 0.5 * (self._world._ws_lim[1][1] - self._world._ws_lim[1][0])
343-
pz = self._world.get_table_height()
341+
px = obj_pos[0] + 0.05
342+
py = obj_pos[1] + 0.05
343+
pz = obj_pos[2]
344+
345+
px = np.clip(px, x_min, x_max)
346+
py = np.clip(py, self._world._ws_lim[1][0], self._world._ws_lim[1][1])
344347

345348
if self._tg_pose_rnd_std > 0:
346349
# Add a Gaussian noise to position
347350
mu, sigma = 0, self._tg_pose_rnd_std
348351
noise = np.random.normal(mu, sigma, 2)
349352

350-
px = px + noise[0]
353+
px = obj_pos[0] + noise[0]
351354
px = np.clip(px, x_min, x_max)
352355

353-
py = py + noise[1]
356+
py = obj_pos[1] + noise[1]
354357
py = np.clip(py, self._world._ws_lim[1][0], self._world._ws_lim[1][1])
355358

356359
pose = (px, py, pz)
357360

358361
return pose
359362

360-
def debug_gui(self):
363+
def _debug_gui(self):
361364
p.addUserDebugLine(self._tg_pose, [self._tg_pose[0] + 0.1, self._tg_pose[1], self._tg_pose[2]], [1, 0, 0])
362365
p.addUserDebugLine(self._tg_pose, [self._tg_pose[0], self._tg_pose[1] + 0.1, self._tg_pose[2]], [0, 1, 0])
363366
p.addUserDebugLine(self._tg_pose, [self._tg_pose[0], self._tg_pose[1], self._tg_pose[2] + 0.1], [0, 0, 1])

pybullet_robot_envs/envs/panda_envs/panda_push_gym_env.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self,
4141
renders=False,
4242
max_steps=1000,
4343
dist_delta=0.03, joint_action_space=7,
44-
obj_pose_rnd_std=0, tg_pose_rnd_std=0,
44+
obj_pose_rnd_std=0, tg_pose_rnd_std=0.2,
4545
includeVelObs=True):
4646

4747
self._timeStep = 1. / 240.
@@ -123,20 +123,29 @@ def reset(self):
123123
p.setTimeStep(self._timeStep)
124124
self._env_step_counter = 0
125125

126-
self._robot.reset()
127-
self._world.reset()
128-
129-
self._target_pose = self._sample_pose()
130-
131126
p.setGravity(0, 0, -9.8)
132127

128+
self._robot.reset()
129+
# Let the world run for a bit
130+
for _ in range(100):
131+
p.stepSimulation()
132+
133+
self._world.reset()
133134
# Let the world run for a bit
134-
for _ in range(500):
135+
for _ in range(100):
135136
p.stepSimulation()
136137

138+
world_obs, _ = self._world.get_observation()
139+
140+
self._target_pose = self._sample_pose(world_obs[:3])
141+
137142
self._robot.debug_gui()
138143
self._world.debug_gui()
139-
self._debug_gui()
144+
self.debug_gui()
145+
146+
# Let the world run for a bit
147+
for _ in range(100):
148+
p.stepSimulation()
140149

141150
self._observation = self.get_extended_observation()
142151
return np.array(self._observation)
@@ -258,31 +267,35 @@ def _compute_reward(self):
258267
reward = np.float32(1000.0) + (100 - d2*80)
259268
return reward
260269

261-
def _sample_pose(self):
270+
def _sample_pose(self, obj_pos):
271+
262272
# ws_lim = self._ws_lim
263273
x_min = self._world._ws_lim[0][0] + 0.064668
264274
x_max = self._world._ws_lim[0][1] - 0.05
265275

266-
px = x_min + 0.2 * (x_max - x_min)
267-
py = self._world._ws_lim[1][0] + 0.5 * (self._world._ws_lim[1][1] - self._world._ws_lim[1][0])
268-
pz = self._world.get_table_height()
276+
px = obj_pos[0] + 0.05
277+
py = obj_pos[1] + 0.05
278+
pz = obj_pos[2]
279+
280+
px = np.clip(px, x_min, x_max)
281+
py = np.clip(py, self._world._ws_lim[1][0], self._world._ws_lim[1][1])
269282

270283
if self._tg_pose_rnd_std > 0:
271284
# Add a Gaussian noise to position
272285
mu, sigma = 0, self._tg_pose_rnd_std
273286
noise = np.random.normal(mu, sigma, 2)
274287

275-
px = px + noise[0]
288+
px = obj_pos[0] + noise[0]
276289
px = np.clip(px, x_min, x_max)
277290

278-
py = py + noise[1]
279-
py = np.clip(py, self._ws_lim[1][0], self._ws_lim[1][1])
291+
py = obj_pos[1] + noise[1]
292+
py = np.clip(py, self._world._ws_lim[1][0], self._world._ws_lim[1][1])
280293

281294
pose = (px, py, pz)
282295

283296
return pose
284297

285-
def _debug_gui(self):
298+
def debug_gui(self):
286299
p.addUserDebugLine(self._target_pose, [self._target_pose[0] + 0.1, self._target_pose[1], self._target_pose[2]], [1, 0, 0])
287300
p.addUserDebugLine(self._target_pose, [self._target_pose[0], self._target_pose[1] + 0.1, self._target_pose[2]], [0, 1, 0])
288301
p.addUserDebugLine(self._target_pose, [self._target_pose[0], self._target_pose[1], self._target_pose[2] + 0.1], [0, 0, 1])

pybullet_robot_envs/examples/test_envs/test_panda_push_gym_env.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
os.sys.path.insert(0, parentdir)
1010

1111
from pybullet_robot_envs.envs.panda_envs.panda_push_gym_env import pandaPushGymEnv
12-
from pybullet_robot_envs import robot_data
1312
import pybullet_data
1413

1514

0 commit comments

Comments
 (0)