Initial release of the Unity plugin.
PiperOrigin-RevId: 425947505
This commit is contained in:
committed by
Saran Tunyasuvunakool
parent
8ec3dd97a4
commit
6de9eafa13
@@ -0,0 +1,74 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjBallJointTests {
|
||||
|
||||
private GameObject _parent;
|
||||
private MjBallJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_parent = new GameObject("parent");
|
||||
_joint = new GameObject("joint").AddComponent<MjBallJoint>();
|
||||
_joint.transform.parent = _parent.transform;
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentWorldPositionConvertedToMjCoordinates() {
|
||||
_joint.transform.position = new Vector3(1, 2, 3);
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"pos=""1 3 2"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateLimits() {
|
||||
_joint.RangeUpper = 10;
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"range=""0 10"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingPosition() {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("pos", "1 2 3");
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.transform.localPosition, Is.EqualTo(new Vector3(1, 3, 2)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingJointLimitRangeSettings() {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("range", "0 10");
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.RangeUpper, Is.EqualTo(10));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76c34ae488142477588dcd6231bb0386
|
||||
timeCreated: 1552057103
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjBaseJointTests {
|
||||
|
||||
public class FakeJoint : MjBaseJoint {
|
||||
protected override void OnParseMjcf(XmlElement mjcf) {}
|
||||
|
||||
protected override XmlElement OnGenerateMjcf(XmlDocument doc) {
|
||||
return (XmlElement)doc.CreateElement("joint");
|
||||
}
|
||||
}
|
||||
|
||||
private FakeJoint _joint;
|
||||
private MjBaseBody _parent;
|
||||
private MjBaseBody _grandParent;
|
||||
|
||||
[Test]
|
||||
public void RetrievingBodiesConnectedByTheJoint() {
|
||||
_joint = new GameObject("joint").AddComponent<FakeJoint>();
|
||||
_parent = new GameObject("parent").AddComponent<MjBody>();
|
||||
_grandParent = new GameObject("grandParent").AddComponent<MjBody>();
|
||||
|
||||
_joint.transform.parent = _parent.transform;
|
||||
_parent.transform.parent = _grandParent.transform;
|
||||
|
||||
MjBaseBody grandParent, parent;
|
||||
_joint.GetConnectedBodies(out grandParent, out parent);
|
||||
Assert.That(grandParent, Is.EqualTo(_grandParent));
|
||||
Assert.That(parent, Is.EqualTo(_parent));
|
||||
|
||||
GameObject.DestroyImmediate(_joint.gameObject);
|
||||
GameObject.DestroyImmediate(_parent.gameObject);
|
||||
GameObject.DestroyImmediate(_grandParent.gameObject);
|
||||
GameObject.DestroyImmediate(MjScene.Instance);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RetrievingBodiesConnectedToTheWorld() {
|
||||
_joint = new GameObject("joint").AddComponent<FakeJoint>();
|
||||
_parent = new GameObject("parent").AddComponent<MjBody>();
|
||||
|
||||
_joint.transform.parent = _parent.transform;
|
||||
|
||||
MjBaseBody grandParent, parent;
|
||||
_joint.GetConnectedBodies(out grandParent, out parent);
|
||||
Assert.That(grandParent, Is.Null);
|
||||
Assert.That(parent, Is.EqualTo(_parent));
|
||||
|
||||
GameObject.DestroyImmediate(_joint.gameObject);
|
||||
GameObject.DestroyImmediate(_parent.gameObject);
|
||||
GameObject.DestroyImmediate(MjScene.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61b458a2c0d3a4c54a2ead000ba4b32e
|
||||
timeCreated: 1538412731
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjHingeJointTests {
|
||||
|
||||
private GameObject _parent;
|
||||
private MjHingeJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
private Vector3EqualityComparer _comparer;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_parent = new GameObject("parent");
|
||||
_joint = new GameObject("joint", typeof(MjHingeJoint)).GetComponent<MjHingeJoint>();
|
||||
_joint.transform.parent = _parent.transform;
|
||||
_doc = new XmlDocument();
|
||||
_comparer = new Vector3EqualityComparer(1e-3f);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentWorldPositionConvertedToMjCoordinates() {
|
||||
_joint.transform.position = new Vector3(1, 2, 3);
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"pos=""1 3 2"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestingAnOffsetAxis() {
|
||||
_joint.transform.rotation =
|
||||
Quaternion.AngleAxis(45.0f, Vector3.up);
|
||||
var element = _joint.GenerateMjcf("name", _doc);
|
||||
Assert.That(element.GetVector3Attribute("axis", Vector3.zero),
|
||||
Is.EqualTo(new Vector3(0.7071068f, -0.7071069f, 0)).Using(_comparer));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateLimits() {
|
||||
_joint.RangeLower = -20;
|
||||
_joint.RangeUpper = 10;
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"range=""-20 10"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingPosition() {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("pos", "1 2 3");
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.transform.localPosition, Is.EqualTo(new Vector3(1, 3, 2)));
|
||||
}
|
||||
|
||||
[TestCase("1 0 0", 1, 0, 0)]
|
||||
[TestCase("0 1 0", 0, 0, 1)]
|
||||
[TestCase("0 0 1", 0, 1, 0)]
|
||||
public void ParsingTranslatesRotationAxisIntoJointRotation(
|
||||
string setting, float rx, float ry, float rz) {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("axis", setting);
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.RotationAxis, Is.EqualTo(new Vector3(rx, ry, rz)).Using(_comparer));
|
||||
}
|
||||
|
||||
[TestCase("0 10", 0, 10)]
|
||||
[TestCase("-10 0", -10, 0)]
|
||||
[TestCase("-10 10", -10, 10)]
|
||||
public void ParsingJointLimitRangeSettings(
|
||||
string setting, float expectedLow, float expectedHigh) {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("range", setting);
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.RangeLower, Is.EqualTo(expectedLow));
|
||||
Assert.That(_joint.RangeUpper, Is.EqualTo(expectedHigh));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61d44d0160a1c43e38cb0f9eaebbfa92
|
||||
timeCreated: 1537527115
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,223 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjJointSettingsGenerationTests {
|
||||
|
||||
private MjJointSettings _settings;
|
||||
private XmlDocument _doc;
|
||||
private XmlElement _mjcf;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_settings = new MjJointSettings();
|
||||
_doc = new XmlDocument();
|
||||
_mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DampingMjcf() {
|
||||
_settings.Spring.Damping = 5;
|
||||
_settings.Spring.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"damping=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FrictionLossMjcf() {
|
||||
_settings.Solver.FrictionLoss = 5;
|
||||
_settings.Solver.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"frictionloss=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StiffnessMjcf() {
|
||||
_settings.Spring.Stiffness = 5;
|
||||
_settings.Spring.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"stiffness=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpringDamperSettingsMjcf() {
|
||||
_settings.Spring.TimeConstant = 5;
|
||||
_settings.Spring.DampingRatio = 6;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"springdamper=""5 6"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpringEquilibriumPoseMjcf() {
|
||||
_settings.Spring.EquilibriumPose = 5;
|
||||
_settings.Spring.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"springref=""5"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArmatureMjcf() {
|
||||
_settings.Armature = 3;
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"armature=""3"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverRefLimitMjcf() {
|
||||
_settings.Solver.RefLimit = new SolverReference() { TimeConst = 5, DampRatio = 6 };
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solreflimit=""5 6"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpLimitMjcf() {
|
||||
_settings.Solver.ImpLimit = new SolverImpedance() {
|
||||
DMin = 5, DMax = 6, Width = 7, Midpoint = 8, Power = 9 };
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solimplimit=""5 6 7 8 9"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverRefFrictionMjcf() {
|
||||
_settings.Solver.RefFriction = new SolverReference() { TimeConst = 5, DampRatio = 6 };
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solreffriction=""5 6"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpFrictionMjcf() {
|
||||
_settings.Solver.ImpFriction = new SolverImpedance() {
|
||||
DMin = 5, DMax = 6, Width = 7, Midpoint = 8, Power = 9 };
|
||||
_settings.ToMjcf(_mjcf);
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"solimpfriction=""5 6 7 8 9"""));
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class MjJointSettingsParsingTests {
|
||||
|
||||
private MjJointSettings _settings;
|
||||
private XmlDocument _doc;
|
||||
private XmlElement _mjcf;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_doc = new XmlDocument();
|
||||
_mjcf = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
_settings = new MjJointSettings();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DampingMjcf() {
|
||||
_mjcf.SetAttribute("damping", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Spring.Damping, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArmatureMjcf() {
|
||||
_mjcf.SetAttribute("armature", "3");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Armature, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FrictionLossMjcf() {
|
||||
_mjcf.SetAttribute("frictionloss", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.FrictionLoss, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StiffnessMjcf() {
|
||||
_mjcf.SetAttribute("stiffness", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Spring.Stiffness, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpringDamperSettingsMjcf() {
|
||||
_mjcf.SetAttribute("springdamper", "5 6");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Spring.TimeConstant, Is.EqualTo(5));
|
||||
Assert.That(_settings.Spring.DampingRatio, Is.EqualTo(6));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpringEquilibriumPoseMjcf() {
|
||||
_mjcf.SetAttribute("springref", "5");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Spring.EquilibriumPose, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[TestCase("true", true)]
|
||||
[TestCase("false", false)]
|
||||
public void ParsingJointLimitSettings(string setting, bool expected) {
|
||||
_mjcf.SetAttribute("limited", setting);
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.Limited, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("1", 1)]
|
||||
[TestCase("-5", -5)]
|
||||
public void ParsingJointLimitMarginSettings(string setting, float expected) {
|
||||
_mjcf.SetAttribute("margin", setting);
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.Margin, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverRefLimitMjcf() {
|
||||
_mjcf.SetAttribute("solreflimit", "5 6");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.RefLimit.TimeConst, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.RefLimit.DampRatio, Is.EqualTo(6));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpLimitMjcf() {
|
||||
_mjcf.SetAttribute("solimplimit", "5 6 7 8 9");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.ImpLimit.DMin, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.ImpLimit.DMax, Is.EqualTo(6));
|
||||
Assert.That(_settings.Solver.ImpLimit.Width, Is.EqualTo(7));
|
||||
Assert.That(_settings.Solver.ImpLimit.Midpoint, Is.EqualTo(8));
|
||||
Assert.That(_settings.Solver.ImpLimit.Power, Is.EqualTo(9));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverRefFrictionMjcf() {
|
||||
_mjcf.SetAttribute("solreffriction", "5 6");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.RefFriction.TimeConst, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.RefFriction.DampRatio, Is.EqualTo(6));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SolverImpFrictionMjcf() {
|
||||
_mjcf.SetAttribute("solimpfriction", "5 6 7 8 9");
|
||||
_settings.FromMjcf(_mjcf);
|
||||
Assert.That(_settings.Solver.ImpFriction.DMin, Is.EqualTo(5));
|
||||
Assert.That(_settings.Solver.ImpFriction.DMax, Is.EqualTo(6));
|
||||
Assert.That(_settings.Solver.ImpFriction.Width, Is.EqualTo(7));
|
||||
Assert.That(_settings.Solver.ImpFriction.Midpoint, Is.EqualTo(8));
|
||||
Assert.That(_settings.Solver.ImpFriction.Power, Is.EqualTo(9));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05670ca69732c47f58a7a6f61510efad
|
||||
timeCreated: 1539945962
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
[TestFixture]
|
||||
public class MjSlideJointTests {
|
||||
|
||||
private GameObject _parent;
|
||||
private MjSlideJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
private Vector3EqualityComparer _comparer;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_parent = new GameObject("parent");
|
||||
_joint = new GameObject("joint", typeof(MjSlideJoint)).GetComponent<MjSlideJoint>();
|
||||
_joint.transform.parent = _parent.transform;
|
||||
_doc = new XmlDocument();
|
||||
_comparer = new Vector3EqualityComparer(1e-3f);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
GameObject.DestroyImmediate(_parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentWorldPositionConvertedToMjCoordinates() {
|
||||
_joint.transform.position = new Vector3(1, 2, 3);
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"pos=""1 3 2"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateLimits() {
|
||||
_joint.RangeLower = -20;
|
||||
_joint.RangeUpper = 10;
|
||||
_doc.AppendChild(_joint.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain(@"range=""-20 10"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestingAnOffsetAxis() {
|
||||
_joint.transform.rotation =
|
||||
Quaternion.AngleAxis(45.0f, Vector3.up);
|
||||
var element = _joint.GenerateMjcf("name", _doc);
|
||||
Assert.That(element.GetVector3Attribute("axis", Vector3.zero),
|
||||
Is.EqualTo(new Vector3(0.7071068f, -0.7071069f, 0)).Using(_comparer));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingPosition() {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("pos", "1 2 3");
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.transform.localPosition, Is.EqualTo(new Vector3(1, 3, 2)));
|
||||
}
|
||||
|
||||
[TestCase("1 0 0", 1, 0, 0)]
|
||||
[TestCase("0 1 0", 0, 0, 1)]
|
||||
[TestCase("0 0 1", 0, 1, 0)]
|
||||
public void ParsingTranslatesSlidexisIntoJointRotation(
|
||||
string setting, float rx, float ry, float rz) {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("axis", setting);
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.SlideAxis, Is.EqualTo(new Vector3(rx, ry, rz)).Using(_comparer));
|
||||
}
|
||||
|
||||
[TestCase("0 10", 0, 10)]
|
||||
[TestCase("-10 0", -10, 0)]
|
||||
[TestCase("-10 10", -10, 10)]
|
||||
public void ParsingJointLimitRangeSettings(
|
||||
string setting, float expectedLow, float expectedHigh) {
|
||||
var jointElement = (XmlElement)_doc.AppendChild(_doc.CreateElement("joint"));
|
||||
jointElement.SetAttribute("range", setting);
|
||||
_joint.ParseMjcf(jointElement);
|
||||
Assert.That(_joint.RangeLower, Is.EqualTo(expectedLow));
|
||||
Assert.That(_joint.RangeUpper, Is.EqualTo(expectedHigh));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dffb7c2e3d1504bfd8830b6c511732ef
|
||||
timeCreated: 1537806570
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user