Skip to content

Commit

Permalink
Merge branch 'main' into toggleCameraMeshTracking
Browse files Browse the repository at this point in the history
  • Loading branch information
winthos committed Nov 6, 2024
2 parents 3f046e1 + 1a0a95c commit 2f3413b
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 145 deletions.
2 changes: 1 addition & 1 deletion ai2thor/tests/data/arm-metadata-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
"type": "number"
},
"isStanding": {
"type": "boolean"
"type": ["boolean", "null"]
},
"inHighFrictionArea": {
"type": "boolean"
Expand Down
7 changes: 4 additions & 3 deletions ai2thor/tests/test_unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,16 +1418,17 @@ def test_teleport_stretch(controller):
agent = "stretch"

event = controller.reset(agentMode=agent)
assert event.metadata["agent"]["isStanding"] is False, agent + " cannot stand!"
assert event.metadata["agent"]["isStanding"] is None, (
agent + " cannot stand so this should be None/null!"
)

# Only degrees of freedom on the locobot
for action in ["Teleport", "TeleportFull"]:
event = controller.step(
action=action,
position=dict(x=-1.5, y=0.9, z=-1.5),
rotation=dict(x=0, y=90, z=0),
horizon=30,
standing=True,
standing=None,
)

print(f"Error Message: {event.metadata['errorMessage']}")
Expand Down
19 changes: 12 additions & 7 deletions unity/Assets/Scripts/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void Initialize(ServerAction action) {
: action.dynamicServerAction.agentInitializationParams
);
Debug.Log(
$"Initialize of AgentController. lastActionSuccess: {primaryAgent.lastActionSuccess}, errorMessage: {primaryAgent.errorMessage}, actionReturn: {primaryAgent.actionReturn}, agentState: {primaryAgent.agentState}"
$"Initialize of AgentController.lastAction: {primaryAgent.lastAction} lastActionSuccess: {primaryAgent.lastActionSuccess}, errorMessage: {primaryAgent.errorMessage}, actionReturn: {primaryAgent.actionReturn}, agentState: {primaryAgent.agentState}"
);
Time.fixedDeltaTime = action.fixedDeltaTime.GetValueOrDefault(Time.fixedDeltaTime);
if (action.targetFrameRate > 0) {
Expand Down Expand Up @@ -1333,17 +1333,22 @@ bool shouldRenderImageSynthesis
if (camera.transform.parent != null) {
cMetadata.parentObjectName = camera.transform.parent.name;

cMetadata.parentRelativeThirdPartyCameraPosition =
camera.transform.localPosition;
cMetadata.parentRelativeThirdPartyCameraPosition = camera
.transform
.localPosition;

//get third party camera rotation as quaternion in parent space
cMetadata.parentRelativeThirdPartyCameraRotation =
camera.transform.localEulerAngles;
cMetadata.parentRelativeThirdPartyCameraRotation = camera
.transform
.localEulerAngles;
} else {
//if not parented, default position and rotation to world coordinate space
cMetadata.parentObjectName = "";
cMetadata.parentRelativeThirdPartyCameraPosition = camera.transform.position;
cMetadata.parentRelativeThirdPartyCameraRotation = camera.transform.rotation.eulerAngles;
cMetadata.parentRelativeThirdPartyCameraRotation = camera
.transform
.rotation
.eulerAngles;
}

//if this camera is part of the agent's hierarchy at all, get agent relative info
Expand All @@ -1360,7 +1365,7 @@ bool shouldRenderImageSynthesis
agentSpaceCameraRotationAsQuaternion.eulerAngles;
} else {
//if this third party camera is not a child of the agent, we don't need agent-relative coordinates
//Note: We don't default this to world space because in the case of a multi-agent scenario, the agent
//Note: We don't default this to world space because in the case of a multi-agent scenario, the agent
//to be relative to is ambiguous and UHHHHH
cMetadata.agentRelativeThirdPartyCameraPosition = null;
cMetadata.agentRelativeThirdPartyCameraRotation = null;
Expand Down
74 changes: 74 additions & 0 deletions unity/Assets/Scripts/ArmAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,80 @@ public virtual IEnumerator RotateAgent(
);
}

public override void Teleport(
Vector3? position = null,
Vector3? rotation = null,
float? horizon = null,
bool? standing = null,
bool forceAction = false
) {
//non-high level agents cannot set standing
if (standing != null) {
errorMessage = "Cannot set standing for arm/stretch agent";
actionFinishedEmit(success: false, actionReturn: null, errorMessage: errorMessage);
return;
}

TeleportFull(
position: position,
rotation: rotation,
horizon: horizon,
standing: standing,
forceAction: forceAction
);
}

public override void TeleportFull(
Vector3? position = null,
Vector3? rotation = null,
float? horizon = null,
bool? standing = null,
bool forceAction = false
) {
//non-high level agents cannot set standing
if (standing != null) {
errorMessage = "Cannot set standing for arm/stretch agent";
actionFinishedEmit(success: false, actionReturn: null, errorMessage: errorMessage);
return;
}

//cache old values in case there is a failure
Vector3 oldPosition = transform.position;
Quaternion oldRotation = transform.rotation;
Quaternion oldCameraRotation = m_Camera.transform.localRotation;

try {
base.teleportFull(
position: position,
rotation: rotation,
horizon: horizon,
forceAction: forceAction
);

// add arm value cases
if (!forceAction) {
if (Arm != null && Arm.IsArmColliding()) {
throw new InvalidOperationException(
"Mid Level Arm is actively clipping with some geometry in the environment. TeleportFull fails in this position."
);
} else if (SArm != null && SArm.IsArmColliding()) {
throw new InvalidOperationException(
"Stretch Arm is actively clipping with some geometry in the environment. TeleportFull fails in this position."
);
}
base.assertTeleportedNearGround(targetPosition: position);
}
} catch (InvalidOperationException e) {
transform.position = oldPosition;
transform.rotation = oldRotation;
m_Camera.transform.localRotation = oldCameraRotation;

throw new InvalidOperationException(e.Message);
}

actionFinished(success: true);
}

/*
Rotates the wrist (in a relative fashion) given some input
pitch, yaw, and roll offsets. Easiest to see how this works by
Expand Down
5 changes: 3 additions & 2 deletions unity/Assets/Scripts/DiscreteHidenSeekAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ void Update() {
) && PhysicsController.ReadyForCommand
) {
ServerAction action = new ServerAction();
if (this.PhysicsController.isStanding()) {
bool? wasStanding = this.PhysicsController.isStanding();
if (wasStanding == true) {
action.action = "Crouch";
PhysicsController.ProcessControlCommand(action);
} else {
} else if (wasStanding == false) {
action.action = "Stand";
PhysicsController.ProcessControlCommand(action);
}
Expand Down
Loading

0 comments on commit 2f3413b

Please sign in to comment.