Skip to content

Commit

Permalink
Added open-close cabinet door test
Browse files Browse the repository at this point in the history
  • Loading branch information
elimvb committed Sep 9, 2022
1 parent 470cc1b commit 2a3a8b4
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion unity/Assets/Scripts/CanOpen_Object.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public void stepOpen(
if ((armBase.IKTarget.position - armBase.armShoulder.position).magnitude + 1e-5 >= armBase.bone2Length + armBase.bone3Length) {
failure = failState.hyperextension;
#if UNITY_EDITOR
Debug.Log("Agent-arm hyperxtended at " + elapsedTime + ". Resetting openness.");
Debug.Log("Agent-arm hyperextended at " + elapsedTime + ". Resetting openness.");
#endif
}
}
Expand Down
78 changes: 78 additions & 0 deletions unity/Assets/UnitTests/Procedural/Physics/TestOpenClose.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System;
using UnityEngine;
using UnityEngine.TestTools;
using UnityStandardAssets.Characters.FirstPerson;
using System.Linq;

namespace Tests {
public class TestOpenClose : TestBase {
[SetUp]
public override void Setup() {
UnityEngine.SceneManagement.SceneManager.LoadScene("FloorPlan1_physics");
}

[UnityTest]
public IEnumerator TestOpening() {

yield return step(new Dictionary<string, object>() {
{ "action", "Initialize"},
{ "agentMode", "arm"},
{ "agentControllerType", "mid-level"},
{ "renderInstanceSegmentation", true}
});
yield return new WaitForSeconds(2f);

yield return step(new Dictionary<string, object>() {
{ "action", "MoveAgent"},
{ "right", -0.7f},
{ "disableRendering", true},
{ "returnToStart", true}
});

//yield return new WaitForSeconds(2f);
yield return step(new Dictionary<string, object>() {
{ "action", "MoveArm"},
{ "coordinateSpace", "world"},
{ "disableRendering", true},
{ "position", new Vector3(-1.3149f, 0.6049995f, 0.04580003f)}
});

//yield return new WaitForSeconds(2f);
yield return step(new Dictionary<string, object>() {
{ "action", "LookDown"},
{ "degrees", 30f}
});

//yield return new WaitForSeconds(2f);
yield return step(new Dictionary<string, object>() {
{ "action", "OpenObject"},
{ "objectId", "Cabinet|-01.55|+00.50|+00.38"},
{ "useGripper", true},
{ "returnToStart", true},
{ "stopAtNonStaticCol", false}
});
yield return new WaitForSeconds(2f);

Transform testCabinetDoor = GameObject.Find("Cabinet_242ff8ff").transform.Find("CabinetDoor");
bool testCabinetDoorOpened = Mathf.Approximately((testCabinetDoor.localEulerAngles.y + 360) % 360, 270);
Assert.AreEqual(testCabinetDoorOpened, true);

yield return true;
}

protected string serializeObject(object obj) {
var jsonResolver = new ShouldSerializeContractResolver();
return Newtonsoft.Json.JsonConvert.SerializeObject(
obj,
Newtonsoft.Json.Formatting.None,
new Newtonsoft.Json.JsonSerializerSettings() {
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
ContractResolver = jsonResolver
}
);
}
}
}
11 changes: 11 additions & 0 deletions unity/Assets/UnitTests/Procedural/Physics/TestOpenClose.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a3a8b4

Please # to comment.