update
This commit is contained in:
parent
b25a1153e6
commit
4b9be845fe
|
@ -1,8 +1,9 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import omnigibson as og
|
import omnigibson as og
|
||||||
from utils.env_utils import *
|
from utils.env_utils import *
|
||||||
|
delta=1.2
|
||||||
|
|
||||||
def grasp(robot, grasped_obj, obj, all_objs, delta=2.7):
|
def grasp(robot, grasped_obj, obj, all_objs):
|
||||||
|
|
||||||
if len(grasped_obj):
|
if len(grasped_obj):
|
||||||
return False, f"Cannot grasp! Robot already holds something!"
|
return False, f"Cannot grasp! Robot already holds something!"
|
||||||
|
@ -15,7 +16,7 @@ def grasp(robot, grasped_obj, obj, all_objs, delta=2.7):
|
||||||
dis = distance_to_cuboid(robot_pos[:2], (obj.aabb[0][:2], obj.aabb[1][:2]))
|
dis = distance_to_cuboid(robot_pos[:2], (obj.aabb[0][:2], obj.aabb[1][:2]))
|
||||||
|
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot grasp! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot grasp! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
robot_pos[2] += robot.aabb_center[2] - 0.2
|
robot_pos[2] += robot.aabb_center[2] - 0.2
|
||||||
|
@ -66,7 +67,7 @@ def move(robot, obj, pos, grasped_obj, all_objs):
|
||||||
return True, "Moved successfully!"
|
return True, "Moved successfully!"
|
||||||
|
|
||||||
|
|
||||||
def put_inside(robot, obj, grasped_obj, container, all_objs, delta=2.7):
|
def put_inside(robot, obj, grasped_obj, container, all_objs):
|
||||||
|
|
||||||
if len(grasped_obj) == 0 or grasped_obj[0] != obj:
|
if len(grasped_obj) == 0 or grasped_obj[0] != obj:
|
||||||
return False, "Cannot put inside! Robot does not hold the object!"
|
return False, "Cannot put inside! Robot does not hold the object!"
|
||||||
|
@ -95,7 +96,7 @@ def put_inside(robot, obj, grasped_obj, container, all_objs, delta=2.7):
|
||||||
dis = distance_to_cuboid(robot_pos, container.aabb)
|
dis = distance_to_cuboid(robot_pos, container.aabb)
|
||||||
|
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot put inside! Robot is not within {delta} meters of the container!"
|
return False, f"Cannot put inside! The container is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
@ -140,7 +141,7 @@ def put_inside(robot, obj, grasped_obj, container, all_objs, delta=2.7):
|
||||||
return True, "Put inside successfully!"
|
return True, "Put inside successfully!"
|
||||||
|
|
||||||
|
|
||||||
def put_on_top(robot, obj, grasped_obj, surface, all_objs, delta=2.7):
|
def put_on_top(robot, obj, grasped_obj, surface, all_objs):
|
||||||
|
|
||||||
if len(grasped_obj) == 0 or grasped_obj[0] != obj:
|
if len(grasped_obj) == 0 or grasped_obj[0] != obj:
|
||||||
return False, "Cannot put on top! Robot does not hold the object!"
|
return False, "Cannot put on top! Robot does not hold the object!"
|
||||||
|
@ -163,7 +164,7 @@ def put_on_top(robot, obj, grasped_obj, surface, all_objs, delta=2.7):
|
||||||
dis = distance_to_cuboid(robot_pos, surface.aabb)
|
dis = distance_to_cuboid(robot_pos, surface.aabb)
|
||||||
|
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot put on top! Robot is not within {delta} meters of the surface!"
|
return False, f"Cannot put on top! The surface is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
@ -208,7 +209,7 @@ def put_on_top(robot, obj, grasped_obj, surface, all_objs, delta=2.7):
|
||||||
return True, "Put on top successfully!"
|
return True, "Put on top successfully!"
|
||||||
|
|
||||||
|
|
||||||
def put_under(robot, obj, grasped_obj, surface, all_objs, delta=2.7):
|
def put_under(robot, obj, grasped_obj, surface, all_objs):
|
||||||
|
|
||||||
if len(grasped_obj) == 0 or grasped_obj[0] != obj:
|
if len(grasped_obj) == 0 or grasped_obj[0] != obj:
|
||||||
return False, "Cannot put under! Robot does not hold the object!"
|
return False, "Cannot put under! Robot does not hold the object!"
|
||||||
|
@ -231,7 +232,7 @@ def put_under(robot, obj, grasped_obj, surface, all_objs, delta=2.7):
|
||||||
dis = distance_to_cuboid(robot_pos, surface.aabb)
|
dis = distance_to_cuboid(robot_pos, surface.aabb)
|
||||||
|
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot put under! Robot is not within {delta} meters of the surface!"
|
return False, f"Cannot put under! The surface is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
@ -276,7 +277,7 @@ def put_under(robot, obj, grasped_obj, surface, all_objs, delta=2.7):
|
||||||
return True, "Put under successfully!"
|
return True, "Put under successfully!"
|
||||||
|
|
||||||
|
|
||||||
def put_next_to(robot, obj, grasped_obj, surface, all_objs, delta=2.7):
|
def put_next_to(robot, obj, grasped_obj, surface, all_objs):
|
||||||
|
|
||||||
if len(grasped_obj) == 0 or grasped_obj[0] != obj:
|
if len(grasped_obj) == 0 or grasped_obj[0] != obj:
|
||||||
return False, "Cannot put next to! Robot doesn't hold the object!"
|
return False, "Cannot put next to! Robot doesn't hold the object!"
|
||||||
|
@ -294,7 +295,7 @@ def put_next_to(robot, obj, grasped_obj, surface, all_objs, delta=2.7):
|
||||||
dis = distance_to_cuboid(robot_pos, surface.aabb)
|
dis = distance_to_cuboid(robot_pos, surface.aabb)
|
||||||
|
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot put next to! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot put next to! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
@ -336,7 +337,7 @@ def put_next_to(robot, obj, grasped_obj, surface, all_objs, delta=2.7):
|
||||||
return True, "Put next to successfully!"
|
return True, "Put next to successfully!"
|
||||||
|
|
||||||
|
|
||||||
def cook(robot, obj, delta=2.7):
|
def cook(robot, obj):
|
||||||
|
|
||||||
if og.object_states.Cooked not in obj.states:
|
if og.object_states.Cooked not in obj.states:
|
||||||
return False, "Cannot cook! Object is not cookable!"
|
return False, "Cannot cook! Object is not cookable!"
|
||||||
|
@ -344,7 +345,7 @@ def cook(robot, obj, delta=2.7):
|
||||||
robot_pos = robot.get_position()
|
robot_pos = robot.get_position()
|
||||||
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot cook! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot cook! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
obj.states[og.object_states.Cooked].set_value(True)
|
obj.states[og.object_states.Cooked].set_value(True)
|
||||||
|
@ -353,7 +354,7 @@ def cook(robot, obj, delta=2.7):
|
||||||
return True, "Cooked successfully!"
|
return True, "Cooked successfully!"
|
||||||
|
|
||||||
|
|
||||||
def burn(robot, obj, delta=2.7):
|
def burn(robot, obj):
|
||||||
|
|
||||||
if og.object_states.Burnt not in obj.states:
|
if og.object_states.Burnt not in obj.states:
|
||||||
return False, "Cannot burn! Object is not burnable!"
|
return False, "Cannot burn! Object is not burnable!"
|
||||||
|
@ -361,7 +362,7 @@ def burn(robot, obj, delta=2.7):
|
||||||
robot_pos = robot.get_position()
|
robot_pos = robot.get_position()
|
||||||
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot burn! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot burn! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
obj.states[og.object_states.Burnt].set_value(True)
|
obj.states[og.object_states.Burnt].set_value(True)
|
||||||
|
@ -370,7 +371,7 @@ def burn(robot, obj, delta=2.7):
|
||||||
return True, "Burnt successfully!"
|
return True, "Burnt successfully!"
|
||||||
|
|
||||||
|
|
||||||
def freeze(robot, obj, delta=2.7):
|
def freeze(robot, obj):
|
||||||
|
|
||||||
if og.object_states.Frozen not in obj.states:
|
if og.object_states.Frozen not in obj.states:
|
||||||
return False, "Cannot freeze! Object is not freezable!"
|
return False, "Cannot freeze! Object is not freezable!"
|
||||||
|
@ -378,7 +379,7 @@ def freeze(robot, obj, delta=2.7):
|
||||||
robot_pos = robot.get_position()
|
robot_pos = robot.get_position()
|
||||||
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot freeze! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot freeze! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
obj.states[og.object_states.Frozen].set_value(True)
|
obj.states[og.object_states.Frozen].set_value(True)
|
||||||
|
@ -387,7 +388,7 @@ def freeze(robot, obj, delta=2.7):
|
||||||
return True, "Frozen successfully!"
|
return True, "Frozen successfully!"
|
||||||
|
|
||||||
|
|
||||||
def heat(robot, obj, delta=2.7):
|
def heat(robot, obj):
|
||||||
|
|
||||||
if og.object_states.Heated not in obj.states:
|
if og.object_states.Heated not in obj.states:
|
||||||
return False, "Cannot heat! Object is not heatable!"
|
return False, "Cannot heat! Object is not heatable!"
|
||||||
|
@ -395,7 +396,7 @@ def heat(robot, obj, delta=2.7):
|
||||||
robot_pos = robot.get_position()
|
robot_pos = robot.get_position()
|
||||||
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot heat! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot heat! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
obj.states[og.object_states.Heated].set_value(True)
|
obj.states[og.object_states.Heated].set_value(True)
|
||||||
|
@ -404,7 +405,7 @@ def heat(robot, obj, delta=2.7):
|
||||||
return True, "Heated successfully!"
|
return True, "Heated successfully!"
|
||||||
|
|
||||||
|
|
||||||
def open(robot, obj, delta=2.7):
|
def open(robot, obj):
|
||||||
|
|
||||||
if og.object_states.Open not in obj.states:
|
if og.object_states.Open not in obj.states:
|
||||||
return False, "Cannot open! Object is not openable!"
|
return False, "Cannot open! Object is not openable!"
|
||||||
|
@ -412,7 +413,7 @@ def open(robot, obj, delta=2.7):
|
||||||
robot_pos = robot.get_position()
|
robot_pos = robot.get_position()
|
||||||
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot open! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot open! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for _ in range(4):
|
for _ in range(4):
|
||||||
|
@ -422,7 +423,7 @@ def open(robot, obj, delta=2.7):
|
||||||
return True, "Opened successfully!"
|
return True, "Opened successfully!"
|
||||||
|
|
||||||
|
|
||||||
def close(robot, obj, delta=2.7):
|
def close(robot, obj):
|
||||||
|
|
||||||
if og.object_states.Open not in obj.states:
|
if og.object_states.Open not in obj.states:
|
||||||
return False, "Cannot close! Object is not openable!"
|
return False, "Cannot close! Object is not openable!"
|
||||||
|
@ -430,7 +431,7 @@ def close(robot, obj, delta=2.7):
|
||||||
robot_pos = robot.get_position()
|
robot_pos = robot.get_position()
|
||||||
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot close! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot close! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
obj.states[og.object_states.Open].set_value(False)
|
obj.states[og.object_states.Open].set_value(False)
|
||||||
|
@ -439,7 +440,7 @@ def close(robot, obj, delta=2.7):
|
||||||
return True, "Closed successfully!"
|
return True, "Closed successfully!"
|
||||||
|
|
||||||
|
|
||||||
def toggle_on(robot, obj, delta=2.7):
|
def toggle_on(robot, obj):
|
||||||
|
|
||||||
if og.object_states.ToggledOn not in obj.states:
|
if og.object_states.ToggledOn not in obj.states:
|
||||||
return False, "Cannot toggle on! Object is not toggleable!"
|
return False, "Cannot toggle on! Object is not toggleable!"
|
||||||
|
@ -448,7 +449,7 @@ def toggle_on(robot, obj, delta=2.7):
|
||||||
obj_pos = obj.get_position()
|
obj_pos = obj.get_position()
|
||||||
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot toggle on! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot toggle on! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
obj.states[og.object_states.ToggledOn].set_value(True)
|
obj.states[og.object_states.ToggledOn].set_value(True)
|
||||||
|
@ -457,7 +458,7 @@ def toggle_on(robot, obj, delta=2.7):
|
||||||
return True, "Toggled on successfully!"
|
return True, "Toggled on successfully!"
|
||||||
|
|
||||||
|
|
||||||
def toggle_off(robot, obj, delta=2.7):
|
def toggle_off(robot, obj):
|
||||||
|
|
||||||
if og.object_states.ToggledOn not in obj.states:
|
if og.object_states.ToggledOn not in obj.states:
|
||||||
return False, "Cannot toggle off! Object is not toggleable!"
|
return False, "Cannot toggle off! Object is not toggleable!"
|
||||||
|
@ -466,7 +467,7 @@ def toggle_off(robot, obj, delta=2.7):
|
||||||
obj_pos = obj.get_position()
|
obj_pos = obj.get_position()
|
||||||
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
dis = distance_to_cuboid(robot_pos, obj.aabb)
|
||||||
if dis > delta:
|
if dis > delta:
|
||||||
return False, f"Cannot toggle off! Robot is not within {delta} meters of the object!"
|
return False, f"Cannot toggle off! The object is not within reach of the robot!"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
obj.states[og.object_states.ToggledOn].set_value(False)
|
obj.states[og.object_states.ToggledOn].set_value(False)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user