Skip to content

Commit

Permalink
Merge pull request #769 from allenai/directionalPush
Browse files Browse the repository at this point in the history
minimal directionalPush bug fix
  • Loading branch information
mattdeitke authored Jun 1, 2021
2 parents d2d8877 + 1559a5f commit 8a855f8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
37 changes: 37 additions & 0 deletions ai2thor/tests/test_unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,43 @@ def test_randomize_materials_clearOnReset(controller):
).sum() / 300 / 300 < 0.01, "Materials should look the same"


@pytest.mark.parametrize("controller", fifo_wsgi)
def test_directionalPush(controller):
positions = []
for angle in [0, 90, 180, 270, -1, -90]:
controller.reset(scene="FloorPlan28")
start = controller.step(
action="TeleportFull",
position=dict(x=-3.25, y=0.9, z=-1.25),
rotation=dict(x=0, y=0, z=0),
horizon=30,
standing=True,
)
# z increases
end = controller.step(
action="DirectionalPush",
pushAngle=angle,
objectId="Tomato|-03.13|+00.92|-00.39",
moveMagnitude=25,
)
start_obj = next(
obj for obj in start.metadata["objects"] if obj["objectType"] == "Tomato"
)
end_obj = next(
obj for obj in end.metadata["objects"] if obj["objectType"] == "Tomato"
)
positions.append((start_obj["position"], end_obj["position"]))

assert positions[0][1]["z"] - positions[0][0]["z"] > 0.2
assert positions[4][1]["z"] - positions[4][0]["z"] > 0.2

assert positions[1][1]["x"] - positions[1][0]["x"] > 0.2
assert positions[2][1]["z"] - positions[2][0]["z"] < -0.2

assert positions[3][1]["x"] - positions[3][0]["x"] < -0.2
assert positions[5][1]["x"] - positions[5][0]["x"] < -0.2


@pytest.mark.parametrize("controller", fifo_wsgi)
def test_randomize_materials_params(controller):
controller.reset(scene="FloorPlan15")
Expand Down
14 changes: 7 additions & 7 deletions unity/Assets/Scripts/PhysicsRemoteFPSAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1896,13 +1896,13 @@ public void DirectionalPush(ServerAction action) {
return;
}

// the direction vecctor to push the target object defined by action.PushAngle
// degrees clockwise from the agent's forward, the PushAngle must be less than 360
if (action.pushAngle <= 0 || action.pushAngle >= 360) {
errorMessage = "please give a PushAngle between 0 and 360.";
Debug.Log(errorMessage);
actionFinished(false);
return;
// The direction vector to push the target object defined by action.pushAngle
// degrees clockwise from the agent's forward.
action.pushAngle %= 360;

// converts negative rotations to be positive
if (action.pushAngle < 360) {
action.pushAngle += 360;
}

SimObjPhysics target = null;
Expand Down

0 comments on commit 8a855f8

Please sign in to comment.