Skip to content

Commit 8d674b5

Browse files
committed
started env
1 parent 89b02c3 commit 8d674b5

6 files changed

Lines changed: 195 additions & 2 deletions

File tree

predicators/envs/spot_env.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,6 +3180,76 @@ def _detection_id_to_obj(self) -> Dict[ObjectDetectionID, Object]:
31803180
def _generate_goal_description(self) -> GoalDescription:
31813181
return "open the drawer"
31823182

3183+
def _get_dry_task(self, train_or_test: str,
3184+
task_idx: int) -> EnvironmentTask:
3185+
raise NotImplementedError("Dry task generation not implemented.")
3186+
3187+
class LISSpotCollectEnv(SpotRearrangementEnv):
3188+
"""An extremely basic environment where a block needs to be picked up and
3189+
is specifically used for testing in the LIS Spot room.
3190+
3191+
Very simple and mostly just for testing.
3192+
"""
3193+
3194+
def __init__(self, use_gui: bool = True) -> None:
3195+
super().__init__(use_gui)
3196+
3197+
op_to_name = {o.name: o for o in _create_operators()}
3198+
op_names_to_keep = {
3199+
"MoveToReachObject",
3200+
"MoveToHandViewObject",
3201+
"PickObjectToDrag",
3202+
"DragToOpenObject",
3203+
"DragToCloseObject",
3204+
"PickObjectFromTop",
3205+
"PlaceObjectOnTop",
3206+
"DropObjectInside"
3207+
}
3208+
self._strips_operators = {op_to_name[o] for o in op_names_to_keep}
3209+
3210+
@classmethod
3211+
def get_name(cls) -> str:
3212+
return "lis_spot_collect_misplaced_items_env"
3213+
3214+
@property
3215+
def _detection_id_to_obj(self) -> Dict[ObjectDetectionID, Object]:
3216+
3217+
detection_id_to_obj: Dict[ObjectDetectionID, Object] = {}
3218+
3219+
blue_block = Object("blue_block", _movable_object_type)
3220+
blue_block_detection = LanguageObjectDetectionID(
3221+
"blue block/blue-ish block/blue-green block")
3222+
detection_id_to_obj[blue_block_detection] = blue_block
3223+
3224+
green_cup = Object("yellow_cup", _movable_object_type)
3225+
green_cup_detection = LanguageObjectDetectionID(
3226+
"yellow cup/yellow cylinder")
3227+
detection_id_to_obj[green_cup_detection] = green_cup
3228+
3229+
toy_plane = Object("toy_plane", _movable_object_type)
3230+
toy_plane_detection = LanguageObjectDetectionID(
3231+
"toy plane")
3232+
detection_id_to_obj[toy_plane_detection] = toy_plane
3233+
3234+
cardboard_box = Object("cardboard_box", _container_type)
3235+
cardboard_box_detection = LanguageObjectDetectionID(
3236+
"cardboard box/brown box")
3237+
detection_id_to_obj[cardboard_box_detection] = cardboard_box
3238+
3239+
green_handle = Object("green_handle", _movable_object_type)
3240+
green_handle_detection = LanguageObjectDetectionID(
3241+
"green duct tape/green handle/green object")
3242+
detection_id_to_obj[green_handle_detection] = green_handle
3243+
3244+
for obj, pose in get_known_immovable_objects().items():
3245+
detection_id = KnownStaticObjectDetectionID(obj.name, pose)
3246+
detection_id_to_obj[detection_id] = obj
3247+
3248+
return detection_id_to_obj
3249+
3250+
def _generate_goal_description(self) -> GoalDescription:
3251+
return "collect misplaced items"
3252+
31833253
def _get_dry_task(self, train_or_test: str,
31843254
task_idx: int) -> EnvironmentTask:
31853255
raise NotImplementedError("Dry task generation not implemented.")

predicators/ground_truth_models/spot_env/nsrts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ def get_env_names(cls) -> Set[str]:
304304
"spot_cube_env", "spot_soda_floor_env", "spot_soda_table_env",
305305
"spot_soda_bucket_env", "spot_soda_chair_env",
306306
"spot_main_sweep_env", "spot_ball_and_cup_sticky_table_env",
307-
"spot_brush_shelf_env", "lis_spot_block_floor_env", "lis_spot_block_drawer_env"
307+
"spot_brush_shelf_env", "lis_spot_block_floor_env", "lis_spot_block_drawer_env",
308+
"lis_spot_collect_misplaced_items_env"
308309
}
309310

310311
@staticmethod

predicators/ground_truth_models/spot_env/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ def get_env_names(cls) -> Set[str]:
10341034
"spot_brush_shelf_env",
10351035
"lis_spot_block_floor_env",
10361036
"lis_spot_block_drawer_env",
1037+
"lis_spot_collect_misplaced_items_env"
10371038
}
10381039

10391040
@classmethod

