浏览代码

Uses matrix maths for observation vectors.

/hotfix-v0.9.2a
GitHub 5 年前
当前提交
17a320a4
共有 1 个文件被更改,包括 19 次插入10 次删除
  1. 29
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs

29
UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs


bool isNewDecisionStep;
int currentDecisionStep;
private Transform workingTransform;
Quaternion lookRotation;
Matrix4x4 targetDirMatrix;
public override void InitializeAgent()
{

jdController.SetupBodyPart(leg2Lower);
jdController.SetupBodyPart(leg3Upper);
jdController.SetupBodyPart(leg3Lower);
workingTransform = new GameObject().transform;
}
}
/// <summary>
/// We only need to change the joint settings based on decision freq.

var rb = bp.rb;
AddVectorObs(bp.groundContact.touchingGround ? 1 : 0); // Whether the bp touching the ground
AddVectorObs(workingTransform.InverseTransformVector(rb.velocity));
AddVectorObs(workingTransform.InverseTransformDirection(rb.angularVelocity));
Vector3 velocityRelativeToLookRotationToTarget = targetDirMatrix.inverse.MultiplyVector(rb.velocity);
AddVectorObs(velocityRelativeToLookRotationToTarget);
Vector3 angularVelocityRelativeToLookRotationToTarget = targetDirMatrix.inverse.MultiplyVector(rb.angularVelocity);
AddVectorObs(angularVelocityRelativeToLookRotationToTarget);
if (bp.rb.transform != body)
{

jdController.GetCurrentJointForces();
// Normalize dir vector to help generalize
workingTransform.rotation = Quaternion.LookRotation(dirToTarget);
lookRotation = Quaternion.LookRotation(dirToTarget);
targetDirMatrix = Matrix4x4.TRS(Vector3.zero, lookRotation, Vector3.one);
// Forward & up to help with orientation
RaycastHit hit;
if (Physics.Raycast(body.position, Vector3.down, out hit, 10.0f))

else
AddVectorObs(10.0f);
AddVectorObs(workingTransform.InverseTransformVector(body.forward));
AddVectorObs(workingTransform.InverseTransformVector(body.up));
AddVectorObs(10.0f);
Vector3 bodyForwardRelativeToLookRotationToTarget = targetDirMatrix.inverse.MultiplyVector(body.forward);
AddVectorObs(bodyForwardRelativeToLookRotationToTarget);
Vector3 bodyUpRelativeToLookRotationToTarget = targetDirMatrix.inverse.MultiplyVector(body.up);
AddVectorObs(bodyUpRelativeToLookRotationToTarget);
foreach (var bodyPart in jdController.bodyPartsDict.Values)
{
CollectObservationBodyPart(bodyPart);

正在加载...
取消
保存