Skip to content

Commit

Permalink
try this for fun
Browse files Browse the repository at this point in the history
  • Loading branch information
NishanthJKumar committed Oct 23, 2023
1 parent 221bae6 commit 0316c74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion predicators/approaches/active_sampler_learning_approach.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def _sample(state: State, goal: Set[GroundAtom], rng: np.random.Generator,
print(best_sample_will_work)
print(learned_sampler_input)
print(option.name)
import ipdb; ipdb.set_trace()
# import ipdb; ipdb.set_trace()
if strategy in ["greedy", "epsilon_greedy"]:
idx = int(np.argmax(scores))
if strategy == "epsilon_greedy" and rng.uniform(
Expand Down
20 changes: 17 additions & 3 deletions predicators/envs/sticky_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class StickyTableEnv(BaseEnv):
x_ub: ClassVar[float] = 1.0
y_lb: ClassVar[float] = 0.0
y_ub: ClassVar[float] = 1.0
reachable_thresh: ClassVar[float] = 0.25
reachable_thresh: ClassVar[float] = 0.1
objs_scale: ClassVar[float] = 0.25 # as a function of table radius
sticky_surface_mode: ClassVar[str] = "half" # half or whole
# Types
Expand Down Expand Up @@ -151,17 +151,21 @@ def simulate(self, state: State, action: Action) -> State:
if self._action_grasps_object(act_x, act_y, cube,
state):
next_state.set(cube, "held", 1.0)
assert self._Holding_holds(next_state, [cube])
elif obj_type_id == 1.0:
if self._action_grasps_object(act_x, act_y, ball,
state):
next_state.set(ball, "held", 1.0)
assert self._Holding_holds(next_state, [ball])
else:
assert obj_type_id == 2.0
if self._action_grasps_object(act_x, act_y, cup,
state):
next_state.set(cup, "held", 1.0)
if ball_in_cup:
next_state.set(ball, "held", 1.0)
assert self._Holding_holds(next_state, [ball])
assert self._Holding_holds(next_state, [cup])
# Placing logic.
else:
if obj_being_held is not None:
Expand Down Expand Up @@ -223,6 +227,8 @@ def simulate(self, state: State, action: Action) -> State:
next_state.set(ball, "y", act_y)
next_state.set(ball, "held", 0.0)
assert self._BallInCup_holds(next_state, [ball, cup])
if self._OnFloor_holds(next_state, [cup]):
assert self._OnFloor_holds(next_state, [ball])
if ball_only < 0.5:
assert self._HandEmpty_holds(next_state, [])
else:
Expand Down Expand Up @@ -555,9 +561,17 @@ def _sample_floor_point_around_table(
x = state.get(table, "x")
y = state.get(table, "y")
radius = state.get(table, "radius")
dist = radius + rng.uniform(radius / 10, radius / 4)
dist_from_table = self.objs_scale * radius
dist = radius + rng.uniform(radius + dist_from_table, radius + (1.15 * dist_from_table))
theta = rng.uniform(0, 2 * np.pi)
return (x + dist * np.cos(theta), y + dist * np.sin(theta))
sampled_x = x + dist * np.cos(theta)
sampled_y = y + dist * np.sin(theta)
while sampled_x < self.x_lb or sampled_x > self.x_ub or sampled_y < self.y_lb or sampled_y > self.y_ub:
dist = radius + rng.uniform(radius + dist_from_table, radius + (1.15 * dist_from_table))
theta = rng.uniform(0, 2 * np.pi)
sampled_x = x + dist * np.cos(theta)
sampled_y = y + dist * np.sin(theta)
return (sampled_x, sampled_y)

@classmethod
def exists_robot_collision(self, state: State) -> bool:
Expand Down

0 comments on commit 0316c74

Please sign in to comment.