Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
FrictionConfigurable.cs
Go to the documentation of this file.
1 using System;
6 using UnityEngine;
7 
8 namespace droid.Runtime.Prototyping.Configurables {
12  [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
13  + "Friction"
14  + ConfigurableComponentMenuPath._Postfix)]
15  [RequireComponent(typeof(Rigidbody))]
17  IHasSingle {
20  [SerializeField]
21  float _velocity_space = 0;
22 
25  Space1 _angular_velocity = Space1.ZeroOne;
26 
29  string _vel_x;
30 
31  Rigidbody _rigidbody;
32 
35  public override string PrototypingTypeName { get { return "RigidbodyConfigurable"; } }
36 
39  public Space1 SingleSpace {
40  get { return this._angular_velocity; }
41  private set { this._angular_velocity = value; }
42  }
43 
46  public float ObservationValue { get { return this._velocity_space; } }
47 
48  public override ISpace ConfigurableValueSpace { get; }
49 
52  public override void UpdateCurrentConfiguration() {
53  //this.Velocity = this._rigidbody.velocity;
54  }
55 
58  protected override void PreSetup() {
59  this._rigidbody = this.GetComponent<Rigidbody>();
60  this._vel_x = this.Identifier + "VelX";
61  }
62 
65  protected override void RegisterComponent() {
66  this.ParentEnvironment =
67  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._vel_x);
68  }
69 
72  protected override void UnRegisterComponent() {
73  if (this.ParentEnvironment == null) {
74  return;
75  }
76 
77  this.ParentEnvironment.UnRegister(this, this._vel_x);
78  }
79 
83  public override void ApplyConfiguration(IConfigurableConfiguration simulator_configuration) {
84  //var vel = this._rigidbody.velocity;
85 
86  var v = simulator_configuration.ConfigurableValue;
87  if (this.SingleSpace._Decimal_Granularity >= 0) {
88  v = (int)Math.Round(v, this.SingleSpace._Decimal_Granularity);
89  }
90 
91  if (this.SingleSpace._Min_Value.CompareTo(this.SingleSpace._Max_Value) != 0) {
92  //TODO NOT IMPLEMENTED CORRECTLY VelocitySpace should not be index but should check all pairwise values, VelocitySpace._Min_Values == VelocitySpace._Max_Values
93  if (v < this.SingleSpace._Min_Value || v > this.SingleSpace._Max_Value) {
94  Debug.Log(string.Format("Configurable does not accept input{2}, outside allowed range {0} to {1}",
95  this.SingleSpace._Min_Value,
96  this.SingleSpace._Max_Value,
97  v));
98  return; // Do nothing
99  }
100  }
101 
102  #if NEODROID_DEBUG
103  if (this.Debugging) {
104  Debug.Log("Applying " + v + " To " + this.Identifier);
105  }
106  #endif
107 
108  if (this.RelativeToExistingValue) {
109  if (simulator_configuration.ConfigurableName == this._vel_x) {
110  //vel.Set(v - vel.x, vel.y, vel.z);
111  }
112  } else {
113  if (simulator_configuration.ConfigurableName == this._vel_x) {
114  //vel.Set(v, vel.y, vel.z);
115  }
116  }
117 
118  //this._rigidbody.angularVelocity = ang;
119  }
120 
126  public override Configuration[] SampleConfigurations() {
127  return new[] {new Configuration(this._vel_x, this._angular_velocity.Sample())};
128  }
129  }
130 }
override void ApplyConfiguration(IConfigurableConfiguration simulator_configuration)