Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to Teleport/TeleportFull and isStanding() #1241

Merged
merged 8 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -320,7 +320,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 @@ -1310,17 +1310,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 @@ -1337,7 +1342,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
Loading