Chris Elion
5 年前
当前提交
2f7174f0
共有 78 个文件被更改,包括 18730 次插入 和 1937 次删除
-
7Project/Assets/ML-Agents/Examples/3DBall/Demos/Expert3DBall.demo.meta
-
7Project/Assets/ML-Agents/Examples/3DBall/Demos/Expert3DBallHard.demo.meta
-
7Project/Assets/ML-Agents/Examples/Basic/Demos/ExpertBasic.demo.meta
-
7Project/Assets/ML-Agents/Examples/Bouncer/Demos/ExpertBouncer.demo.meta
-
7Project/Assets/ML-Agents/Examples/Crawler/Demos/ExpertCrawlerDyn.demo.meta
-
7Project/Assets/ML-Agents/Examples/Crawler/Demos/ExpertCrawlerSta.demo.meta
-
978Project/Assets/ML-Agents/Examples/Crawler/Prefabs/DynamicPlatform.prefab
-
108Project/Assets/ML-Agents/Examples/Crawler/Prefabs/FixedPlatform.prefab
-
3Project/Assets/ML-Agents/Examples/Crawler/Prefabs/FixedPlatform.prefab.meta
-
954Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerDynamicTarget.unity
-
943Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerStaticTarget.unity
-
466Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
-
7Project/Assets/ML-Agents/Examples/FoodCollector/Demos/ExpertFood.demo.meta
-
7Project/Assets/ML-Agents/Examples/GridWorld/Demos/ExpertGrid.demo.meta
-
7Project/Assets/ML-Agents/Examples/Hallway/Demos/ExpertHallway.demo.meta
-
7Project/Assets/ML-Agents/Examples/PushBlock/Demos/ExpertPush.demo.meta
-
7Project/Assets/ML-Agents/Examples/Pyramids/Demos/ExpertPyramid.demo.meta
-
7Project/Assets/ML-Agents/Examples/Reacher/Demos/ExpertReacher.demo.meta
-
937Project/Assets/ML-Agents/Examples/Reacher/Prefabs/Agent.prefab
-
85Project/Assets/ML-Agents/Examples/Reacher/Scenes/Reacher.unity
-
208Project/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAgent.cs
-
41Project/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherGoal.cs
-
7Project/Assets/ML-Agents/Examples/Tennis/Demos/ExpertTennis.demo.meta
-
7Project/Assets/ML-Agents/Examples/Walker/Demos/ExpertWalker.demo.meta
-
21Project/Packages/manifest.json
-
3Project/ProjectSettings/ProjectVersion.txt
-
401Project/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedCrawler.prefab
-
7Project/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedCrawler.prefab.meta
-
978Project/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedDynamicPlatform.prefab
-
7Project/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedDynamicPlatform.prefab.meta
-
801Project/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedFixedPlatform.prefab
-
7Project/Assets/ML-Agents/Examples/Crawler/Prefabs/ArticulatedFixedPlatform.prefab.meta
-
1001Project/Assets/ML-Agents/Examples/Crawler/Prefabs/Body.prefab
-
7Project/Assets/ML-Agents/Examples/Crawler/Prefabs/Body.prefab.meta
-
1001Project/Assets/ML-Agents/Examples/Crawler/Prefabs/Crawler.prefab
-
8Project/Assets/ML-Agents/Examples/Crawler/Prefabs/Crawler.prefab.meta
-
1001Project/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerDynamicTarget.unity
-
7Project/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerDynamicTarget.unity.meta
-
580Project/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerManualControl.unity
-
7Project/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerManualControl.unity.meta
-
1001Project/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerStaticTarget.unity
-
7Project/Assets/ML-Agents/Examples/Crawler/Scenes/ArticulatedCrawlerStaticTarget.unity.meta
-
370Project/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerAgent.cs
-
3Project/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerAgent.cs.meta
-
279Project/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerManualControl.cs
-
3Project/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedCrawlerManualControl.cs.meta
-
169Project/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedJointDriveController.cs
-
3Project/Assets/ML-Agents/Examples/Crawler/Scripts/ArticulatedJointDriveController.cs.meta
-
25Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAcademy.cs
-
11Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAcademy.cs.meta
-
1001Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamicLearning.nn
-
11Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamicLearning.nn.meta
-
1001Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStaticLearning.nn
-
11Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStaticLearning.nn.meta
-
369Project/Assets/ML-Agents/Examples/Reacher/Prefabs/ArticulatedAgent.prefab
-
7Project/Assets/ML-Agents/Examples/Reacher/Prefabs/ArticulatedAgent.prefab.meta
-
626Project/Assets/ML-Agents/Examples/Reacher/Prefabs/ReacherRoot.prefab
-
7Project/Assets/ML-Agents/Examples/Reacher/Prefabs/ReacherRoot.prefab.meta
-
1001Project/Assets/ML-Agents/Examples/Reacher/Scenes/ArticulatedReacher.unity
-
7Project/Assets/ML-Agents/Examples/Reacher/Scenes/ArticulatedReacher.unity.meta
-
589Project/Assets/ML-Agents/Examples/Reacher/Scenes/ArticulatedReacherManualControl.unity
-
7Project/Assets/ML-Agents/Examples/Reacher/Scenes/ArticulatedReacherManualControl.unity.meta
-
918Project/Assets/ML-Agents/Examples/Reacher/Scenes/scaling.unity
-
7Project/Assets/ML-Agents/Examples/Reacher/Scenes/scaling.unity.meta
-
875Project/Assets/ML-Agents/Examples/Reacher/Scenes/simpleTest.unity
-
7Project/Assets/ML-Agents/Examples/Reacher/Scenes/simpleTest.unity.meta
-
1001Project/Assets/ML-Agents/Examples/Reacher/Scenes/testHand.unity
-
7Project/Assets/ML-Agents/Examples/Reacher/Scenes/testHand.unity.meta
-
178Project/Assets/ML-Agents/Examples/Reacher/Scripts/ArticulatedReacherAgent.cs
-
11Project/Assets/ML-Agents/Examples/Reacher/Scripts/ArticulatedReacherAgent.cs.meta
-
37Project/Assets/ML-Agents/Examples/Reacher/Scripts/ArticulatedReacherGoal.cs
-
3Project/Assets/ML-Agents/Examples/Reacher/Scripts/ArticulatedReacherGoal.cs.meta
-
137Project/Assets/ML-Agents/Examples/Reacher/Scripts/ManualControlReacherArm.cs
-
3Project/Assets/ML-Agents/Examples/Reacher/Scripts/ManualControlReacherArm.cs.meta
-
14Project/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAcademy.cs
-
12Project/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAcademy.cs.meta
-
284Project/Assets/ML-Agents/Examples/Reacher/TFModels/ReacherLearning.nn
-
7Project/Assets/ML-Agents/Examples/Reacher/TFModels/ReacherLearning.nn.meta
|
|||
fileFormatVersion: 2 |
|||
guid: bbf6756da134740eaa002a1b84f655cb |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/3DBall/Demos/Expert3DBall.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/3DBall/Demos/Expert3DBall.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6942431e411b146be9a597663eca89af |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/3DBall/Demos/Expert3DBallHard.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/3DBall/Demos/Expert3DBallHard.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 414224ce8b3e247ad936b17f574b10ab |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/Basic/Demos/ExpertBasic.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/Basic/Demos/ExpertBasic.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6285af622c80e493b906f26cf5b2327f |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/Bouncer/Demos/ExpertBouncer.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/Bouncer/Demos/ExpertBouncer.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 557283e524ca0493ebc67c7b475304fe |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/Crawler/Demos/ExpertCrawlerDyn.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/Crawler/Demos/ExpertCrawlerDyn.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 4975695b6ea23446a94c9be3b5d21731 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/Crawler/Demos/ExpertCrawlerSta.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/Crawler/Demos/ExpertCrawlerSta.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
978
Project/Assets/ML-Agents/Examples/Crawler/Prefabs/DynamicPlatform.prefab
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 1b9d167a4e71146a883212e4f08bda88 |
|||
NativeFormatImporter: |
|||
PrefabImporter: |
|||
mainObjectFileID: 100100000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
954
Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerDynamicTarget.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
943
Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerStaticTarget.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using UnityEngine; |
|||
using Unity.MLAgents; |
|||
using Unity.MLAgentsExamples; |
|||
[RequireComponent(typeof(JointDriveController))] // Required to set joint forces
|
|||
public class CrawlerAgent : Agent |
|||
namespace Unity.MLAgentsExamples |
|||
[Header("Target To Walk Towards")] |
|||
[Space(10)] |
|||
public Transform target; |
|||
public Transform ground; |
|||
public bool detectTargets; |
|||
public bool targetIsStatic; |
|||
public bool respawnTargetWhenTouched; |
|||
public float targetSpawnRadius; |
|||
[RequireComponent(typeof(JointDriveController))] // Required to set joint forces
|
|||
public class CrawlerAgent : Agent |
|||
{ |
|||
[Header("Target To Walk Towards")] |
|||
[Space(10)] |
|||
public Transform target; |
|||
[Header("Body Parts")] [Space(10)] public Transform body; |
|||
public Transform leg0Upper; |
|||
public Transform leg0Lower; |
|||
public Transform leg1Upper; |
|||
public Transform leg1Lower; |
|||
public Transform leg2Upper; |
|||
public Transform leg2Lower; |
|||
public Transform leg3Upper; |
|||
public Transform leg3Lower; |
|||
public Transform ground; |
|||
public bool detectTargets; |
|||
public bool targetIsStatic = false; |
|||
public bool respawnTargetWhenTouched; |
|||
public float targetSpawnRadius; |
|||
[Header("Joint Settings")] [Space(10)] JointDriveController m_JdController; |
|||
Vector3 m_DirToTarget; |
|||
float m_MovingTowardsDot; |
|||
float m_FacingDot; |
|||
[Header("Body Parts")] |
|||
[Space(10)] |
|||
public Transform body; |
|||
public Transform leg0Upper; |
|||
public Transform leg0Lower; |
|||
public Transform leg1Upper; |
|||
public Transform leg1Lower; |
|||
public Transform leg2Upper; |
|||
public Transform leg2Lower; |
|||
public Transform leg3Upper; |
|||
public Transform leg3Lower; |
|||
[Header("Reward Functions To Use")] |
|||
[Space(10)] |
|||
public bool rewardMovingTowardsTarget; // Agent should move towards target
|
|||
[Header("Joint Settings")] |
|||
[Space(10)] |
|||
JointDriveController m_JdController; |
|||
Vector3 m_DirToTarget; |
|||
float m_MovingTowardsDot; |
|||
float m_FacingDot; |
|||
public bool rewardFacingTarget; // Agent should face the target
|
|||
public bool rewardUseTimePenalty; // Hurry up
|
|||
[Header("Reward Functions To Use")] |
|||
[Space(10)] |
|||
public bool rewardMovingTowardsTarget; // Agent should move towards target
|
|||
[Header("Foot Grounded Visualization")] |
|||
[Space(10)] |
|||
public bool useFootGroundedVisualization; |
|||
public bool rewardFacingTarget; // Agent should face the target
|
|||
public bool rewardUseTimePenalty; // Hurry up
|
|||
public MeshRenderer foot0; |
|||
public MeshRenderer foot1; |
|||
public MeshRenderer foot2; |
|||
public MeshRenderer foot3; |
|||
public Material groundedMaterial; |
|||
public Material unGroundedMaterial; |
|||
[Header("Foot Grounded Visualization")] |
|||
[Space(10)] |
|||
public bool useFootGroundedVisualization; |
|||
Quaternion m_LookRotation; |
|||
Matrix4x4 m_TargetDirMatrix; |
|||
public MeshRenderer foot0; |
|||
public MeshRenderer foot1; |
|||
public MeshRenderer foot2; |
|||
public MeshRenderer foot3; |
|||
public Material groundedMaterial; |
|||
public Material unGroundedMaterial; |
|||
bool m_IsNewDecisionStep; |
|||
int m_CurrentDecisionStep; |
|||
public override void Initialize() |
|||
{ |
|||
m_JdController = GetComponent<JointDriveController>(); |
|||
m_DirToTarget = target.position - body.position; |
|||
Quaternion m_LookRotation; |
|||
Matrix4x4 m_TargetDirMatrix; |
|||
public override void Initialize() |
|||
{ |
|||
m_JdController = GetComponent<JointDriveController>(); |
|||
m_CurrentDecisionStep = 1; |
|||
m_DirToTarget = target.position - body.position; |
|||
//Setup each body part
|
|||
m_JdController.SetupBodyPart(body); |
|||
m_JdController.SetupBodyPart(leg0Upper); |
|||
m_JdController.SetupBodyPart(leg0Lower); |
|||
m_JdController.SetupBodyPart(leg1Upper); |
|||
m_JdController.SetupBodyPart(leg1Lower); |
|||
m_JdController.SetupBodyPart(leg2Upper); |
|||
m_JdController.SetupBodyPart(leg2Lower); |
|||
m_JdController.SetupBodyPart(leg3Upper); |
|||
m_JdController.SetupBodyPart(leg3Lower); |
|||
} |
|||
/// <summary>
|
|||
/// Add relevant information on each body part to observations.
|
|||
/// </summary>
|
|||
public void CollectObservationBodyPart(BodyPart bp, VectorSensor sensor) |
|||
{ |
|||
var rb = bp.rb; |
|||
sensor.AddObservation(bp.groundContact.touchingGround ? 1 : 0); // Whether the bp touching the ground
|
|||
//Setup each body part
|
|||
m_JdController.SetupBodyPart(body); |
|||
m_JdController.SetupBodyPart(leg0Upper); |
|||
m_JdController.SetupBodyPart(leg0Lower); |
|||
m_JdController.SetupBodyPart(leg1Upper); |
|||
m_JdController.SetupBodyPart(leg1Lower); |
|||
m_JdController.SetupBodyPart(leg2Upper); |
|||
m_JdController.SetupBodyPart(leg2Lower); |
|||
m_JdController.SetupBodyPart(leg3Upper); |
|||
m_JdController.SetupBodyPart(leg3Lower); |
|||
} |
|||
var velocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(rb.velocity); |
|||
sensor.AddObservation(velocityRelativeToLookRotationToTarget); |
|||
|
|||
var angularVelocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(rb.angularVelocity); |
|||
sensor.AddObservation(angularVelocityRelativeToLookRotationToTarget); |
|||
|
|||
if (bp.rb.transform != body) |
|||
/// <summary>
|
|||
/// We only need to change the joint settings based on decision freq.
|
|||
/// </summary>
|
|||
public void IncrementDecisionTimer() |
|||
var localPosRelToBody = body.InverseTransformPoint(rb.position); |
|||
sensor.AddObservation(localPosRelToBody); |
|||
sensor.AddObservation(bp.currentXNormalizedRot); // Current x rot
|
|||
sensor.AddObservation(bp.currentYNormalizedRot); // Current y rot
|
|||
sensor.AddObservation(bp.currentZNormalizedRot); // Current z rot
|
|||
sensor.AddObservation(bp.currentStrength / m_JdController.maxJointForceLimit); |
|||
// TODO Decision Requester
|
|||
// if (m_CurrentDecisionStep == agentParameters.numberOfActionsBetweenDecisions
|
|||
// || agentParameters.numberOfActionsBetweenDecisions == 1)
|
|||
// {
|
|||
// m_CurrentDecisionStep = 1;
|
|||
// m_IsNewDecisionStep = true;
|
|||
// }
|
|||
// else
|
|||
// {
|
|||
// m_CurrentDecisionStep++;
|
|||
// m_IsNewDecisionStep = false;
|
|||
// }
|
|||
} |
|||
public override void CollectObservations(VectorSensor sensor) |
|||
{ |
|||
m_JdController.GetCurrentJointForces(); |
|||
|
|||
// Update pos to target
|
|||
m_DirToTarget = target.position - body.position; |
|||
m_LookRotation = Quaternion.LookRotation(m_DirToTarget); |
|||
m_TargetDirMatrix = Matrix4x4.TRS(Vector3.zero, m_LookRotation, Vector3.one); |
|||
|
|||
RaycastHit hit; |
|||
if (Physics.Raycast(body.position, Vector3.down, out hit, 10.0f)) |
|||
/// <summary>
|
|||
/// Add relevant information on each body part to observations.
|
|||
/// </summary>
|
|||
public void CollectObservationBodyPart(VectorSensor vectorSensor, BodyPart bp) |
|||
sensor.AddObservation(hit.distance); |
|||
} |
|||
else |
|||
sensor.AddObservation(10.0f); |
|||
var rb = bp.rb; |
|||
vectorSensor.AddObservation(bp.groundContact.touchingGround ? 1 : 0); // Whether the bp touching the ground
|
|||
// Forward & up to help with orientation
|
|||
var bodyForwardRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(body.forward); |
|||
sensor.AddObservation(bodyForwardRelativeToLookRotationToTarget); |
|||
var velocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(rb.velocity); |
|||
vectorSensor.AddObservation(velocityRelativeToLookRotationToTarget); |
|||
var bodyUpRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(body.up); |
|||
sensor.AddObservation(bodyUpRelativeToLookRotationToTarget); |
|||
var angularVelocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(rb.angularVelocity); |
|||
vectorSensor.AddObservation(angularVelocityRelativeToLookRotationToTarget); |
|||
foreach (var bodyPart in m_JdController.bodyPartsDict.Values) |
|||
{ |
|||
CollectObservationBodyPart(bodyPart, sensor); |
|||
if (bp.rb.transform != body) |
|||
{ |
|||
var localPosRelToBody = body.InverseTransformPoint(rb.position); |
|||
vectorSensor.AddObservation(localPosRelToBody); |
|||
vectorSensor.AddObservation(bp.currentXNormalizedRot); // Current x rot
|
|||
vectorSensor.AddObservation(bp.currentYNormalizedRot); // Current y rot
|
|||
vectorSensor.AddObservation(bp.currentZNormalizedRot); // Current z rot
|
|||
vectorSensor.AddObservation(bp.currentStrength / m_JdController.maxJointForceLimit); |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// Agent touched the target
|
|||
/// </summary>
|
|||
public void TouchedTarget() |
|||
{ |
|||
AddReward(1f); |
|||
if (respawnTargetWhenTouched) |
|||
public override void CollectObservations(VectorSensor vectorSensor) |
|||
GetRandomTargetPos(); |
|||
} |
|||
} |
|||
m_JdController.GetCurrentJointForces(); |
|||
/// <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; |
|||
} |
|||
// Update pos to target
|
|||
m_DirToTarget = target.position - body.position; |
|||
m_LookRotation = Quaternion.LookRotation(m_DirToTarget); |
|||
m_TargetDirMatrix = Matrix4x4.TRS(Vector3.zero, m_LookRotation, Vector3.one); |
|||
public override void OnActionReceived(float[] vectorAction) |
|||
{ |
|||
// The dictionary with all the body parts in it are in the jdController
|
|||
var bpDict = m_JdController.bodyPartsDict; |
|||
RaycastHit hit; |
|||
if (Physics.Raycast(body.position, Vector3.down, out hit, 10.0f)) |
|||
{ |
|||
vectorSensor.AddObservation(hit.distance); |
|||
} |
|||
else |
|||
vectorSensor.AddObservation(10.0f); |
|||
var i = -1; |
|||
// Pick a new target joint rotation
|
|||
bpDict[leg0Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[leg1Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[leg2Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[leg3Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[leg0Lower].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[leg1Lower].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[leg2Lower].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[leg3Lower].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
// Forward & up to help with orientation
|
|||
var bodyForwardRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(body.forward); |
|||
vectorSensor.AddObservation(bodyForwardRelativeToLookRotationToTarget); |
|||
// Update joint strength
|
|||
bpDict[leg0Upper].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg1Upper].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg2Upper].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg3Upper].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg0Lower].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg1Lower].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg2Lower].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg3Lower].SetJointStrength(vectorAction[++i]); |
|||
} |
|||
var bodyUpRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(body.up); |
|||
vectorSensor.AddObservation(bodyUpRelativeToLookRotationToTarget); |
|||
void FixedUpdate() |
|||
{ |
|||
if (detectTargets) |
|||
{ |
|||
if (bodyPart.targetContact && bodyPart.targetContact.touchingTarget) |
|||
{ |
|||
TouchedTarget(); |
|||
} |
|||
CollectObservationBodyPart(vectorSensor, bodyPart); |
|||
// If enabled the feet will light up green when the foot is grounded.
|
|||
// This is just a visualization and isn't necessary for function
|
|||
if (useFootGroundedVisualization) |
|||
/// <summary>
|
|||
/// Agent touched the target
|
|||
/// </summary>
|
|||
public void TouchedTarget() |
|||
foot0.material = m_JdController.bodyPartsDict[leg0Lower].groundContact.touchingGround |
|||
? groundedMaterial |
|||
: unGroundedMaterial; |
|||
foot1.material = m_JdController.bodyPartsDict[leg1Lower].groundContact.touchingGround |
|||
? groundedMaterial |
|||
: unGroundedMaterial; |
|||
foot2.material = m_JdController.bodyPartsDict[leg2Lower].groundContact.touchingGround |
|||
? groundedMaterial |
|||
: unGroundedMaterial; |
|||
foot3.material = m_JdController.bodyPartsDict[leg3Lower].groundContact.touchingGround |
|||
? groundedMaterial |
|||
: unGroundedMaterial; |
|||
AddReward(1f); |
|||
if (respawnTargetWhenTouched) |
|||
{ |
|||
GetRandomTargetPos(); |
|||
} |
|||
// Set reward for this step according to mixture of the following elements.
|
|||
if (rewardMovingTowardsTarget) |
|||
/// <summary>
|
|||
/// Moves target to a random position within specified radius.
|
|||
/// </summary>
|
|||
public void GetRandomTargetPos() |
|||
RewardFunctionMovingTowards(); |
|||
var newTargetPos = Random.insideUnitSphere * targetSpawnRadius; |
|||
newTargetPos.y = 5; |
|||
target.position = newTargetPos + ground.position; |
|||
if (rewardFacingTarget) |
|||
public override void OnActionReceived(float[] vectorAction) |
|||
RewardFunctionFacingTarget(); |
|||
} |
|||
if (detectTargets) |
|||
{ |
|||
foreach (var bodyPart in m_JdController.bodyPartsDict.Values) |
|||
{ |
|||
if (bodyPart.targetContact |
|||
// && !IsDone() - TODO copied from old code
|
|||
&& bodyPart.targetContact.touchingTarget) |
|||
{ |
|||
TouchedTarget(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// If enabled the feet will light up green when the foot is grounded.
|
|||
// This is just a visualization and isn't necessary for function
|
|||
if (useFootGroundedVisualization) |
|||
{ |
|||
foot0.material = m_JdController.bodyPartsDict[leg0Lower].groundContact.touchingGround |
|||
? groundedMaterial |
|||
: unGroundedMaterial; |
|||
foot1.material = m_JdController.bodyPartsDict[leg1Lower].groundContact.touchingGround |
|||
? groundedMaterial |
|||
: unGroundedMaterial; |
|||
foot2.material = m_JdController.bodyPartsDict[leg2Lower].groundContact.touchingGround |
|||
? groundedMaterial |
|||
: unGroundedMaterial; |
|||
foot3.material = m_JdController.bodyPartsDict[leg3Lower].groundContact.touchingGround |
|||
? groundedMaterial |
|||
: unGroundedMaterial; |
|||
} |
|||
|
|||
// Joint update logic only needs to happen when a new decision is made
|
|||
if (m_IsNewDecisionStep) |
|||
{ |
|||
// The dictionary with all the body parts in it are in the jdController
|
|||
var bpDict = m_JdController.bodyPartsDict; |
|||
|
|||
var i = -1; |
|||
|
|||
// Pick a new target joint rotation
|
|||
bpDict[leg0Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[leg1Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[leg2Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[leg3Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[leg0Lower].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[leg1Lower].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[leg2Lower].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[leg3Lower].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
if (rewardUseTimePenalty) |
|||
{ |
|||
RewardFunctionTimePenalty(); |
|||
} |
|||
} |
|||
// Update joint strength
|
|||
bpDict[leg0Upper].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg1Upper].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg2Upper].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg3Upper].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg0Lower].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg1Lower].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg2Lower].SetJointStrength(vectorAction[++i]); |
|||
bpDict[leg3Lower].SetJointStrength(vectorAction[++i]); |
|||
} |
|||
/// <summary>
|
|||
/// Reward moving towards target & Penalize moving away from target.
|
|||
/// </summary>
|
|||
void RewardFunctionMovingTowards() |
|||
{ |
|||
m_MovingTowardsDot = Vector3.Dot(m_JdController.bodyPartsDict[body].rb.velocity, m_DirToTarget.normalized); |
|||
AddReward(0.03f * m_MovingTowardsDot); |
|||
} |
|||
// Set reward for this step according to mixture of the following elements.
|
|||
if (rewardMovingTowardsTarget) |
|||
{ |
|||
RewardFunctionMovingTowards(); |
|||
} |
|||
/// <summary>
|
|||
/// Reward facing target & Penalize facing away from target
|
|||
/// </summary>
|
|||
void RewardFunctionFacingTarget() |
|||
{ |
|||
m_FacingDot = Vector3.Dot(m_DirToTarget.normalized, body.forward); |
|||
AddReward(0.01f * m_FacingDot); |
|||
} |
|||
if (rewardFacingTarget) |
|||
{ |
|||
RewardFunctionFacingTarget(); |
|||
} |
|||
/// <summary>
|
|||
/// Existential penalty for time-contrained tasks.
|
|||
/// </summary>
|
|||
void RewardFunctionTimePenalty() |
|||
{ |
|||
AddReward(-0.001f); |
|||
} |
|||
if (rewardUseTimePenalty) |
|||
{ |
|||
RewardFunctionTimePenalty(); |
|||
} |
|||
/// <summary>
|
|||
/// Loop over body parts and reset them to initial conditions.
|
|||
/// </summary>
|
|||
public override void OnEpisodeBegin() |
|||
{ |
|||
if (m_DirToTarget != Vector3.zero) |
|||
IncrementDecisionTimer(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Reward moving towards target & Penalize moving away from target.
|
|||
/// </summary>
|
|||
void RewardFunctionMovingTowards() |
|||
transform.rotation = Quaternion.LookRotation(m_DirToTarget); |
|||
m_MovingTowardsDot = Vector3.Dot(m_JdController.bodyPartsDict[body].rb.velocity, m_DirToTarget.normalized); |
|||
AddReward(0.03f * m_MovingTowardsDot); |
|||
transform.Rotate(Vector3.up, Random.Range(0.0f, 360.0f)); |
|||
foreach (var bodyPart in m_JdController.bodyPartsDict.Values) |
|||
/// <summary>
|
|||
/// Reward facing target & Penalize facing away from target
|
|||
/// </summary>
|
|||
void RewardFunctionFacingTarget() |
|||
bodyPart.Reset(bodyPart); |
|||
m_FacingDot = Vector3.Dot(m_DirToTarget.normalized, body.forward); |
|||
AddReward(0.01f * m_FacingDot); |
|||
if (!targetIsStatic) |
|||
|
|||
/// <summary>
|
|||
/// Existential penalty for time-contrained tasks.
|
|||
/// </summary>
|
|||
void RewardFunctionTimePenalty() |
|||
GetRandomTargetPos(); |
|||
AddReward(-0.001f); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loop over body parts and reset them to initial conditions.
|
|||
/// </summary>
|
|||
public override void OnEpisodeBegin() |
|||
{ |
|||
if (m_DirToTarget != Vector3.zero) |
|||
{ |
|||
transform.rotation = Quaternion.LookRotation(m_DirToTarget); |
|||
} |
|||
|
|||
transform.Rotate(Vector3.up, Random.Range(0.0f, 360.0f)); |
|||
|
|||
foreach (var bodyPart in m_JdController.bodyPartsDict.Values) |
|||
{ |
|||
bodyPart.Reset(bodyPart); |
|||
} |
|||
|
|||
if (!targetIsStatic) |
|||
{ |
|||
GetRandomTargetPos(); |
|||
} |
|||
|
|||
m_IsNewDecisionStep = true; |
|||
m_CurrentDecisionStep = 1; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 95285c32be79a4c77a5ac225e671e4b5 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/FoodCollector/Demos/ExpertFood.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/FoodCollector/Demos/ExpertFood.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0092f2e4aece345aea4730a37eeebf68 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/GridWorld/Demos/ExpertGrid.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/GridWorld/Demos/ExpertGrid.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 41c6af18564fe425fa1c047d603ee34e |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/Hallway/Demos/ExpertHallway.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/Hallway/Demos/ExpertHallway.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7f11f35191533404c9957443a681aaee |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/PushBlock/Demos/ExpertPush.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/PushBlock/Demos/ExpertPush.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 2f9d53c90f11846d7a6499ce0f1dfebb |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/Pyramids/Demos/ExpertPyramid.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/Pyramids/Demos/ExpertPyramid.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 4f14b17d2835e482097c88301323e587 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/Reacher/Demos/ExpertReacher.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/Reacher/Demos/ExpertReacher.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
937
Project/Assets/ML-Agents/Examples/Reacher/Prefabs/Agent.prefab
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using UnityEngine; |
|||
|
|||
public class ReacherGoal : MonoBehaviour |
|||
namespace Unity.MLAgentsExamples |
|||
public GameObject agent; |
|||
public GameObject hand; |
|||
public GameObject goalOn; |
|||
public class ReacherGoal : MonoBehaviour |
|||
{ |
|||
public GameObject agent; |
|||
public GameObject hand; |
|||
public GameObject goalOn; |
|||
void OnTriggerEnter(Collider other) |
|||
{ |
|||
if (other.gameObject == hand) |
|||
private void OnTriggerEnter(Collider other) |
|||
goalOn.transform.localScale = new Vector3(1f, 1f, 1f); |
|||
if (other.gameObject == hand) |
|||
{ |
|||
goalOn.transform.localScale = new Vector3(1f, 1f, 1f); |
|||
} |
|||
} |
|||
void OnTriggerExit(Collider other) |
|||
{ |
|||
if (other.gameObject == hand) |
|||
private void OnTriggerExit(Collider other) |
|||
goalOn.transform.localScale = new Vector3(0f, 0f, 0f); |
|||
if (other.gameObject == hand) |
|||
{ |
|||
goalOn.transform.localScale = new Vector3(0f, 0f, 0f); |
|||
} |
|||
} |
|||
void OnTriggerStay(Collider other) |
|||
{ |
|||
if (other.gameObject == hand) |
|||
private void OnTriggerStay(Collider other) |
|||
agent.GetComponent<ReacherAgent>().AddReward(0.01f); |
|||
if (other.gameObject == hand) |
|||
{ |
|||
agent.GetComponent<ReacherAgent>().AddReward(0.01f); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9676a67fc4a8d420aab12eb513a845a8 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/Tennis/Demos/ExpertTennis.demo |
|||
internalIDToNameTable: |
|||
- first: |
|||
114: 11400000 |
|||
second: Assets/ML-Agents/Examples/Tennis/Demos/ExpertTennis.demo |
|||
serializedVersion: 2 |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |