浏览代码

updated WalkerStatic scene with new ragdoll

/hh-develop-ragdoll-testing
HH 4 年前
当前提交
6701bb3b
共有 11 个文件被更改,包括 1141 次插入3057 次删除
  1. 20
      Project/Assets/ML-Agents/Examples/Walker/Prefabs/DynamicPlatformWalker.prefab
  2. 999
      Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerPair.prefab
  3. 6
      Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerRagdoll.prefab
  4. 6
      Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerDynamic.unity
  5. 154
      Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs
  6. 1
      Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgentDynamic.cs
  7. 1001
      Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStatic.unity
  8. 1001
      Project/Assets/ML-Agents/Examples/Walker/Scenes/Walker.unity
  9. 1001
      Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStaticNewRagdoll.unity
  10. 9
      Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStaticNewRagdoll.unity.meta
  11. 0
      /Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStatic.unity.meta

20
Project/Assets/ML-Agents/Examples/Walker/Prefabs/DynamicPlatformWalker.prefab


propertyPath: m_Name
value: WalkerRagdoll
objectReference: {fileID: 0}
- target: {fileID: 895268871377934296, guid: 765582efd9dda46ed98564603316353f,
type: 3}
propertyPath: target
value:
objectReference: {fileID: 4714470935848893865}
- target: {fileID: 895268871377934296, guid: 765582efd9dda46ed98564603316353f,
type: 3}
propertyPath: ground
value:
objectReference: {fileID: 4715966284166353839}
- target: {fileID: 895268871377934298, guid: 765582efd9dda46ed98564603316353f,
type: 3}
propertyPath: m_LocalPosition.x

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7408209125961349353, guid: 765582efd9dda46ed98564603316353f,
type: 3}
propertyPath: target
value:
objectReference: {fileID: 4714470935848893865}
- target: {fileID: 7408209125961349353, guid: 765582efd9dda46ed98564603316353f,
type: 3}
propertyPath: ground
value:
objectReference: {fileID: 4715966284166353839}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 765582efd9dda46ed98564603316353f, type: 3}
--- !u!4 &6065910098925129092 stripped

999
Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerPair.prefab
文件差异内容过多而无法显示
查看文件

6
Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerRagdoll.prefab


m_Component:
- component: {fileID: 895268871377934298}
- component: {fileID: 895268871377934297}
- component: {fileID: 895268871377934296}
- component: {fileID: 7408209125961349353}
- component: {fileID: 895268871377934303}
- component: {fileID: 895268871377934302}
- component: {fileID: 895268871377934301}

