Skip to content

Commit

Permalink
more formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
winthos committed Aug 2, 2024
1 parent 2f0661d commit b2b77e8
Show file tree
Hide file tree
Showing 155 changed files with 21,114 additions and 12,171 deletions.
290 changes: 195 additions & 95 deletions unity/Assets/Scripts/ActionDispatcher.cs

Large diffs are not rendered by default.

982 changes: 664 additions & 318 deletions unity/Assets/Scripts/AgentManager.cs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion unity/Assets/Scripts/Arm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;

public interface Arm {
public interface Arm
{
// void ContinuousUpdate();
bool IsArmColliding();

Expand Down
107 changes: 72 additions & 35 deletions unity/Assets/Scripts/ArmAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
using UnityEngine;
using UnityEngine.AI;

namespace UnityStandardAssets.Characters.FirstPerson {
public abstract class ArmAgentController : PhysicsRemoteFPSAgentController {
namespace UnityStandardAssets.Characters.FirstPerson
{
public abstract class ArmAgentController : PhysicsRemoteFPSAgentController
{
public ArmAgentController(BaseAgentComponent baseAgentComponent, AgentManager agentManager)
: base(baseAgentComponent, agentManager) { }

Expand All @@ -17,19 +19,24 @@ public ArmAgentController(BaseAgentComponent baseAgentComponent, AgentManager ag
/*
Toggles the visibility of the magnet sphere at the end of the arm.
*/
public ActionFinished ToggleMagnetVisibility(bool? visible = null) {
public ActionFinished ToggleMagnetVisibility(bool? visible = null)
{
MeshRenderer mr = GameObject
.Find("MagnetRenderer")
.GetComponentInChildren<MeshRenderer>();
if (visible.HasValue) {
if (visible.HasValue)
{
mr.enabled = visible.Value;
} else {
}
else
{
mr.enabled = !mr.enabled;
}
return ActionFinished.Success;
}

public override void updateImageSynthesis(bool status) {
public override void updateImageSynthesis(bool status)
{
base.updateImageSynthesis(status);

// updateImageSynthesis is run in BaseFPSController's Initialize method after the
Expand Down Expand Up @@ -64,7 +71,8 @@ public IEnumerator MoveArmRelative(
bool returnToStart = true,
string coordinateSpace = "armBase",
bool restrictMovement = false
) {
)
{
var arm = getArm();
return arm.moveArmRelative(
controller: this,
Expand All @@ -83,7 +91,8 @@ public virtual IEnumerator MoveArm(
bool returnToStart = true,
string coordinateSpace = "armBase",
bool restrictMovement = false
) {
)
{
var arm = getArm();
return arm.moveArmTarget(
controller: this,
Expand All @@ -99,7 +108,8 @@ public virtual IEnumerator MoveArm(
// perhaps this should fail if no object is picked up?
// currently action success happens as long as the arm is
// enabled because it is a successful "attempt" to pickup something
public IEnumerator PickupObject(List<string> objectIdCandidates = null) {
public IEnumerator PickupObject(List<string> objectIdCandidates = null)
{
var arm = getArm();
return arm.PickupObject(objectIdCandidates);
}
Expand All @@ -109,7 +119,8 @@ public override void PickupObject(
float y,
bool forceAction = false,
bool manualInteract = false
) {
)
{
throw new InvalidOperationException(
"You are passing in iTHOR PickupObject parameters (x, y) to the arm agent!"
);
Expand All @@ -119,21 +130,25 @@ public override void PickupObject(
string objectId,
bool forceAction = false,
bool manualInteract = false
) {
)
{
throw new InvalidOperationException(
"You are passing in iTHOR PickupObject parameters (objectId) to the arm agent!"
);
}

public IEnumerator ReleaseObject() {
public IEnumerator ReleaseObject()
{
var arm = getArm();
return arm.DropObject();
}

// note this does not reposition the center point of the magnet orb
// so expanding the radius too much will cause it to clip backward into the wrist joint
public ActionFinished SetHandSphereRadius(float radius) {
if (radius < 0.04f || radius > 0.5f) {
public ActionFinished SetHandSphereRadius(float radius)
{
if (radius < 0.04f || radius > 0.5f)
{
throw new ArgumentOutOfRangeException(
$"radius={radius} of hand cannot be less than 0.04m nor greater than 0.5m"
);
Expand All @@ -149,8 +164,10 @@ public IEnumerator MoveAgent(
float ahead = 0,
float right = 0,
float speed = 1
) {
if (ahead == 0 && right == 0) {
)
{
if (ahead == 0 && right == 0)
{
throw new ArgumentException("Must specify ahead or right!");
}
Vector3 direction = new Vector3(x: right, y: 0, z: ahead);
Expand Down Expand Up @@ -178,7 +195,8 @@ public IEnumerator MoveAhead(
float? moveMagnitude = null,
float speed = 1,
bool returnToStart = true
) {
)
{
return MoveAgent(
ahead: moveMagnitude.GetValueOrDefault(gridSize),
speed: speed,
Expand All @@ -190,7 +208,8 @@ public IEnumerator MoveBack(
float? moveMagnitude = null,
float speed = 1,
bool returnToStart = true
) {
)
{
return MoveAgent(
ahead: -moveMagnitude.GetValueOrDefault(gridSize),
speed: speed,
Expand All @@ -202,7 +221,8 @@ public IEnumerator MoveRight(
float? moveMagnitude = null,
float speed = 1,
bool returnToStart = true
) {
)
{
return MoveAgent(
right: moveMagnitude.GetValueOrDefault(gridSize),
speed: speed,
Expand All @@ -214,7 +234,8 @@ public IEnumerator MoveLeft(
float? moveMagnitude = null,
float speed = 1,
bool returnToStart = true
) {
)
{
return MoveAgent(
right: -moveMagnitude.GetValueOrDefault(gridSize),
speed: speed,
Expand All @@ -226,7 +247,8 @@ public IEnumerator RotateRight(
float? degrees = null,
float speed = 1.0f,
bool returnToStart = true
) {
)
{
return RotateAgent(
degrees: degrees.GetValueOrDefault(rotateStepDegrees),
speed: speed,
Expand All @@ -238,7 +260,8 @@ public IEnumerator RotateLeft(
float? degrees = null,
float speed = 1.0f,
bool returnToStart = true
) {
)
{
return RotateAgent(
degrees: -degrees.GetValueOrDefault(rotateStepDegrees),
speed: speed,
Expand All @@ -250,7 +273,8 @@ public virtual IEnumerator RotateAgent(
float degrees,
float speed = 1.0f,
bool returnToStart = true
) {
)
{
CollisionListener collisionListener = this.GetComponentInParent<CollisionListener>();
collisionListener.Reset();

Expand Down Expand Up @@ -282,7 +306,8 @@ public virtual IEnumerator RotateWristRelative(
float roll = 0f,
float speed = 10f,
bool returnToStart = true
) {
)
{
var arm = getArm();
return arm.rotateWrist(
controller: this,
Expand All @@ -301,8 +326,10 @@ public virtual IEnumerator MoveArmBase(
float speed = 1,
bool returnToStart = true,
bool normalizedY = true
) {
if (normalizedY && (y < 0f || y > 1f)) {
)
{
if (normalizedY && (y < 0f || y > 1f))
{
// Checking for bounds when normalizedY == false is handled by arm.moveArmBase
throw new ArgumentOutOfRangeException(
$"y={y} value must be in [0, 1] when normalizedY=true."
Expand All @@ -324,7 +351,8 @@ public virtual IEnumerator MoveArmBaseUp(
float distance,
float speed = 1,
bool returnToStart = true
) {
)
{
var arm = getArm();
return arm.moveArmBaseUp(
controller: this,
Expand All @@ -339,24 +367,31 @@ public virtual IEnumerator MoveArmBaseDown(
float distance,
float speed = 1,
bool returnToStart = true
) {
)
{
return MoveArmBaseUp(distance: -distance, speed: speed, returnToStart: returnToStart);
}

#if UNITY_EDITOR
// debug for static arm collisions from collision listener
public void GetMidLevelArmCollisions() {
public void GetMidLevelArmCollisions()
{
var arm = getArm();
CollisionListener collisionListener = arm.GetComponentInChildren<CollisionListener>();
if (collisionListener != null) {
if (collisionListener != null)
{
List<Dictionary<string, string>> collisions =
new List<Dictionary<string, string>>();
foreach (var sc in collisionListener.StaticCollisions()) {
foreach (var sc in collisionListener.StaticCollisions())
{
Dictionary<string, string> element = new Dictionary<string, string>();
if (sc.simObjPhysics != null) {
if (sc.simObjPhysics != null)
{
element["objectType"] = "simObjPhysics";
element["name"] = sc.simObjPhysics.objectID;
} else {
}
else
{
element["objectType"] = "gameObject";
element["name"] = sc.gameObject.name;
}
Expand All @@ -367,11 +402,13 @@ public void GetMidLevelArmCollisions() {
}

// debug for static arm collisions from collision listener
public void DebugMidLevelArmCollisions() {
public void DebugMidLevelArmCollisions()
{
var arm = getArm();
List<StaticCollision> scs = arm.collisionListener.StaticCollisions().ToList();
Debug.Log("Total current active static arm collisions: " + scs.Count);
foreach (StaticCollision sc in scs) {
foreach (StaticCollision sc in scs)
{
Debug.Log("Arm static collision: " + sc.name);
}
actionFinished(true);
Expand Down
34 changes: 23 additions & 11 deletions unity/Assets/Scripts/ArmCollisionResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
using System.Linq;
using UnityEngine;

public class ArmCollisionResolver : CollisionEventResolver {
public class ArmCollisionResolver : CollisionEventResolver
{
public Collider bodyColliderIgnore;
public GameObject bodyCollidersParent;

// TODO: Abstract arm api so that this class doesn't need to be duplicated for ik arm
protected Stretch_Robot_Arm_Controller arm;

protected new void Start() {
protected new void Start()
{
base.Start();
arm = this.GetComponent<Stretch_Robot_Arm_Controller>();
var collisionListener = this.GetComponentInParent<CollisionListener>();
Expand All @@ -19,23 +21,33 @@ public class ArmCollisionResolver : CollisionEventResolver {
public override StaticCollision resolveToStaticCollision(
Collider externalCollider,
HashSet<Collider> internalColliders
) {
if (externalCollider.transform.parent != null) {
if (externalCollider.transform.parent.gameObject.Equals(bodyCollidersParent)) {
)
{
if (externalCollider.transform.parent != null)
{
if (externalCollider.transform.parent.gameObject.Equals(bodyCollidersParent))
{
// Collision with body
Debug.Log("-------- RESOLVED COLLISION WITH BODY");
return new StaticCollision() {
return new StaticCollision()
{
gameObject = externalCollider.transform.parent.gameObject
};
}
}

if (externalCollider.GetComponentInParent<Stretch_Robot_Arm_Controller>() != null) {
if (internalColliders.Count == 1 && internalColliders.First() == bodyColliderIgnore) {
if (externalCollider.GetComponentInParent<Stretch_Robot_Arm_Controller>() != null)
{
if (internalColliders.Count == 1 && internalColliders.First() == bodyColliderIgnore)
{
return null;
} else {
foreach (var objectColliderSet in arm.heldObjects.Values) {
if (objectColliderSet.Contains(externalCollider)) {
}
else
{
foreach (var objectColliderSet in arm.heldObjects.Values)
{
if (objectColliderSet.Contains(externalCollider))
{
// Held-Object collision with aram
Debug.Log("-------- RESOLVED COLLISION WITH ARm");
return new StaticCollision() { gameObject = externalCollider.gameObject };
Expand Down
Loading

0 comments on commit b2b77e8

Please sign in to comment.