-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[MLA-1135] Physics sensors - optional reference body #4276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
[assembly: InternalsVisibleTo("Unity.ML-Agents.Editor.Tests")] | ||
[assembly: InternalsVisibleTo("Unity.ML-Agents.Editor")] | ||
[assembly: InternalsVisibleTo("Unity.ML-Agents.Extensions")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly controversial; I added this to get timers. But it's something we could use in the future, e.g. public actuators in extensions, but keep IActuator internal.
|
||
//Get velocities in the context of our orientation cube's space | ||
//Note: You can get these velocities in world space as well but it may not train as well. | ||
sensor.AddObservation(orientationCube.transform.InverseTransformDirection(bp.rb.velocity)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponds to model space velocity
//Get velocities in the context of our orientation cube's space | ||
//Note: You can get these velocities in world space as well but it may not train as well. | ||
sensor.AddObservation(orientationCube.transform.InverseTransformDirection(bp.rb.velocity)); | ||
sensor.AddObservation(orientationCube.transform.InverseTransformDirection(bp.rb.angularVelocity)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No direct correspondence, but removing it didn't seem to hurt much. I also need to convince myself that you can just transform angular velocities like that.
sensor.AddObservation(orientationCube.transform.InverseTransformDirection(bp.rb.angularVelocity)); | ||
|
||
//Get position relative to hips in the context of our orientation cube's space | ||
sensor.AddObservation(orientationCube.transform.InverseTransformDirection(bp.rb.position - body.position)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponds to model space positions
|
||
if (bp.rb.transform != body) | ||
{ | ||
sensor.AddObservation(bp.rb.transform.localRotation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponds to local space rotations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these decisions that could have been made with the help of the tool @andrewcoh was talking about for saliency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I removed everything from CollectObservations that had an equivalent in the sensor.
In general, we could turn everything on in the sensor, run the tool to see what's important, and then disable unimportant stuff. However:
- It could be tedious to attribute a particular index in the tool to a specific option in the sensor.
- The tool might be too fine-grained. For example, if it said that the w component of one quaternion wasn't relevant, we couldn't just turn that one off. Or if local space velocities was only relevant for one body, we couldn't keep that one but disable the rest.
com.unity.ml-agents.extensions/Runtime/Sensors/PhysicsSensorSettings.cs
Outdated
Show resolved
Hide resolved
propertyPath: targetToLookAt | ||
value: | ||
objectReference: {fileID: 7802320107249901494} | ||
- target: {fileID: 4622120667686875944, guid: 0456c89e8c9c243d595b039fe7aa0bf9, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, don't think I meant to override this. Now I need to double check the model settings
com.unity.ml-agents.extensions/Runtime/Sensors/PoseExtractor.cs
Outdated
Show resolved
Hide resolved
com.unity.ml-agents.extensions/Runtime/Sensors/PhysicsSensorSettings.cs
Outdated
Show resolved
Hide resolved
/// </summary> | ||
/// <param name="index"></param> | ||
/// <param name="val"></param> | ||
public void SetPoseEnabled(int index, bool val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SetPoseEnabled is only used to make sure the Virtual Root is not being observed right? I did not see being used elsewhere. Making it public might be dangerous, dot sure what would happen if the user called SetPoseEnabled in the middle of training.
Also, nothing to do with Enabled / Disabled GameObjects right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment, it's only used on the root (virtual or otherwise). But I was to add a custom Editor to expose it per-body. For example, on the Worm scene, the eyes are actually rigid bodies constrained to the head, with locked linear motion and free angular motion:
We would basically be wasting observations on those, so I'd like to be able to filter them out.
For now, I'd prefer to keep things more accessible, and tighten up the visibility if we move to the core package.
Correct, nothing to do Enabled / Disabled GameObjects. I hadn't thought about that - is there a better name that would make this more obvious?
/// </summary> | ||
/// <param name="parentIndices"></param> | ||
protected void SetParentIndices(int[] parentIndices) | ||
protected void Setup(int[] parentIndices) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the assumption be checked since this is a protected method on a public class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done now.
|
||
/// <inheritdoc/> | ||
protected override Vector3 GetLinearVelocityAt(int index) | ||
protected internal override Vector3 GetLinearVelocityAt(int index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the internal addition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanted to be able to assert on it
ml-agents/com.unity.ml-agents.extensions/Tests/Editor/Sensors/RigidBodyPoseExtractorTests.cs
Line 67 in 7e75f12
Assert.AreEqual(rb1.velocity, poseExtractor.GetLinearVelocityAt(0)); |
// * go2 | ||
// - rb2 | ||
// - joint | ||
var virtualRoot = new GameObject("I am vroot"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🌳
Proposed change(s)
Followup:
Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
https://jira.unity3d.com/browse/MLA-1135
https://jira.unity3d.com/browse/MLA-1166
https://jira.unity3d.com/browse/MLA-1167
Types of change(s)
Checklist
Other comments