Version 2.1.2: Python bindings, OBJ assets support, bugfixes.
PiperOrigin-RevId: 434731612 Change-Id: I0cfda3e7a3d1c72036764986efc252ffa1b8c6b0
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
// 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 MjActuatorScalarSensorTests {
|
||||
|
||||
private MjActuatorScalarSensor _sensor;
|
||||
private MjActuator _actuator;
|
||||
private MjHingeJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjActuatorScalarSensor))
|
||||
.GetComponent<MjActuatorScalarSensor>();
|
||||
_joint = new GameObject("joint", typeof(MjHingeJoint)).GetComponent<MjHingeJoint>();
|
||||
_actuator = new GameObject("actuator", typeof(MjActuator)).GetComponent<MjActuator>();
|
||||
_actuator.Joint = _joint;
|
||||
_sensor.Actuator = _actuator;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_actuator.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorPos, "actuatorpos")]
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorVel, "actuatorvel")]
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorFrc, "actuatorfrc")]
|
||||
public void GenerateSensorName(
|
||||
MjActuatorScalarSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorPos)]
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorVel)]
|
||||
[TestCase(MjActuatorScalarSensor.AvailableSensors.ActuatorFrc)]
|
||||
public void GenerateJointReference(MjActuatorScalarSensor.AvailableSensors type) {
|
||||
var parentNode = _doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_actuator.GenerateMjcf("test_actuator", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("actuator=\"test_actuator\""));
|
||||
}
|
||||
|
||||
[TestCase("actuatorpos", MjActuatorScalarSensor.AvailableSensors.ActuatorPos)]
|
||||
[TestCase("actuatorvel", MjActuatorScalarSensor.AvailableSensors.ActuatorVel)]
|
||||
[TestCase("actuatorfrc", MjActuatorScalarSensor.AvailableSensors.ActuatorFrc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjActuatorScalarSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} actuator=\"actuator\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("actuatorpos")]
|
||||
[TestCase("actuatorvel")]
|
||||
[TestCase("actuatorfrc")]
|
||||
public void ParsingReferenceToExistingActuator(string tag) {
|
||||
var mjcfString = $"<sensors><{tag} actuator=\"actuator\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Actuator, Is.EqualTo(_actuator));
|
||||
}
|
||||
|
||||
[TestCase("actuatorpos")]
|
||||
[TestCase("actuatorvel")]
|
||||
[TestCase("actuatorfrc")]
|
||||
public void ParsingReferenceToMissingAcgtuatorThrowsException(string tag) {
|
||||
var mjcfString = $"<sensors><{tag} actuator=\"missing_actuator\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 287455e1e42ce4ac1817b65258ddd17f
|
||||
timeCreated: 1548111403
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
// 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 MjBaseSensorTests {
|
||||
|
||||
public class MjMockSensor : MjBaseSensor {
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
return doc.CreateElement("sensor");
|
||||
}
|
||||
protected override void FromMjcf(XmlElement mjcf) {}
|
||||
}
|
||||
|
||||
private MjMockSensor _sensor;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjMockSensor)).GetComponent<MjMockSensor>();
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeneratingNoiseAndCutoffMjcf() {
|
||||
_sensor.Noise = 2.0f;
|
||||
_sensor.Cutoff = 3.0f;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("name", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("noise=\"2\""));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("cutoff=\"3\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingShapePropertiesMjcf() {
|
||||
var mjcfString = "<sensor noise=\"3\" cutoff=\"4\" actuator=\"actuator\"/>";
|
||||
var mjcfElement = Parse(mjcfString, "sensor");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Noise, Is.EqualTo(3.0f));
|
||||
Assert.That(_sensor.Cutoff, Is.EqualTo(4.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bfd8b530bc0546a69960cffd3c1cb35
|
||||
timeCreated: 1548085697
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
// 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 MjBodyQuaternionSensorTests {
|
||||
|
||||
private MjBodyQuaternionSensor _sensor;
|
||||
private MjBody _body;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjBodyQuaternionSensor))
|
||||
.GetComponent<MjBodyQuaternionSensor>();
|
||||
_body = new GameObject("body", typeof(MjBody)).GetComponent<MjBody>();
|
||||
_sensor.Body = _body;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_body.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSensorName() {
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<framequat"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateBodyReference() {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
parentNode.AppendChild(_body.GenerateMjcf("test_body", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"objname=\"test_body\""));
|
||||
}
|
||||
|
||||
[TestCase(true, "xbody")]
|
||||
[TestCase(false, "body")]
|
||||
public void FrameTypeSpecification(bool useInertial, string expectedValue) {
|
||||
_sensor.UseInertialFrame = useInertial;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname=\"{expectedValue}\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingFrameBodyName() {
|
||||
var mjcfString = $"<sensors><framequat objname=\"body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"framequat");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Body, Is.EqualTo(_body));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExceptionThrownWhenReferencedBodyNotFoundInScene() {
|
||||
var mjcfString = $"<sensors><framequat objname=\"missing_body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"framequat");
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f205441f0cfbb407abd911ffd114bef9
|
||||
timeCreated: 1548171405
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,176 @@
|
||||
// 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 MjBodyVectorSensorTests {
|
||||
|
||||
private MjBodyVectorSensor _sensor;
|
||||
private MjBody _body;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjBodyVectorSensor))
|
||||
.GetComponent<MjBodyVectorSensor>();
|
||||
_body = new GameObject("body", typeof(MjBody)).GetComponent<MjBody>();
|
||||
_sensor.Body = _body;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_body.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeCom, "subtreecom")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeLinVel, "subtreelinvel")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeAngMom, "subtreeangmom")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FramePos, "framepos")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameXAxis, "framexaxis")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameYAxis, "frameyaxis")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameZAxis, "framezaxis")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinVel, "framelinvel")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngVel, "frameangvel")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinAcc, "framelinacc")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngAcc, "frameangacc")]
|
||||
public void GenerateSensorName(
|
||||
MjBodyVectorSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeCom, "body")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeLinVel, "body")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeAngMom, "body")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FramePos, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameXAxis, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameYAxis, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameZAxis, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinVel, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngVel, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinAcc, "objname")]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngAcc, "objname")]
|
||||
public void GenerateBodyReference(
|
||||
MjBodyVectorSensor.AvailableSensors type, string expectedAttribute) {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_body.GenerateMjcf("test_body", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"{expectedAttribute}=\"test_body\""));
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeCom)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeLinVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.SubtreeAngMom)]
|
||||
public void SensorsWithoutExplicitBindingTypeSpecification(
|
||||
MjBodyVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname"));
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void InertialFrameSpecification(MjBodyVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_sensor.UseInertialFrame = true;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname=\"xbody\""));
|
||||
}
|
||||
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase(MjBodyVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void RegularFrameSpecification(MjBodyVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_sensor.UseInertialFrame = false;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname=\"body\""));
|
||||
}
|
||||
|
||||
[TestCase("subtreecom", MjBodyVectorSensor.AvailableSensors.SubtreeCom)]
|
||||
[TestCase("subtreelinvel", MjBodyVectorSensor.AvailableSensors.SubtreeLinVel)]
|
||||
[TestCase("subtreeangmom", MjBodyVectorSensor.AvailableSensors.SubtreeAngMom)]
|
||||
[TestCase("framepos", MjBodyVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase("framexaxis", MjBodyVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase("frameyaxis", MjBodyVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase("framezaxis", MjBodyVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase("framelinvel", MjBodyVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase("frameangvel", MjBodyVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase("framelinacc", MjBodyVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase("frameangacc", MjBodyVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjBodyVectorSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} body=\"body\" objname=\"body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("subtreecom", "body")]
|
||||
[TestCase("subtreelinvel", "body")]
|
||||
[TestCase("subtreeangmom", "body")]
|
||||
public void ParsingSubtreeBodyName(string tag, string bodyAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {bodyAttribute}=\"body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Body, Is.EqualTo(_body));
|
||||
}
|
||||
|
||||
[TestCase("framepos", "objname")]
|
||||
[TestCase("framexaxis", "objname")]
|
||||
[TestCase("frameyaxis", "objname")]
|
||||
[TestCase("framezaxis", "objname")]
|
||||
[TestCase("framelinvel", "objname")]
|
||||
[TestCase("frameangvel", "objname")]
|
||||
[TestCase("framelinacc", "objname")]
|
||||
[TestCase("frameangacc", "objname")]
|
||||
public void ParsingFrameBodyName(string tag, string bodyAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {bodyAttribute}=\"body\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Body, Is.EqualTo(_body));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f526488db0d874499bc9af392d6dedd1
|
||||
timeCreated: 1548105164
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
// 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 MjGeomQuaternionSensorTests {
|
||||
|
||||
private MjGeomQuaternionSensor _sensor;
|
||||
private MjGeom _geom;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("MjGeomQuaternionSensorTests_sensor")
|
||||
.AddComponent<MjGeomQuaternionSensor>();
|
||||
_geom = new GameObject("MjGeomQuaternionSensorTests_geom").AddComponent<MjGeom>();
|
||||
_sensor.Geom = _geom;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_geom.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
public void GenerateSensorName() {
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("<framequat"));
|
||||
}
|
||||
|
||||
public void GenerateGeomReference() {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
parentNode.AppendChild(_geom.GenerateMjcf("test_geom", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("objname=\"test_geom\""));
|
||||
}
|
||||
|
||||
public void FrameTypeSpecification() {
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(
|
||||
_doc.OuterXml, Does.Not.Contain("objname=\"MjGeomQuaternionSensorTests_geom\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindTheReferencedGeom() {
|
||||
var mjcfString =
|
||||
"<sensors><framequat objname=\"MjGeomQuaternionSensorTests_geom\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, "framequat");
|
||||
_sensor.Geom = null;
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Geom, Is.EqualTo(_geom));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExceptionThrownWhenReferencedBodyNotFoundInScene() {
|
||||
var mjcfString = "<sensors><framequat objname=\"missing_geom\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, "framequat");
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca32673e22b8f42f58cb7fb324980224
|
||||
timeCreated: 1548171623
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,134 @@
|
||||
// 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 MjGeomVectorSensorTests {
|
||||
|
||||
private MjGeomVectorSensor _sensor;
|
||||
private MjGeom _geom;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("MjGeomVectorSensorTests_sensor")
|
||||
.AddComponent<MjGeomVectorSensor>();
|
||||
_geom = new GameObject("MjGeomVectorSensorTests_geom").AddComponent<MjGeom>();
|
||||
_sensor.Geom = _geom;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_geom.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FramePos, "framepos")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameXAxis, "framexaxis")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameYAxis, "frameyaxis")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameZAxis, "framezaxis")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinVel, "framelinvel")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngVel, "frameangvel")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinAcc, "framelinacc")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngAcc, "frameangacc")]
|
||||
public void GenerateSensorName(
|
||||
MjGeomVectorSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FramePos, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameXAxis, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameYAxis, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameZAxis, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinVel, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngVel, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinAcc, "objname")]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngAcc, "objname")]
|
||||
public void GenerateGeomReference(
|
||||
MjGeomVectorSensor.AvailableSensors type, string expectedAttribute) {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_geom.GenerateMjcf("test_geom", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"{expectedAttribute}=\"test_geom\""));
|
||||
}
|
||||
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase(MjGeomVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void FrameTypeSpecification(MjGeomVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname=\"MjGeomVectorSensorTests_geom\""));
|
||||
}
|
||||
|
||||
[TestCase("framepos", MjGeomVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase("framexaxis", MjGeomVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase("frameyaxis", MjGeomVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase("framezaxis", MjGeomVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase("framelinvel", MjGeomVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase("frameangvel", MjGeomVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase("framelinacc", MjGeomVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase("frameangacc", MjGeomVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjGeomVectorSensor.AvailableSensors expectedType) {
|
||||
var mjcfString =
|
||||
$"<sensors><{tag} geom=\"MjGeomVectorSensorTests_geom\" " +
|
||||
"objname=\"MjGeomVectorSensorTests_geom\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("framepos", "objname")]
|
||||
[TestCase("framexaxis", "objname")]
|
||||
[TestCase("frameyaxis", "objname")]
|
||||
[TestCase("framezaxis", "objname")]
|
||||
[TestCase("framelinvel", "objname")]
|
||||
[TestCase("frameangvel", "objname")]
|
||||
[TestCase("framelinacc", "objname")]
|
||||
[TestCase("frameangacc", "objname")]
|
||||
public void ParsingFrameGeomName(string tag, string siteAttribute) {
|
||||
var mjcfString =
|
||||
$"<sensors><{tag} {siteAttribute}=\"MjGeomVectorSensorTests_geom\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Geom, Is.EqualTo(_geom));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2692b29d3e9a341338aeeedf820a6ee6
|
||||
timeCreated: 1548110539
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,113 @@
|
||||
// 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 MjJointScalarSensorTests {
|
||||
|
||||
private MjJointScalarSensor _sensor;
|
||||
private MjHingeJoint _joint;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor").AddComponent<MjJointScalarSensor>();
|
||||
_joint = new GameObject("joint").AddComponent<MjHingeJoint>();
|
||||
_sensor.Joint = _joint;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_joint.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointPos, "jointpos")]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointVel, "jointvel")]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitPos, "jointlimitpos")]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitVel, "jointlimitvel")]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitFrc, "jointlimitfrc")]
|
||||
public void GenerateSensorName(
|
||||
MjJointScalarSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointPos)]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointVel)]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitPos)]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitVel)]
|
||||
[TestCase(MjJointScalarSensor.AvailableSensors.JointLimitFrc)]
|
||||
public void GenerateJointReference(MjJointScalarSensor.AvailableSensors type) {
|
||||
var parentNode = _doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_joint.GenerateMjcf("test_joint", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("joint=\"test_joint\""));
|
||||
}
|
||||
|
||||
[TestCase("jointpos", MjJointScalarSensor.AvailableSensors.JointPos)]
|
||||
[TestCase("jointvel", MjJointScalarSensor.AvailableSensors.JointVel)]
|
||||
[TestCase("jointlimitpos", MjJointScalarSensor.AvailableSensors.JointLimitPos)]
|
||||
[TestCase("jointlimitvel", MjJointScalarSensor.AvailableSensors.JointLimitVel)]
|
||||
[TestCase("jointlimitfrc", MjJointScalarSensor.AvailableSensors.JointLimitFrc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjJointScalarSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} joint=\"joint\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("jointpos")]
|
||||
[TestCase("jointvel")]
|
||||
[TestCase("jointlimitpos")]
|
||||
[TestCase("jointlimitvel")]
|
||||
[TestCase("jointlimitfrc")]
|
||||
public void ParsingReferenceToExistingJoint(string tag) {
|
||||
var mjcfString = $"<sensors><{tag} joint=\"joint\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Joint, Is.EqualTo(_joint));
|
||||
}
|
||||
|
||||
[TestCase("jointpos")]
|
||||
[TestCase("jointvel")]
|
||||
[TestCase("jointlimitpos")]
|
||||
[TestCase("jointlimitvel")]
|
||||
[TestCase("jointlimitfrc")]
|
||||
public void ParsingReferenceToMissingJointThrowsException(string tag) {
|
||||
var mjcfString = $"<sensors><{tag} joint=\"missing_joint\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 723fee04a97c5487486652cd5167bd06
|
||||
timeCreated: 1548111043
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,84 @@
|
||||
// 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 MjSiteQuaternionSensorTests {
|
||||
|
||||
private MjSiteQuaternionSensor _sensor;
|
||||
private MjSite _site;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjSiteQuaternionSensor))
|
||||
.GetComponent<MjSiteQuaternionSensor>();
|
||||
_site = new GameObject("site", typeof(MjSite)).GetComponent<MjSite>();
|
||||
_sensor.Site = _site;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_site.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSensorName() {
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("<framequat"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSiteReference() {
|
||||
var parentNode = _doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
parentNode.AppendChild(_site.GenerateMjcf("test_site", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain("objname=\"test_site\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindingRenferencedSite() {
|
||||
var mjcfString = "<sensors><framequat objname=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, "framequat");
|
||||
_sensor.Site = null;
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Site, Is.EqualTo(_site));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExceptionThrownWhenReferencedBodyNotFoundInScene() {
|
||||
var mjcfString = "<sensors><framequat objname=\"missing_site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, "framequat");
|
||||
Assert.That(() => { _sensor.ParseMjcf(mjcfElement); }, Throws.TypeOf<ArgumentException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 733b3b2c8a1ea44ddab4da302810cc4d
|
||||
timeCreated: 1548171912
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,101 @@
|
||||
// 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 MjSiteScalarSensorTests {
|
||||
|
||||
private MjSiteScalarSensor _sensor;
|
||||
private MjSite _site;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor", typeof(MjSiteScalarSensor))
|
||||
.GetComponent<MjSiteScalarSensor>();
|
||||
_site = new GameObject("site", typeof(MjSite)).GetComponent<MjSite>();
|
||||
_sensor.Site = _site;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_site.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.Touch, "touch")]
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.RangeFinder, "rangefinder")]
|
||||
public void GenerateSensorName(
|
||||
MjSiteScalarSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.Touch)]
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.RangeFinder)]
|
||||
public void GenerateSiteReference(MjSiteScalarSensor.AvailableSensors type) {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_site.GenerateMjcf("test_site", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"site=\"test_site\""));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.Touch)]
|
||||
[TestCase(MjSiteScalarSensor.AvailableSensors.RangeFinder)]
|
||||
public void SensorsWithoutExplicitBindingTypeSpecification(
|
||||
MjSiteScalarSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain($"objname"));
|
||||
}
|
||||
|
||||
[TestCase("touch", MjSiteScalarSensor.AvailableSensors.Touch)]
|
||||
[TestCase("rangefinder", MjSiteScalarSensor.AvailableSensors.RangeFinder)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjSiteScalarSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} site=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("touch", "site")]
|
||||
[TestCase("rangefinder", "site")]
|
||||
public void ParsingSubtreeSiteName(string tag, string siteAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {siteAttribute}=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, $"{tag}");
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Site, Is.EqualTo(_site));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a827466bc75c47b6afc4bc474a2a066
|
||||
timeCreated: 1548110161
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,173 @@
|
||||
// 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 MjSiteVectorSensorTests {
|
||||
|
||||
private MjSiteVectorSensor _sensor;
|
||||
private MjSite _site;
|
||||
private XmlDocument _doc;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
_sensor = new GameObject("sensor").AddComponent<MjSiteVectorSensor>();
|
||||
_site = new GameObject("site").AddComponent<MjSite>();
|
||||
_sensor.Site = _site;
|
||||
|
||||
_doc = new XmlDocument();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
UnityEngine.Object.DestroyImmediate(_sensor.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(_site.gameObject);
|
||||
}
|
||||
|
||||
private XmlElement Parse(string mjcfString, string tag) {
|
||||
_doc.LoadXml(mjcfString);
|
||||
var elementList = _doc.GetElementsByTagName(tag);
|
||||
return elementList[0] as XmlElement;
|
||||
}
|
||||
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Accelerometer, "accelerometer")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Velocimeter, "velocimeter")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Gyro, "gyro")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Force, "force")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Torque, "torque")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Magnetometer, "magnetometer")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FramePos, "framepos")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameXAxis, "framexaxis")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameYAxis, "frameyaxis")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameZAxis, "framezaxis")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinVel, "framelinvel")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngVel, "frameangvel")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinAcc, "framelinacc")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngAcc, "frameangacc")]
|
||||
public void GenerateSensorName(
|
||||
MjSiteVectorSensor.AvailableSensors type, string expectedTag) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"<{expectedTag}"));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Accelerometer, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Velocimeter, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Gyro, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Force, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Torque, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Magnetometer, "site")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FramePos, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameXAxis, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameYAxis, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameZAxis, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinVel, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngVel, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinAcc, "objname")]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngAcc, "objname")]
|
||||
public void GenerateSiteReference(
|
||||
MjSiteVectorSensor.AvailableSensors type, string expectedAttribute) {
|
||||
var parentNode = (XmlElement)_doc.CreateElement("parent");
|
||||
_doc.AppendChild(parentNode);
|
||||
_sensor.SensorType = type;
|
||||
parentNode.AppendChild(_site.GenerateMjcf("test_site", _doc));
|
||||
parentNode.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Contain($"{expectedAttribute}=\"test_site\""));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Accelerometer)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Velocimeter)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Gyro)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Force)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Torque)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.Magnetometer)]
|
||||
public void SensorsWithoutExplicitBindingTypeSpecification(
|
||||
MjSiteVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain("objname"));
|
||||
}
|
||||
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase(MjSiteVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void FrameTypeSpecification(MjSiteVectorSensor.AvailableSensors type) {
|
||||
_sensor.SensorType = type;
|
||||
_doc.AppendChild(_sensor.GenerateMjcf("test_sensor", _doc));
|
||||
Assert.That(_doc.OuterXml, Does.Not.Contain("objname=\"site\""));
|
||||
}
|
||||
|
||||
[TestCase("accelerometer", MjSiteVectorSensor.AvailableSensors.Accelerometer)]
|
||||
[TestCase("velocimeter", MjSiteVectorSensor.AvailableSensors.Velocimeter)]
|
||||
[TestCase("gyro", MjSiteVectorSensor.AvailableSensors.Gyro)]
|
||||
[TestCase("force", MjSiteVectorSensor.AvailableSensors.Force)]
|
||||
[TestCase("torque", MjSiteVectorSensor.AvailableSensors.Torque)]
|
||||
[TestCase("magnetometer", MjSiteVectorSensor.AvailableSensors.Magnetometer)]
|
||||
[TestCase("framepos", MjSiteVectorSensor.AvailableSensors.FramePos)]
|
||||
[TestCase("framexaxis", MjSiteVectorSensor.AvailableSensors.FrameXAxis)]
|
||||
[TestCase("frameyaxis", MjSiteVectorSensor.AvailableSensors.FrameYAxis)]
|
||||
[TestCase("framezaxis", MjSiteVectorSensor.AvailableSensors.FrameZAxis)]
|
||||
[TestCase("framelinvel", MjSiteVectorSensor.AvailableSensors.FrameLinVel)]
|
||||
[TestCase("frameangvel", MjSiteVectorSensor.AvailableSensors.FrameAngVel)]
|
||||
[TestCase("framelinacc", MjSiteVectorSensor.AvailableSensors.FrameLinAcc)]
|
||||
[TestCase("frameangacc", MjSiteVectorSensor.AvailableSensors.FrameAngAcc)]
|
||||
public void ParsingSensorType(
|
||||
string tag, MjSiteVectorSensor.AvailableSensors expectedType) {
|
||||
var mjcfString = $"<sensors><{tag} site=\"site\" objname=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.SensorType, Is.EqualTo(expectedType));
|
||||
}
|
||||
|
||||
[TestCase("accelerometer", "site")]
|
||||
[TestCase("velocimeter", "site")]
|
||||
[TestCase("gyro", "site")]
|
||||
[TestCase("force", "site")]
|
||||
[TestCase("torque", "site")]
|
||||
[TestCase("magnetometer", "site")]
|
||||
public void ParsingSubtreeSiteName(string tag, string siteAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {siteAttribute}=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Site, Is.EqualTo(_site));
|
||||
}
|
||||
|
||||
[TestCase("framepos", "objname")]
|
||||
[TestCase("framexaxis", "objname")]
|
||||
[TestCase("frameyaxis", "objname")]
|
||||
[TestCase("framezaxis", "objname")]
|
||||
[TestCase("framelinvel", "objname")]
|
||||
[TestCase("frameangvel", "objname")]
|
||||
[TestCase("framelinacc", "objname")]
|
||||
[TestCase("frameangacc", "objname")]
|
||||
public void ParsingFrameSiteName(string tag, string siteAttribute) {
|
||||
var mjcfString = $"<sensors><{tag} {siteAttribute}=\"site\"/></sensors>";
|
||||
var mjcfElement = Parse(mjcfString, tag);
|
||||
_sensor.ParseMjcf(mjcfElement);
|
||||
Assert.That(_sensor.Site, Is.EqualTo(_site));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f9f930ccc5684f279f5e2ca0ec29cc8
|
||||
timeCreated: 1548171912
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user