Version 2.1.2: Python bindings, OBJ assets support, bugfixes.
PiperOrigin-RevId: 434731612 Change-Id: I0cfda3e7a3d1c72036764986efc252ffa1b8c6b0
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// 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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
public class MjActuatorScalarSensor : MjBaseSensor {
|
||||
// NOTE: These names must match sensor names listed on mujoco.org.
|
||||
// Changing them is justified only when Mujoco is upgraded to a new version.
|
||||
public enum AvailableSensors {
|
||||
ActuatorPos,
|
||||
ActuatorVel,
|
||||
ActuatorFrc,
|
||||
}
|
||||
public AvailableSensors SensorType;
|
||||
public MjActuator Actuator;
|
||||
|
||||
public double SensorReading { get; private set; }
|
||||
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
if (Actuator == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjActuator.");
|
||||
}
|
||||
var mjcf = doc.CreateElement(SensorType.ToString().ToLower());
|
||||
mjcf.SetAttribute("actuator", Actuator.MujocoName);
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
if (!Enum.TryParse(mjcf.Name, ignoreCase: true, result: out SensorType)) {
|
||||
throw new ArgumentException($"Unknown sensor type {mjcf.Name}.");
|
||||
}
|
||||
Actuator = mjcf.GetObjectReferenceAttribute<MjActuator>("actuator");
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
SensorReading = data->sensordata[_sensorAddress];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d6f957ac545d4e8ea581fcc861a0498
|
||||
timeCreated: 1548092931
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,80 @@
|
||||
// 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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
// The base class for Mujoco sensors.
|
||||
//
|
||||
// Mujoco offers a very wide range of sensors, each contingent on the following three aspects:
|
||||
// 1. the Mujoco Component it observes: Body, Joint, etc.
|
||||
// 2. the type of data it returns: scalar, Vector3, quaternion, etc.
|
||||
// 3. the field it reads to retreive the data: xpos, xquat, cfrc, etc.
|
||||
//
|
||||
// In Mujoco proper, names of some of the sensors repeat for many data types. In order to get rid
|
||||
// of this ambiguity, we chose to split the sensors into groups.
|
||||
// Each sensor class represents a group of aspects (1) and (2), which is reflected in its name.
|
||||
// For example, the class of sensors that listen to Bodies and produce Vector3 observations is
|
||||
// called MjBodyVectorSensor.
|
||||
//
|
||||
// That very class contains a wide range of sensing capabilities - as in fact most of the classes
|
||||
// do. What each sensor can sense can be controlled by the sensor's Type field. Using the
|
||||
// MjBodyVectorSensor as an example, one can set it to SubtreeCom, FramePos or any of the other
|
||||
// supported observation types.
|
||||
public abstract class MjBaseSensor : MjComponent {
|
||||
|
||||
[Tooltip("The standard deviation of zero-mean Gaussian noise added to the sensor output.")]
|
||||
[AbsoluteValue]
|
||||
public float Noise = 0.0f;
|
||||
|
||||
[Tooltip("When this value is positive, it limits the absolute value of the sensor output.")]
|
||||
[AbsoluteValue]
|
||||
public float Cutoff = 0.0f;
|
||||
|
||||
public override MujocoLib.mjtObj ObjectType => MujocoLib.mjtObj.mjOBJ_SENSOR;
|
||||
|
||||
// Address of the sensor, that can be used to index into MujocoLib.mjData_.sensordata.
|
||||
protected int _sensorAddress;
|
||||
|
||||
// Parse the component settings from an external Mjcf.
|
||||
protected override void OnParseMjcf(XmlElement mjcf) {
|
||||
Noise = mjcf.GetFloatAttribute("noise", defaultValue: 0.0f);
|
||||
Cutoff = mjcf.GetFloatAttribute("cutoff", defaultValue: 0.0f);
|
||||
FromMjcf(mjcf);
|
||||
}
|
||||
|
||||
// Generate implementation specific XML element.
|
||||
protected override XmlElement OnGenerateMjcf(XmlDocument doc) {
|
||||
var mjcf = ToMjcf(doc);
|
||||
mjcf.SetAttribute("noise", Noise.ToString());
|
||||
mjcf.SetAttribute("cutoff", Cutoff.ToString());
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
// Perform bind time initialization of the component.
|
||||
protected override unsafe void OnBindToRuntime(MujocoLib.mjModel_* model, MujocoLib.mjData_* data) {
|
||||
_sensorAddress = model->sensor_adr[MujocoId];
|
||||
}
|
||||
|
||||
// Create the implementation dependent Mjcf node.
|
||||
protected abstract XmlElement ToMjcf(XmlDocument doc);
|
||||
|
||||
// Parse the implementation dependent details from the provided Mjcf node.
|
||||
protected abstract void FromMjcf(XmlElement mjcf);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9535e8d4bdb484c4dbd07806fcae7568
|
||||
timeCreated: 1548084206
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjBodyQuaternionSensor : MjBaseSensor {
|
||||
public MjBody Body;
|
||||
|
||||
[Tooltip("Should the Frame sensors use the inertial or the regular frame of reference.")]
|
||||
public bool UseInertialFrame;
|
||||
|
||||
public Quaternion SensorReading { get; private set; }
|
||||
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
if (Body == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjBody.");
|
||||
}
|
||||
var mjcf = doc.CreateElement("framequat");
|
||||
mjcf.SetAttribute("objtype", UseInertialFrame ? "body" : "xbody");
|
||||
mjcf.SetAttribute("objname", Body.MujocoName);
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
UseInertialFrame = mjcf.HasAttribute("body");
|
||||
Body = mjcf.GetObjectReferenceAttribute<MjBody>("objname");
|
||||
if (Body == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjBody.");
|
||||
}
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
SensorReading = MjEngineTool.UnityQuaternion(data->sensordata, _sensorAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af03f553fc93c44ec8d1cc3fbbcce947
|
||||
timeCreated: 1548170856
|
||||
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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjBodyVectorSensor : MjBaseSensor {
|
||||
// NOTE: These names must match sensor names listed on mujoco.org.
|
||||
// Changing them is justified only when Mujoco is upgraded to a new version.
|
||||
public enum AvailableSensors {
|
||||
SubtreeCom,
|
||||
SubtreeLinVel,
|
||||
SubtreeAngMom,
|
||||
FramePos,
|
||||
FrameXAxis,
|
||||
FrameYAxis,
|
||||
FrameZAxis,
|
||||
FrameLinVel,
|
||||
FrameAngVel,
|
||||
FrameLinAcc,
|
||||
FrameAngAcc,
|
||||
}
|
||||
public AvailableSensors SensorType;
|
||||
public MjBody Body;
|
||||
|
||||
[Tooltip("Should the Frame sensors use the inertial or the regular frame of reference.")]
|
||||
public bool UseInertialFrame;
|
||||
|
||||
public Vector3 SensorReading { get; private set; }
|
||||
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
if (Body == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjBody.");
|
||||
}
|
||||
var tag = SensorType.ToString().ToLower();
|
||||
var mjcf = doc.CreateElement(tag);
|
||||
if (tag.Contains("frame")) {
|
||||
mjcf.SetAttribute("objtype", UseInertialFrame ? "body" : "xbody");
|
||||
mjcf.SetAttribute("objname", Body.MujocoName);
|
||||
} else {
|
||||
mjcf.SetAttribute("body", Body.MujocoName);
|
||||
}
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
if (!Enum.TryParse(mjcf.Name, ignoreCase: true, result: out SensorType)) {
|
||||
throw new ArgumentException($"Unknown sensor type {mjcf.Name}.");
|
||||
}
|
||||
if (mjcf.Name.Contains("frame")) {
|
||||
UseInertialFrame = mjcf.HasAttribute("body"); // as opposed to xbody
|
||||
Body = mjcf.GetObjectReferenceAttribute<MjBody>("objname");
|
||||
} else {
|
||||
Body = mjcf.GetObjectReferenceAttribute<MjBody>("body");
|
||||
}
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
SensorReading = MjEngineTool.UnityVector3(data->sensordata, _sensorAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 537df637b11f44df2a20bea718a015a6
|
||||
timeCreated: 1548092931
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
// 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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
public class MjGeomQuaternionSensor : MjBaseSensor {
|
||||
public MjGeom Geom;
|
||||
|
||||
public Quaternion SensorReading { get; private set; }
|
||||
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
if (Geom == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjGeom.");
|
||||
}
|
||||
var mjcf = doc.CreateElement("framequat");
|
||||
mjcf.SetAttribute("objtype", "geom");
|
||||
mjcf.SetAttribute("objname", Geom.MujocoName);
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
Geom = mjcf.GetObjectReferenceAttribute<MjGeom>("objname");
|
||||
if (Geom == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjGeom.");
|
||||
}
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
SensorReading = MjEngineTool.UnityQuaternion(data->sensordata, _sensorAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71b28b4bc4c27423aaba5b98863e0c92
|
||||
timeCreated: 1548170856
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
// 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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjGeomVectorSensor : MjBaseSensor {
|
||||
// NOTE: These names must match sensor names listed on mujoco.org.
|
||||
// Changing them is justified only when Mujoco is upgraded to a new version.
|
||||
public enum AvailableSensors {
|
||||
FramePos,
|
||||
FrameXAxis,
|
||||
FrameYAxis,
|
||||
FrameZAxis,
|
||||
FrameLinVel,
|
||||
FrameAngVel,
|
||||
FrameLinAcc,
|
||||
FrameAngAcc,
|
||||
}
|
||||
|
||||
public AvailableSensors SensorType;
|
||||
|
||||
public MjGeom Geom;
|
||||
|
||||
public Vector3 SensorReading { get; private set; }
|
||||
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
if (Geom == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjGeom.");
|
||||
}
|
||||
var mjcf = doc.CreateElement(SensorType.ToString().ToLower());
|
||||
mjcf.SetAttribute("objtype", "geom");
|
||||
mjcf.SetAttribute("objname", Geom.MujocoName);
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
if (!Enum.TryParse(mjcf.Name, ignoreCase: true, result: out SensorType)) {
|
||||
throw new ArgumentException($"Unknown sensor type {mjcf.Name}.");
|
||||
}
|
||||
Geom = mjcf.GetObjectReferenceAttribute<MjGeom>("objname");
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
SensorReading = MjEngineTool.UnityVector3(data->sensordata, _sensorAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c63b35fff51454145b2c5cabf4a81669
|
||||
timeCreated: 1548107238
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
// 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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
public class MjJointScalarSensor : MjBaseSensor {
|
||||
// NOTE: These names must match sensor names listed on mujoco.org.
|
||||
// Changing them is justified only when Mujoco is upgraded to a new version.
|
||||
public enum AvailableSensors {
|
||||
JointPos,
|
||||
JointVel,
|
||||
JointLimitPos,
|
||||
JointLimitVel,
|
||||
JointLimitFrc,
|
||||
}
|
||||
public AvailableSensors SensorType;
|
||||
public MjBaseJoint Joint;
|
||||
|
||||
public double SensorReading { get; private set; }
|
||||
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
if (Joint == null) {
|
||||
throw new NullReferenceException("Missing a reference to a Joint.");
|
||||
}
|
||||
var mjcf = doc.CreateElement(SensorType.ToString().ToLower());
|
||||
mjcf.SetAttribute("joint", Joint.MujocoName);
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
if (!Enum.TryParse(mjcf.Name, ignoreCase: true, result: out SensorType)) {
|
||||
throw new ArgumentException($"Unknown sensor type {mjcf.Name}.");
|
||||
}
|
||||
Joint = mjcf.GetObjectReferenceAttribute<MjBaseJoint>("joint");
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
SensorReading = data->sensordata[_sensorAddress];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4f0b9237548c452e8a050f3e4cba63e
|
||||
timeCreated: 1548092931
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjSiteQuaternionSensor : MjBaseSensor {
|
||||
|
||||
public MjSite Site;
|
||||
|
||||
public Quaternion SensorReading { get; private set; }
|
||||
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
if (Site == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjSite.");
|
||||
}
|
||||
var mjcf = doc.CreateElement("framequat");
|
||||
mjcf.SetAttribute("objtype", "site");
|
||||
mjcf.SetAttribute("objname", Site.MujocoName);
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
Site = mjcf.GetObjectReferenceAttribute<MjSite>("objname");
|
||||
if (Site == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjSite.");
|
||||
}
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
SensorReading = MjEngineTool.UnityQuaternion(data->sensordata, _sensorAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9184adbba0c7046b49d799f28d26c8a8
|
||||
timeCreated: 1548170856
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
// 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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjSiteScalarSensor : MjBaseSensor {
|
||||
// NOTE: These names must match sensor names listed on mujoco.org.
|
||||
// Changing them is justified only when Mujoco is upgraded to a new version.
|
||||
public enum AvailableSensors {
|
||||
Touch,
|
||||
RangeFinder,
|
||||
}
|
||||
public AvailableSensors SensorType;
|
||||
public MjSite Site;
|
||||
|
||||
public double SensorReading { get; private set; }
|
||||
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
if (Site == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjSite.");
|
||||
}
|
||||
var mjcf = doc.CreateElement(SensorType.ToString().ToLower());
|
||||
mjcf.SetAttribute("site", Site.MujocoName);
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
if (!Enum.TryParse(mjcf.Name, ignoreCase: true, result: out SensorType)) {
|
||||
throw new ArgumentException($"Unknown sensor type {mjcf.Name}.");
|
||||
}
|
||||
Site = mjcf.GetObjectReferenceAttribute<MjSite>("site");
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
SensorReading = data->sensordata[_sensorAddress];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9d61f371ce8e4821ac8c64a5bd90232
|
||||
timeCreated: 1548167404
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
// 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.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
public class MjSiteVectorSensor : MjBaseSensor {
|
||||
// NOTE: These names must match sensor names listed on mujoco.org.
|
||||
// Changing them is justified only when Mujoco is upgraded to a new version.
|
||||
public enum AvailableSensors {
|
||||
Accelerometer,
|
||||
Velocimeter,
|
||||
Gyro,
|
||||
Force,
|
||||
Torque,
|
||||
Magnetometer,
|
||||
FramePos,
|
||||
FrameXAxis,
|
||||
FrameYAxis,
|
||||
FrameZAxis,
|
||||
FrameLinVel,
|
||||
FrameAngVel,
|
||||
FrameLinAcc,
|
||||
FrameAngAcc,
|
||||
}
|
||||
public AvailableSensors SensorType;
|
||||
public MjSite Site;
|
||||
|
||||
public Vector3 SensorReading { get; private set; }
|
||||
|
||||
protected override XmlElement ToMjcf(XmlDocument doc) {
|
||||
if (Site == null) {
|
||||
throw new NullReferenceException("Missing a reference to a MjSite.");
|
||||
}
|
||||
var tag = SensorType.ToString().ToLower();
|
||||
var mjcf = doc.CreateElement(tag);
|
||||
if (tag.Contains("frame")) {
|
||||
mjcf.SetAttribute("objtype", "site");
|
||||
mjcf.SetAttribute("objname", Site.MujocoName);
|
||||
} else {
|
||||
mjcf.SetAttribute("site", Site.MujocoName);
|
||||
}
|
||||
return mjcf;
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
if (!Enum.TryParse(mjcf.Name, ignoreCase: true, result: out SensorType)) {
|
||||
throw new ArgumentException($"Unknown sensor type {mjcf.Name}.");
|
||||
}
|
||||
if (mjcf.Name.Contains("frame")) {
|
||||
Site = mjcf.GetObjectReferenceAttribute<MjSite>("objname");
|
||||
} else {
|
||||
Site = mjcf.GetObjectReferenceAttribute<MjSite>("site");
|
||||
}
|
||||
}
|
||||
|
||||
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
|
||||
SensorReading = MjEngineTool.UnityVector3(data->sensordata, _sensorAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ed49bd87930f40b9aaaf5b77beead64
|
||||
timeCreated: 1548168043
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user