| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| using System; |
| using System.Linq; |
| using System.Xml; |
| using UnityEngine; |
|
|
| namespace Mujoco { |
|
|
| public class MjGeomVectorSensor : MjBaseSensor { |
| |
| |
| 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); |
| } |
| } |
| } |
|
|