Skip to content

Commit 89b02c3

Browse files
committed
open and close skill
1 parent be3cebb commit 89b02c3

5 files changed

Lines changed: 198 additions & 9 deletions

File tree

predicators/envs/spot_env.py

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,15 @@ def _holding_classifier(state: State, objects: Sequence[Object]) -> bool:
10721072
return False
10731073
return state.get(obj, "held") > 0.5
10741074

1075+
def _open_classifier(state: State, objects: Sequence[Object]) -> bool:
1076+
obj = objects[0]
1077+
return False
1078+
1079+
def _not_open_classifier(state: State, objects: Sequence[Object]) -> bool:
1080+
obj = objects[0]
1081+
if not obj.is_instance(_movable_object_type):
1082+
return True
1083+
return not _open_classifier(state, objects)
10751084

10761085
def _not_holding_classifier(state: State, objects: Sequence[Object]) -> bool:
10771086
_, obj = objects
@@ -1395,6 +1404,10 @@ def _get_sweeping_surface_for_container(container: Object,
13951404
return None
13961405

13971406

1407+
_Open = Predicate("Open", [_movable_object_type],
1408+
_open_classifier)
1409+
_NotOpen = Predicate("NotOpen", [_movable_object_type],
1410+
_not_open_classifier)
13981411
_NEq = Predicate("NEq", [_base_object_type, _base_object_type],
13991412
_neq_classifier)
14001413
_On = Predicate("On", [_movable_object_type, _base_object_type],
@@ -1448,7 +1461,7 @@ def _get_sweeping_surface_for_container(container: Object,
14481461
_HandEmpty, _Holding, _NotHolding, _InHandView, _InView, _Reachable,
14491462
_Blocking, _NotBlocked, _ContainerReadyForSweeping, _IsPlaceable,
14501463
_IsNotPlaceable, _IsSweeper, _HasFlatTopSurface, _RobotReadyForSweeping,
1451-
_IsSemanticallyGreaterThan
1464+
_IsSemanticallyGreaterThan, _Open, _NotOpen
14521465
}
14531466
_NONPERCEPT_PREDICATES: Set[Predicate] = set()
14541467

@@ -1685,6 +1698,44 @@ def _create_operators() -> Iterator[STRIPSOperator]:
16851698
ignore_effs = {_InHandView, _Reachable, _RobotReadyForSweeping, _Blocking}
16861699
yield STRIPSOperator("DragToBlockObject", parameters, preconds, add_effs,
16871700
del_effs, ignore_effs)
1701+
1702+
# DragToOpenObject
1703+
robot = Variable("?robot", _robot_type)
1704+
obj = Variable("?obj", _movable_object_type)
1705+
parameters = [robot, obj]
1706+
preconds = {
1707+
LiftedAtom(_Holding, [robot, obj]),
1708+
}
1709+
add_effs = {
1710+
LiftedAtom(_HandEmpty, [robot]),
1711+
LiftedAtom(_NotHolding, [robot, obj]),
1712+
LiftedAtom(_Open, [obj]),
1713+
}
1714+
del_effs = {
1715+
LiftedAtom(_Holding, [robot, obj]),
1716+
}
1717+
ignore_effs = {_InHandView, _Reachable, _RobotReadyForSweeping, _Blocking}
1718+
yield STRIPSOperator("DragToOpenObject", parameters, preconds, add_effs,
1719+
del_effs, ignore_effs)
1720+
1721+
# DragToCloseObject
1722+
robot = Variable("?robot", _robot_type)
1723+
obj = Variable("?obj", _movable_object_type)
1724+
parameters = [robot, obj]
1725+
preconds = {
1726+
LiftedAtom(_Holding, [robot, obj]),
1727+
}
1728+
add_effs = {
1729+
LiftedAtom(_HandEmpty, [robot]),
1730+
LiftedAtom(_NotHolding, [robot, obj]),
1731+
LiftedAtom(_NotOpen, [obj]),
1732+
}
1733+
del_effs = {
1734+
LiftedAtom(_Holding, [robot, obj]),
1735+
}
1736+
ignore_effs = {_InHandView, _Reachable, _RobotReadyForSweeping, _Blocking}
1737+
yield STRIPSOperator("DragToCloseObject", parameters, preconds, add_effs,
1738+
del_effs, ignore_effs)
16881739

16891740
# MoveToReadySweep
16901741
robot = Variable("?robot", _robot_type)
@@ -3062,10 +3113,10 @@ def _detection_id_to_obj(self) -> Dict[ObjectDetectionID, Object]:
30623113

30633114
detection_id_to_obj: Dict[ObjectDetectionID, Object] = {}
30643115

3065-
red_block = Object("red_block", _movable_object_type)
3066-
red_block_detection = LanguageObjectDetectionID(
3067-
"red block/orange block/yellow block")
3068-
detection_id_to_obj[red_block_detection] = red_block
3116+
blue_block = Object("blue_block", _movable_object_type)
3117+
blue_block_detection = LanguageObjectDetectionID(
3118+
"blue block/blue-ish block/blue-green block")
3119+
detection_id_to_obj[blue_block_detection] = blue_block
30693120

30703121
for obj, pose in get_known_immovable_objects().items():
30713122
detection_id = KnownStaticObjectDetectionID(obj.name, pose)
@@ -3074,8 +3125,61 @@ def _detection_id_to_obj(self) -> Dict[ObjectDetectionID, Object]:
30743125
return detection_id_to_obj
30753126

30763127
def _generate_goal_description(self) -> GoalDescription:
3077-
return "pick up the red block"
3128+
return "pick up the blue block"
30783129

30793130
def _get_dry_task(self, train_or_test: str,
30803131
task_idx: int) -> EnvironmentTask:
30813132
raise NotImplementedError("Dry task generation not implemented.")
3133+
3134+
3135+
class LISSpotBlockDrawerEnv(SpotRearrangementEnv):
3136+
"""An extremely basic environment where a block needs to be picked up and
3137+
is specifically used for testing in the LIS Spot room.
3138+
3139+
Very simple and mostly just for testing.
3140+
"""
3141+
3142+
def __init__(self, use_gui: bool = True) -> None:
3143+
super().__init__(use_gui)
3144+
3145+
op_to_name = {o.name: o for o in _create_operators()}
3146+
op_names_to_keep = {
3147+
"MoveToReachObject",
3148+
"MoveToHandViewObject",
3149+
"PickObjectToDrag",
3150+
"DragToOpenObject",
3151+
"DragToCloseObject",
3152+
}
3153+
self._strips_operators = {op_to_name[o] for o in op_names_to_keep}
3154+
3155+
@classmethod
3156+
def get_name(cls) -> str:
3157+
return "lis_spot_block_drawer_env"
3158+
3159+
@property
3160+
def _detection_id_to_obj(self) -> Dict[ObjectDetectionID, Object]:
3161+
3162+
detection_id_to_obj: Dict[ObjectDetectionID, Object] = {}
3163+
3164+
blue_block = Object("blue_block", _movable_object_type)
3165+
blue_block_detection = LanguageObjectDetectionID(
3166+
"blue block/blue-ish block/blue-green block")
3167+
detection_id_to_obj[blue_block_detection] = blue_block
3168+
3169+
green_handle = Object("green_handle", _movable_object_type)
3170+
green_handle_detection = LanguageObjectDetectionID(
3171+
"green duct tape/green handle/green object")
3172+
detection_id_to_obj[green_handle_detection] = green_handle
3173+
3174+
for obj, pose in get_known_immovable_objects().items():
3175+
detection_id = KnownStaticObjectDetectionID(obj.name, pose)
3176+
detection_id_to_obj[detection_id] = obj
3177+
3178+
return detection_id_to_obj
3179+
3180+
def _generate_goal_description(self) -> GoalDescription:
3181+
return "open the drawer"
3182+
3183+
def _get_dry_task(self, train_or_test: str,
3184+
task_idx: int) -> EnvironmentTask:
3185+
raise NotImplementedError("Dry task generation not implemented.")

predicators/ground_truth_models/spot_env/nsrts.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def _get_approach_angle_bounds(obj: Object,
121121
if surface is not None and surface.name in angle_bounds:
122122
return angle_bounds[surface.name]
123123
# Default to all possible approach angles.
124+
if obj.name == 'green_handle':
125+
return (np.pi/2, np.pi/2)
124126
return (-np.pi, np.pi)
125127

126128

@@ -230,6 +232,20 @@ def _drag_to_unblock_object_sampler(state: State, goal: Set[GroundAtom],
230232
del state, goal, objs, rng # randomization coming soon
231233
return np.array([0.0, 0.0, np.pi / 1.5])
232234

235+
def _drag_to_open_object_sampler(state: State, goal: Set[GroundAtom],
236+
rng: np.random.Generator,
237+
objs: Sequence[Object]) -> Array:
238+
# Parameters are relative dx, dy, dyaw to move while holding.
239+
del state, goal, objs, rng # randomization coming soon
240+
return np.array([-0.5, 0.0, 0.0])
241+
242+
def _drag_to_close_object_sampler(state: State, goal: Set[GroundAtom],
243+
rng: np.random.Generator,
244+
objs: Sequence[Object]) -> Array:
245+
# Parameters are relative dx, dy, dyaw to move while holding.
246+
del state, goal, objs, rng # randomization coming soon
247+
return np.array([0.5, 0.0, 0.0])
248+
233249

234250
def _drag_to_block_object_sampler(state: State, goal: Set[GroundAtom],
235251
rng: np.random.Generator,
@@ -288,7 +304,7 @@ def get_env_names(cls) -> Set[str]:
288304
"spot_cube_env", "spot_soda_floor_env", "spot_soda_table_env",
289305
"spot_soda_bucket_env", "spot_soda_chair_env",
290306
"spot_main_sweep_env", "spot_ball_and_cup_sticky_table_env",
291-
"spot_brush_shelf_env", "lis_spot_block_floor_env"
307+
"spot_brush_shelf_env", "lis_spot_block_floor_env", "lis_spot_block_drawer_env"
292308
}
293309

294310
@staticmethod
@@ -314,6 +330,8 @@ def get_nsrts(env_name: str, types: Dict[str, Type],
314330
"DropObjectInside": _drop_object_inside_sampler,
315331
"DropObjectInsideContainerOnTop": _drop_object_inside_sampler,
316332
"DragToUnblockObject": _drag_to_unblock_object_sampler,
333+
"DragToOpenObject": _drag_to_open_object_sampler,
334+
"DragToCloseObject": _drag_to_close_object_sampler,
317335
"DragToBlockObject": _drag_to_block_object_sampler,
318336
"SweepIntoContainer": _sweep_into_container_sampler,
319337
"SweepTwoObjectsIntoContainer": _sweep_into_container_sampler,

predicators/ground_truth_models/spot_env/options.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ def _grasp_policy(name: str,
333333
memory: Dict,
334334
objects: Sequence[Object],
335335
params: Array,
336-
do_dump: bool = False) -> Action:
336+
do_dump: bool = False,
337+
do_not_stow: bool = False) -> Action:
337338
del memory # not used
338339

339340
robot, _, _ = get_robot()
@@ -369,7 +370,8 @@ def _grasp_policy(name: str,
369370
state.get(target_obj, "width"))
370371

371372
do_stow = not do_dump and \
372-
target_obj_volume < CFG.spot_grasp_stow_volume_threshold
373+
target_obj_volume < CFG.spot_grasp_stow_volume_threshold and \
374+
not do_not_stow
373375
fn = _grasp_at_pixel_and_maybe_stow_or_dump
374376
sim_fn = None # NOTE: cannot simulate using this option, so this
375377
# shouldn't be called anyways...
@@ -593,6 +595,8 @@ def _pick_object_to_drag_policy(state: State, memory: Dict,
593595
params: Array) -> Action:
594596
name = "PickObjectToDrag"
595597
target_obj_idx = 1
598+
if objects[target_obj_idx ].name == 'green_handle':
599+
return _grasp_policy(name, target_obj_idx, state, memory, objects, params, do_not_stow=True)
596600
return _grasp_policy(name, target_obj_idx, state, memory, objects, params)
597601

598602

@@ -791,6 +795,35 @@ def _drag_to_unblock_object_policy(state: State, memory: Dict,
791795
tuple())
792796
return utils.create_spot_env_action(action_extra_info)
793797

798+
def _drag_to_open_object_policy(state: State, memory: Dict,
799+
objects: Sequence[Object],
800+
params: Array) -> Action:
801+
del state, memory # not used
802+
803+
name = "DragToOpenObject"
804+
robot, _, _ = get_robot()
805+
dx, dy, dyaw = params
806+
move_rel_pos = math_helpers.SE2Pose(dx, dy, angle=dyaw)
807+
# Note that simulation fn and args not yet implemented.
808+
action_extra_info = SpotActionExtraInfo(name, objects, _drag_and_release,
809+
(robot, move_rel_pos), None,
810+
tuple())
811+
return utils.create_spot_env_action(action_extra_info)
812+
813+
def _drag_to_close_object_policy(state: State, memory: Dict,
814+
objects: Sequence[Object],
815+
params: Array) -> Action:
816+
del state, memory # not used
817+
818+
name = "DragToCloseObject"
819+
robot, _, _ = get_robot()
820+
dx, dy, dyaw = params
821+
move_rel_pos = math_helpers.SE2Pose(dx, dy, angle=dyaw)
822+
# Note that simulation fn and args not yet implemented.
823+
action_extra_info = SpotActionExtraInfo(name, objects, _drag_and_release,
824+
(robot, move_rel_pos), None,
825+
tuple())
826+
return utils.create_spot_env_action(action_extra_info)
794827

795828
def _drag_to_block_object_policy(state: State, memory: Dict,
796829
objects: Sequence[Object],
@@ -922,6 +955,8 @@ def _move_to_ready_sweep_policy(state: State, memory: Dict,
922955
"DropObjectInsideContainerOnTop": Box(-np.inf, np.inf,
923956
(3, )), # rel dx, dy, dz
924957
"DragToUnblockObject": Box(-np.inf, np.inf, (3, )), # rel dx, dy, dyaw
958+
"DragToOpenObject": Box(-np.inf, np.inf, (3, )), # rel dx, dy, dyaw
959+
"DragToCloseObject": Box(-np.inf, np.inf, (3, )), # rel dx, dy, dyaw
925960
"DragToBlockObject": Box(-np.inf, np.inf, (3, )), # rel dx, dy, dyaw
926961
"SweepIntoContainer": Box(-np.inf, np.inf, (1, )), # velocity
927962
"SweepTwoObjectsIntoContainer": Box(-np.inf, np.inf, (1, )), # same
@@ -945,6 +980,8 @@ def _move_to_ready_sweep_policy(state: State, memory: Dict,
945980
"DropObjectInside": _drop_object_inside_policy,
946981
"DropObjectInsideContainerOnTop": _move_and_drop_object_inside_policy,
947982
"DragToUnblockObject": _drag_to_unblock_object_policy,
983+
"DragToOpenObject": _drag_to_open_object_policy,
984+
"DragToCloseObject": _drag_to_close_object_policy,
948985
"DragToBlockObject": _drag_to_block_object_policy,
949986
"SweepIntoContainer": _sweep_into_container_policy,
950987
"SweepTwoObjectsIntoContainer": _sweep_two_objects_into_container_policy,
@@ -996,6 +1033,7 @@ def get_env_names(cls) -> Set[str]:
9961033
"spot_ball_and_cup_sticky_table_env",
9971034
"spot_brush_shelf_env",
9981035
"lis_spot_block_floor_env",
1036+
"lis_spot_block_drawer_env",
9991037
}
10001038

10011039
@classmethod

predicators/perception/spot_perceiver.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,21 @@ def _create_goal(self, state: State,
464464
block = Object("red_block", _movable_object_type)
465465
Holding = pred_name_to_pred["Holding"]
466466
return {GroundAtom(Holding, [robot, block])}
467+
if goal_description == "pick up the blue block":
468+
robot = Object("robot", _robot_type)
469+
block = Object("blue_block", _movable_object_type)
470+
Holding = pred_name_to_pred["Holding"]
471+
return {GroundAtom(Holding, [robot, block])}
472+
if goal_description == "open the drawer":
473+
robot = Object("robot", _robot_type)
474+
handle = Object("green_handle", _movable_object_type)
475+
Open = pred_name_to_pred["Open"]
476+
return {GroundAtom(Open, [handle])}
477+
if goal_description == "close the drawer":
478+
robot = Object("robot", _robot_type)
479+
handle = Object("green_handle", _movable_object_type)
480+
NotOpen = pred_name_to_pred["NotOpen"]
481+
return {GroundAtom(NotOpen, [handle])}
467482
if goal_description == "setup sweeping":
468483
robot = Object("robot", _robot_type)
469484
brush = Object("brush", _movable_object_type)

predicators/spot_utils/graph_nav_maps/b45-621/metadata.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,18 @@ static-object-features:
4646
length: 0.1
4747
width: 0.1
4848
placeable: 1
49+
is_sweeper: 0
50+
blue_block:
51+
shape: 2
52+
height: 0.1
53+
length: 0.1
54+
width: 0.1
55+
placeable: 1
56+
is_sweeper: 0
57+
green_handle:
58+
shape: 2
59+
height: 0.1
60+
length: 0.1
61+
width: 0.1
62+
placeable: 0
4963
is_sweeper: 0

0 commit comments

Comments
 (0)