浏览代码

update crawler rewards and gravity

/develop/bisim-review
Andrew Cohen 4 年前
当前提交
b2efa00b
共有 5 个文件被更改,包括 46 次插入22 次删除
  1. 55
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
  2. 5
      Project/Assets/ML-Agents/Examples/OldCrawler/Prefabs/OldCrawler.prefab
  3. 5
      Project/Assets/ML-Agents/Examples/OldCrawler/Prefabs/OldFixedPlatform.prefab
  4. 2
      Project/Assets/ML-Agents/Examples/OldCrawler/Scenes/OldCrawlerStaticTarget.unity
  5. 1
      Project/Assets/ML-Agents/Examples/OldCrawler/Scripts/OldCrawlerAgent.cs

55
Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs


public Material groundedMaterial;
public Material unGroundedMaterial;
Vector3 m_DirToTarget;
m_DirToTarget = target.transform.position - body.position;
m_JdController = GetComponent<JointDriveController>();
//Setup each body part

{
bodyPart.Reset(bodyPart);
}
if (m_DirToTarget != Vector3.zero)
{
transform.rotation = Quaternion.LookRotation(m_DirToTarget);
}
transform.Rotate(Vector3.up, Random.Range(0.0f, 360.0f));
transform.rotation = Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0);
// transform.rotation = Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0);
orientationCube.UpdateOrientation(body, target.transform);
}

/// </summary>
public void CollectObservationBodyPart(BodyPart bp, VectorSensor sensor)
{
m_DirToTarget = target.transform.position - body.position;
//GROUND CHECK
sensor.AddObservation(bp.groundContact.touchingGround); // Is this bp touching the ground

/// </summary>
void RewardFunctionMovingTowards()
{
var movingTowardsDot = Vector3.Dot(orientationCube.transform.forward,
Vector3.ClampMagnitude(m_JdController.bodyPartsDict[body].rb.velocity, maximumWalkingSpeed));
if (float.IsNaN(movingTowardsDot))
{
throw new ArgumentException(
"NaN in movingTowardsDot.\n" +
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
$" body.velocity: {m_JdController.bodyPartsDict[body].rb.velocity}\n"+
$" maximumWalkingSpeed: {maximumWalkingSpeed}"
);
}
//var movingTowardsDot = Vector3.Dot(orientationCube.transform.forward,
// Vector3.ClampMagnitude(m_JdController.bodyPartsDict[body].rb.velocity, maximumWalkingSpeed));
//if (float.IsNaN(movingTowardsDot))
//{
// throw new ArgumentException(
// "NaN in movingTowardsDot.\n" +
// $" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
// $" body.velocity: {m_JdController.bodyPartsDict[body].rb.velocity}\n"+
// $" maximumWalkingSpeed: {maximumWalkingSpeed}"
// );
//}
var movingTowardsDot = Vector3.Dot(m_JdController.bodyPartsDict[body].rb.velocity, m_DirToTarget.normalized);
AddReward(0.03f * movingTowardsDot);
}

void RewardFunctionFacingTarget()
{
var facingReward = Vector3.Dot(orientationCube.transform.forward, body.forward);
if (float.IsNaN(facingReward))
{
throw new ArgumentException(
"NaN in movingTowardsDot.\n" +
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
$" body.forward: {body.forward}"
);
}
//var facingReward = Vector3.Dot(orientationCube.transform.forward, body.forward);
//if (float.IsNaN(facingReward))
//{
// throw new ArgumentException(
// "NaN in movingTowardsDot.\n" +
// $" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
// $" body.forward: {body.forward}"
// );
//}
var facingReward = Vector3.Dot(m_DirToTarget.normalized, body.forward);
AddReward(0.01f * facingReward);
}

5
Project/Assets/ML-Agents/Examples/OldCrawler/Prefabs/OldCrawler.prefab


propertyPath: m_Name
value: OldCrawler
objectReference: {fileID: 0}
- target: {fileID: 6234525248087620104, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 4845971001715176649, guid: 0456c89e8c9c243d595b039fe7aa0bf9, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 0456c89e8c9c243d595b039fe7aa0bf9, type: 3}

5
Project/Assets/ML-Agents/Examples/OldCrawler/Prefabs/OldFixedPlatform.prefab


propertyPath: m_Name
value: OldCrawler
objectReference: {fileID: 0}
- target: {fileID: 6208443033207927858, guid: e24df050e78384b24b065a2b14effd14,
type: 3}
propertyPath: targetToLookAt
value:
objectReference: {fileID: 4749909135913778}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: e24df050e78384b24b065a2b14effd14, type: 3}
--- !u!4 &4245501741859669185 stripped

2
Project/Assets/ML-Agents/Examples/OldCrawler/Scenes/OldCrawlerStaticTarget.unity


m_Script: {fileID: 11500000, guid: ec51f47c5ed0478080c449c74fd9c154, type: 3}
m_Name:
m_EditorClassIdentifier:
gravityMultiplier: 1
gravityMultiplier: 1.5
fixedDeltaTime: 0.01333
maximumDeltaTime: 0.15
solverIterations: 12

1
Project/Assets/ML-Agents/Examples/OldCrawler/Scripts/OldCrawlerAgent.cs


{
[Header("Target To Walk Towards")]
[Space(10)]
public float maximumWalkingSpeed = 999; //The max walk velocity magnitude an agent will be rewarded for
public Transform target;
public Transform ground;

正在加载...
取消
保存