Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
PositionSensor.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
6 using UnityEngine;
7 
8 namespace droid.Runtime.Prototyping.Sensors.Transform {
12  [AddComponentMenu(
13  SensorComponentMenuPath._ComponentMenuPath + "Position" + SensorComponentMenuPath._Postfix)]
14  [ExecuteInEditMode]
15  [Serializable]
16  public class PositionSensor : Sensor,
17  IHasTriple {
18  [Header("Observation", order = 103)]
19  [SerializeField]
20  Vector3 _position;
21 
22  [SerializeField] Space3 _position_space = new Space3(new DistributionSampler(), 10);
23 
24  [Header("Specific", order = 102)]
25  [SerializeField]
26  ObservationSpace _space = ObservationSpace.Environment_;
27 
30  public override string PrototypingTypeName { get { return "Position"; } }
31 
34  public Vector3 ObservationValue {
35  get { return this._position; }
36  set {
37  this._position = this.TripleSpace.IsNormalised
38  ? this._position_space.ClipNormaliseRound(value)
39  : value;
40  }
41  }
42 
45  public Space3 TripleSpace { get; } = new Space3();
46 
49  protected override void PreSetup() { }
50 
51  public override IEnumerable<float> FloatEnumerable {
52  get { return new[] {this.ObservationValue.x, this.ObservationValue.y, this.ObservationValue.z}; }
53  }
54 
57  public override void UpdateObservation() {
58  if (this.ParentEnvironment != null && this._space == ObservationSpace.Environment_) {
59  this.ObservationValue = this.ParentEnvironment.TransformPoint(this.transform.position);
60  } else if (this._space == ObservationSpace.Local_) {
61  this.ObservationValue = this.transform.localPosition;
62  } else {
63  this.ObservationValue = this.transform.position;
64  }
65  }
66  }
67 }
Vector3 ClipNormaliseRound(Vector3 v)
Definition: Space3.cs:55