predicators/perception/spot_perceiver.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,19 @@ def _create_goal(self, state: State,
479479
handle = Object("green_handle", _movable_object_type)
480480
NotOpen = pred_name_to_pred["NotOpen"]
481481
return {GroundAtom(NotOpen, [handle])}
482+
if goal_description == "collect misplaced items":
483+
robot = Object("robot", _robot_type)
484+
handle = Object("green_handle", _movable_object_type)
485+
blue_block = Object("blue_block", _movable_object_type)
486+
yellow_cup = Object("yellow_cup", _movable_object_type)
487+
toy_plane = Object("toy_plane", _movable_object_type)
488+
cardboard_box = Object("cardboard_box", _container_type)
489+
Inside = pred_name_to_pred["Inside"]
490+
return {
491+
GroundAtom(Inside, [blue_block, cardboard_box]),
492+
GroundAtom(Inside, [yellow_cup, cardboard_box]),
493+
GroundAtom(Inside, [toy_plane, cardboard_box]),
494+
}
482495
if goal_description == "setup sweeping":
483496
robot = Object("robot", _robot_type)
484497
brush = Object("brush", _movable_object_type)

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,38 @@ static-object-features:
6060
length: 0.1
6161
width: 0.1
6262
placeable: 0
63-
is_sweeper: 0
63+
is_sweeper: 0
64+
yellow_cup:
65+
shape: 2
66+
height: 0.1
67+
length: 0.1
68+
width: 0.1
69+
placeable: 1
70+
is_sweeper: 0
71+
toy_plane:
72+
shape: 2
73+
height: 0.1
74+
length: 0.1
75+
width: 0.1
76+
placeable: 1
77+
is_sweeper: 0
78+
cardboard_box:
79+
shape: 1
80+
height: 0.05
81+
width: 0.3
82+
length: 0.4
83+
placeable: 1
84+
is_sweeper: 0
85+
# Important for TopAbove that the bucket appears to always be on the ground
86+
z: -0.15
87+
# Rotation can't be detected.
88+
qw: 1
89+
qx: 0
90+
qy: 0
91+
qz: 0
92+
# This should be calculable, but I'm lazy. These values represent the SE2 pose
93+
# (in the table frame) for the robot before placing the container.
94+
prepare_container_relative_xy:
95+
dx: -0.8
96+
dy: -0.6
97+
angle: 0.0

run_predicates.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import numpy as np
2+
import json
3+
from predicators.envs.spot_env import LISSpotCollectEnv
4+
from predicators.perception.spot_perceiver import SpotPerceiver
5+
from predicators.ground_truth_models import get_gt_nsrts, get_gt_options
6+
from predicators.structs import Object, State, GroundAtom
7+
from predicators.spot_utils.utils import _container_type, _movable_object_type, _robot_type
8+
from predicators import utils
9+
10+
utils.reset_config({
11+
"env":
12+
"lis_spot_collect_misplaced_items_env",
13+
"approach":
14+
"spot_wrapper[oracle]",
15+
"num_train_tasks":
16+
0,
17+
"num_test_tasks":
18+
1,
19+
"seed":
20+
0,
21+
"spot_run_dry":
22+
True,
23+
"spot_robot_ip":
24+
None,
25+
"spot_graph_nav_map":
26+
"b45-621",
27+
"bilevel_plan_without_sim":
28+
True,
29+
"perceiver":
30+
"spot_perceiver",
31+
"spot_use_perfect_samplers":
32+
True,
33+
})
34+
35+
rng = np.random.default_rng(123)
36+
env = LISSpotCollectEnv()
37+
perceiver = SpotPerceiver()
38+
nsrts = get_gt_nsrts(env.get_name(), env.predicates,
39+
get_gt_options(env.get_name()))
40+
41+
pred_name_to_pred = {p.name: p for p in env.predicates}
42+
43+
robot = Object("robot", _robot_type)
44+
handle = Object("green_handle", _movable_object_type)
45+
blue_block = Object("blue_block", _movable_object_type)
46+
yellow_cup = Object("yellow_cup", _movable_object_type)
47+
toy_plane = Object("toy_plane", _movable_object_type)
48+
cardboard_box = Object("cardboard_box", _container_type)
49+
Inside = pred_name_to_pred["Inside"]
50+
51+
# state from json
52+
state = State({}, simulator_state=None)
53+
54+
# get all grounded atoms
55+
all_grounded_atoms = None
56+
57+
json_file = "/Users/shashlik/Desktop/last.json"
58+
with open(json_file, "r", encoding="utf-8") as f:
59+
json_dict = json.load(f)
60+
object_name_to_object = env._parse_object_name_to_object_from_json(
61+
json_dict)
62+
init_dict = env._parse_init_state_dict_from_json(
63+
json_dict, object_name_to_object)
64+
for i, (obj, init_val) in enumerate(sorted(init_dict.items())):
65+
init_val["object_id"] = i
66+
state = utils.create_state_from_dict(init_dict)
67+
68+
a = GroundAtom(Inside, [blue_block, cardboard_box])
69+
print(a, a.holds(state))
70+
71+
import ipdb; ipdb.set_trace()
72+
73+
for a in all_grounded_atoms:
74+
a.holds(state)

0 commit comments

Comments
 (0)