m_BehaviorName: WalkerDynamic
TeamId: 0
m_UseChildSensors: 1
--- !u!114 &895268871377934296
--- !u!114 &7408209125961349353
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 21bcc2d3e08144151a0df9fa506dbbe7, type: 3}
m_Script: {fileID: 11500000, guid: ccb0f85f0009540d7ad997952e2aed7b, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:

6
Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerDynamic.unity


propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6065910098925129094, guid: f51e8260728fd4c8fa87bcda9d0e2027,
- target: {fileID: 6065910098925129092, guid: f51e8260728fd4c8fa87bcda9d0e2027,
propertyPath: showOrientationCubeGizmo
value: 1
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f51e8260728fd4c8fa87bcda9d0e2027, type: 3}

154
Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs


using MLAgentsExamples;
using UnityEditor;
using BodyPart = Unity.MLAgentsExamples.BodyPart;
[Header("Walking Speed")]
[Space(10)]
public float maximumWalkingSpeed = 999; //The max walk velocity magnitude an agent will be rewarded for
Vector3 m_WalkDir;
Quaternion m_WalkDirLookRot;
[Space(10)]
[Header("Orientation Cube")]
[Space(10)]
//This will be used as a stable observation platform for the ragdoll to use.
GameObject m_OrientationCube;
public Transform directionIndicator;
public float targetSpawnRadius;
public Transform ground;
public bool detectTargets;
public bool targetIsStatic;
public bool respawnTargetWhenTouched;
Vector3 m_DirToTarget;
[Header("Body Parts")]
[Space(10)]
public Transform hips;
public Transform chest;
public Transform spine;

Rigidbody m_SpineRb;
EnvironmentParameters m_ResetParams;
//Spawn an orientation cube
Vector3 oCubePos = hips.position;
oCubePos.y = -.45f;
m_OrientationCube = Instantiate(Resources.Load<GameObject>("OrientationCube"), oCubePos, Quaternion.identity);
m_OrientationCube.transform.SetParent(transform);
UpdateOrientationCube();
m_JdController = GetComponent<JointDriveController>();
m_JdController.SetupBodyPart(hips);
m_JdController.SetupBodyPart(chest);

/// </summary>
public void CollectObservationBodyPart(BodyPart bp, VectorSensor sensor)
{
var rb = bp.rb;
//GROUND CHECK
sensor.AddObservation(rb.velocity);
sensor.AddObservation(rb.angularVelocity);
var localPosRelToHips = hips.InverseTransformPoint(rb.position);
sensor.AddObservation(localPosRelToHips);
//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(m_OrientationCube.transform.InverseTransformDirection(bp.rb.velocity));
sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(bp.rb.angularVelocity));
//Get position relative to hips in the context of our orientation cube's space
sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(bp.rb.position - hips.position)); //best
if (bp.rb.transform != hips && bp.rb.transform != handL && bp.rb.transform != handR &&
bp.rb.transform != footL && bp.rb.transform != footR && bp.rb.transform != head)
if (bp.rb.transform != hips && bp.rb.transform != handL && bp.rb.transform != handR)
sensor.AddObservation(bp.currentXNormalizedRot);
sensor.AddObservation(bp.currentYNormalizedRot);
sensor.AddObservation(bp.currentZNormalizedRot);
sensor.AddObservation(bp.rb.transform.localRotation);
m_JdController.GetCurrentJointForces();
sensor.AddObservation(m_DirToTarget.normalized);
sensor.AddObservation(m_JdController.bodyPartsDict[hips].rb.position);
sensor.AddObservation(hips.forward);
sensor.AddObservation(hips.up);
sensor.AddObservation(Quaternion.FromToRotation(hips.forward, m_OrientationCube.transform.forward));
sensor.AddObservation(Quaternion.FromToRotation(head.forward, m_OrientationCube.transform.forward));
foreach (var bodyPart in m_JdController.bodyPartsDict.Values)
{

bpDict[footR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]);
bpDict[footL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]);
bpDict[armL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[armR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[forearmL].SetJointTargetRotation(vectorAction[++i], 0, 0);

bpDict[forearmR].SetJointStrength(vectorAction[++i]);
}
void UpdateOrientationCube()
{
//FACING DIR
m_WalkDir = target.position - m_OrientationCube.transform.position;
m_WalkDir.y = 0; //flatten dir on the y
m_WalkDirLookRot = Quaternion.LookRotation(m_WalkDir); //get our look rot to the target
//UPDATE ORIENTATION CUBE POS & ROT
m_OrientationCube.transform.position = hips.position;
m_OrientationCube.transform.rotation = m_WalkDirLookRot;
directionIndicator.position = new Vector3(hips.position.x, directionIndicator.position.y, hips.position.z);
directionIndicator.rotation = m_WalkDirLookRot;
}
if (detectTargets)
{
foreach (var bodyPart in m_JdController.bodyPartsDict.Values)
{
if (bodyPart.targetContact && bodyPart.targetContact.touchingTarget)
{
TouchedTarget();
}
}
}
UpdateOrientationCube();
// d. Discourage head movement.
m_DirToTarget = target.position - m_JdController.bodyPartsDict[hips].rb.position;
+0.03f * Vector3.Dot(m_DirToTarget.normalized, m_JdController.bodyPartsDict[hips].rb.velocity)
+ 0.01f * Vector3.Dot(m_DirToTarget.normalized, hips.forward)
+ 0.02f * (head.position.y - hips.position.y)
- 0.01f * Vector3.Distance(m_JdController.bodyPartsDict[head].rb.velocity,
m_JdController.bodyPartsDict[hips].rb.velocity)
+0.02f * Vector3.Dot(m_OrientationCube.transform.forward,
Vector3.ClampMagnitude(m_JdController.bodyPartsDict[hips].rb.velocity, maximumWalkingSpeed))
+ 0.01f * Vector3.Dot(m_OrientationCube.transform.forward, head.forward)
+ 0.005f * (head.position.y - footL.position.y)
+ 0.005f * (head.position.y - footR.position.y)
/// Agent touched the target
/// </summary>
public void TouchedTarget()
{
AddReward(1f);
if (respawnTargetWhenTouched)
{
GetRandomTargetPos();
}
}
/// <summary>
/// Moves target to a random position within specified radius.
/// </summary>
public void GetRandomTargetPos()
{
var newTargetPos = Random.insideUnitSphere * targetSpawnRadius;
newTargetPos.y = 5;
target.position = newTargetPos + ground.position;
}
/// <summary>
if (m_DirToTarget != Vector3.zero)
foreach (var bodyPart in m_JdController.bodyPartsDict.Values)
transform.rotation = Quaternion.LookRotation(m_DirToTarget);
bodyPart.Reset(bodyPart);
//Random start rotation
transform.rotation = Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0);
UpdateOrientationCube();
foreach (var bodyPart in m_JdController.bodyPartsDict.Values)
if (detectTargets && !targetIsStatic)
bodyPart.Reset(bodyPart);
GetRandomTargetPos();
SetResetParameters();
}

public void SetResetParameters()
{
SetTorsoMass();
}
private void OnDrawGizmosSelected()
{
if (Application.isPlaying)
{
Gizmos.color = Color.green;
Gizmos.matrix = m_OrientationCube.transform.localToWorldMatrix;
Gizmos.DrawWireCube(Vector3.zero, m_OrientationCube.transform.localScale);
Gizmos.DrawRay(Vector3.zero, Vector3.forward);
}
}
}

1
Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgentDynamic.cs


bpDict[footR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]);
bpDict[footL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]);
bpDict[armL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[armR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[forearmL].SetJointTargetRotation(vectorAction[++i], 0, 0);

1001
Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStatic.unity
文件差异内容过多而无法显示
查看文件

1001
Project/Assets/ML-Agents/Examples/Walker/Scenes/Walker.unity
文件差异内容过多而无法显示
查看文件

1001
Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStaticNewRagdoll.unity
文件差异内容过多而无法显示
查看文件

9
Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStaticNewRagdoll.unity.meta


fileFormatVersion: 2
guid: 4619cf9f250c14e9c9af102bc16c1323
timeCreated: 1520420566
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

/Project/Assets/ML-Agents/Examples/Walker/Scenes/Walker.unity.meta → /Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStatic.unity.meta

正在加载...
取消
保存