embodied intelligence1

from ai2thor.controller import Controller
import os
import cv2
import matplotlib
import matplotlib.pyplot as plt
from PIL import Image
import json

sav_path = './tmp_data/'
if not os.path.exists(sav_path):
    os.makedirs(sav_path, exist_ok = True)

# controller = Controller(
#     agentMode="default",
#     visibilityDistance=1.5,
#     scene="FloorPlan1",
#
#     # step sizes
#     gridSize=0.25,
#     snapToGrid=True,
#     rotateStepDegrees=90,
#
#     # image modalities
#     renderDepthImage=False,
#     renderInstanceSegmentation=False,
#
#     # camera properties
#     width=2000,
#     height=1000,
#     fieldOfView=100
# )
# controller.step("PausePhysicsAutoSim")
# controller.step(
#     action="AdvancePhysicsStep",
#     timeStep=0.02
# )
# controller.step(
#     action="PickupObject",
#     objectId="Apple|1|1|1",
#     forceAction=False,
#     manualInteract=False
# )
# controller.step(
#     action="MoveAhead",
#     moveMagnitude=5
# )
#
# controller.step(
#     action="MoveAhead",
#     moveMagnitude=5
# )
# controller.step(
#     action="MoveAhead",
#     moveMagnitude=5
# )
# controller.step(
#     action="RotateRight",
#     degrees=30
# )
# controller.step(
#     action="LookUp",
#     degrees=30
# )
# controller.step("UnpausePhysicsAutoSim")
# Other supported directions
# controller.step("MoveBack")
# controller.step("MoveLeft")
# controller.step("MoveRight")


# print(event.third_party_camera_frames)

controller = Controller(
        scene = "FloorPlan1",
        gridSize = 0.5,
        rotateStepDegrees = 90,
        renderDepthImage = True,
        renderInstanceSegmentation = True,
        width=300,
        height=300,
        fieldOfView = 90
    )
print("Start the controller.")

num_step = 0
event = controller.step(action = "GetReachablePositions")
reachable_positions = event.metadata["actionReturn"]
print(f"Reachable Points: {reachable_positions}")
for i in event.metadata["objects"]:
    # if i["pickupable"]==True:
    #     print(i['objectId'])
    # if i['objectId']=='Shelf|+01.75|+00.55|-02.56':
    #     print(i)
    print(i['objectId'])
# print(event.metadata["objects"])
plt.imsave(os.path.join(sav_path, f'frame_{num_step}.png'), event.frame)
num_step += 1

event = controller.step(
    action = "Teleport",
    position = dict(x = -1.0, y = 0.900999128818512, z = 1.0),
    rotation = dict(x = 0, y = 0, z = 0),
    horizon = 0,
    standing = True
)
print("Teleport {}".format(event.metadata["lastActionSuccess"]))
plt.imsave(os.path.join(sav_path, f'frame_{num_step}.png'), event.frame)
num_step += 1



nav_actions = ['MoveAhead', 'RotateRight']

for act in nav_actions:
    event = controller.step(action = act)
    print("action:{} {}".format(act, event.metadata["lastActionSuccess"]))
    plt.imsave(os.path.join(sav_path, f'frame_{num_step}.png'), event.frame)
    num_step += 1

event = controller.step(
    action="PickupObject",
    objectId="Book|+00.15|+01.10|+00.62"
)
print("PickUp {}".format(event.metadata["lastActionSuccess"]))
plt.imsave(os.path.join(sav_path, f'frame_{num_step}.png'), event.frame)
num_step += 1

nav_actions2 = ['MoveAhead', 'MoveAhead', 'MoveAhead', 'MoveAhead', 'MoveAhead']
for act in nav_actions2:
    event = controller.step(action = act)
    print("action:{} {}".format(act, event.metadata["lastActionSuccess"]))
    plt.imsave(os.path.join(sav_path, f'frame_{num_step}.png'), event.frame)
    num_step += 1

event = controller.step(
    action = "PutObject",
    objectId = "Floor|+00.00|+00.00|+00.00",
    forceAction = True
)
print("Put Book {}".format(event.metadata["lastActionSuccess"]))
plt.imsave(os.path.join(sav_path, f'frame_{num_step}.png'), event.frame)
num_step += 1

event = controller.step(action = "GetMapViewCameraProperties", raise_for_failure = True)
event = controller.step(
    action = "AddThirdPartyCamera",
    **event.metadata["actionReturn"]
)
top_down_frame = event.third_party_camera_frames[-1]
print("Draw Top-Down View")
plt.imsave(os.path.join(sav_path, f'top_down.png'), top_down_frame)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值