allenai / procthor

🏘️ Scaling Embodied AI by Procedurally Generating Interactive 3D Houses
https://procthor.allenai.org/
Apache License 2.0
293 stars 25 forks source link

How to get a shortest path to an object? #23

Open whcpumpkin opened 1 year ago

whcpumpkin commented 1 year ago

Hi, I would like to ask how to get a shortest path to the object. I use the code from https://ai2thor.allenai.org/robothor/documentation/#navigation :

from ai2thor.util.metrics import (
    get_shortest_path_to_object_type
)

path = get_shortest_path_to_object(
   controller=controller,
    object_type="Apple",
    initial_position=dict(
        x=0,
        y=0.9,
        z=0.25
    )
)

But the path point returned by this code is not on the grid point. Thanks!!!

ChongjianGE commented 1 year ago

hi @whcpumpkin did you solved the problems?

whcpumpkin commented 1 year ago

@ChongjianGE Hi, I use thortils to get the path (computed by A* algo). https://github.com/zkytony/thortils

ChongjianGE commented 1 year ago

@whcpumpkin Thanks for the quick reply. It's really helpful to me.

ChongjianGE commented 1 year ago

Hi @whcpumpkin Sorry for disturbing you again. I utilized the thortils to get the path with the following code

dataset = prior.load_dataset("procthor-10k")
data_collect_path = '/Users/rhettgee/Desktop/2-research-projects/mac_ai2thor/data'

data = dataset["train"][0]
controller = tt.launch_controller({"scene": data})

event = controller.step(action="GetReachablePositions")
positions = event.metadata["actionReturn"]
initial_position = random.choice(positions)
initial_rotation = event.metadata['agent']['rotation']

controller.step(
            action="Teleport",
            position=initial_position,
            rotation=initial_rotation,
            horizon=0)

path=tt.navigation.get_shortest_path_to_object_type(controller=controller, object_type='Apple', start_position=initial_position,start_rotation=initial_rotation)

However the program breaks down like

Traceback (most recent call last):
  File "/Users/rhettgee/Desktop/2-research-projects/mac_ai2thor/ai2thor/debug_tt.py", line 48, in <module>
    path=tt.navigation.get_shortest_path_to_object_type(controller=controller, object_type='Apple', start_position=initial_position,start_rotation=initial_rotation)
  File "/Users/rhettgee/Desktop/2-research-projects/mac_ai2thor/ai2thor/thortils/thortils/navigation.py", line 473, in get_shortest_path_to_object_type
    return get_shortest_path_to_object(controller, obj["objectId"], *args, **kwargs)
  File "/Users/rhettgee/Desktop/2-research-projects/mac_ai2thor/ai2thor/thortils/thortils/navigation.py", line 408, in get_shortest_path_to_object
    tentative_plan, expanded_poses = find_navigation_plan(start_pose,
  File "/Users/rhettgee/Desktop/2-research-projects/mac_ai2thor/ai2thor/thortils/thortils/navigation.py", line 287, in find_navigation_plan
    start_rotation = normalize_angles(start[1])
  File "/Users/rhettgee/Desktop/2-research-projects/mac_ai2thor/ai2thor/thortils/thortils/utils/math.py", line 25, in normalize_angles
    return type(angles)(map(lambda x: x % 360, angles))
  File "/Users/rhettgee/Desktop/2-research-projects/mac_ai2thor/ai2thor/thortils/thortils/utils/math.py", line 25, in <lambda>
    return type(angles)(map(lambda x: x % 360, angles))
TypeError: not all arguments converted during string formatting

Could you please tell me the detailed start_position, and start_rotation you passed into the tt.navigation.get_shortest_path_to_object_type function?

Thanks in advance.

whcpumpkin commented 1 year ago
 path, plan = get_shortest_path_to_object(controller=self.controller,
                                                      object_id=object["name"],
                                                      start_position=event.metadata["agent"]["position"],
                                                      start_rotation=event.metadata["agent"]["rotation"],
                                                      return_plan=True,
                                                      goal_distance=1.5,
                                                      h_angles=[0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330])

@ChongjianGE This is my code that use the get_shortest_path_to_object_type function. I'm not quite sure what your error is about, I haven't encountered this problem.

ChongjianGE commented 1 year ago

@whcpumpkin Thanks for the reply. There may be some bugs in my implementation. I'll try to fix them.