allenai / ai2thor

An open-source platform for Visual AI.
http://ai2thor.allenai.org
Apache License 2.0
1.09k stars 210 forks source link

snapToGrid affects GetReachablePositions #1208

Open garfieldnate opened 2 months ago

garfieldnate commented 2 months ago

If you set snapToGrid to False, GetReachablePositions may or may not return positions that are directly on the grid points. Here's an example:

from ai2thor.controller import Controller

# Spawn in FloorPlan1 with snapToGrid disabled
controller = Controller(snapToGrid=False)

# reachable floor XZ coordinates are multiples of .25, the default gridSize parameter
event = controller.step("GetReachablePositions")
print(event.metadata["actionReturn"])

# Walk to the left and around the kitchen island
controller.step("RotateLeft")
for i in range(12):
    controller.step("MoveAhead")
controller.step("RotateLeft")
for i in range(11):
    controller.step("MoveAhead")

# reachable floor XZ coordinates are no longer multiples of .25!
event = controller.step("GetReachablePositions")
print(event.metadata["actionReturn"])

The output will look like this:

[{'x': 0.0, 'y': 0.9009992480278015, 'z': -1.25}, {'x': 0.25, 'y': 0.9009992480278015, 'z': -1.25},...
[{'x': -2.750000238418579, 'y': 0.9009992480278015, 'z': 1.75}, {'x': -2.500000238418579, 'y': 0.9009992480278015, 'z': 1.75},...

Notice that the first reachable positions printed have the XZ coordinates rounded to .25 (the gridSize), and the second ones do not. The extra digits always seem to occur at the 7th decimal point, which is around where 32-bit precision lies, so it makes me wonder a 32-bit float is being used where a 64-bit one should be on the unity side somewhere.

This was an issue for us because we were doing exact matching over the coordinate values while looking for a path through the scene. There's a method in Controller.py called key_for_point (also used for path finding of some sort), and it seems to account for this discrepancy by always rounding to 3 decimal places (although, of course, if gridSize is very small this will not work). For now I'm using the same workaround.