浏览代码

more cleanup

/active-variablespeed
HH 4 年前
当前提交
510c146e
共有 3 个文件被更改,包括 17 次插入9 次删除
  1. 4
      Project/Assets/ML-Agents/Examples/Walker/Prefabs/Ragdoll/WalkerRagdollStSingleSpeedVariant.prefab
  2. 4
      Project/Assets/ML-Agents/Examples/Walker/Prefabs/Ragdoll/WalkerRagdollStVariableSpeedVariant.prefab
  3. 18
      Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs

4
Project/Assets/ML-Agents/Examples/Walker/Prefabs/Ragdoll/WalkerRagdollStSingleSpeedVariant.prefab


propertyPath: updateViaScript
value: 1
objectReference: {fileID: 0}
- target: {fileID: 693499830, guid: 765582efd9dda46ed98564603316353f, type: 3}
propertyPath: updatedByAgent
value: 1
objectReference: {fileID: 0}
- target: {fileID: 895268871377934275, guid: 765582efd9dda46ed98564603316353f,
type: 3}
propertyPath: m_Name

4
Project/Assets/ML-Agents/Examples/Walker/Prefabs/Ragdoll/WalkerRagdollStVariableSpeedVariant.prefab


propertyPath: updateViaScript
value: 1
objectReference: {fileID: 0}
- target: {fileID: 693499830, guid: 765582efd9dda46ed98564603316353f, type: 3}
propertyPath: updatedByAgent
value: 1
objectReference: {fileID: 0}
- target: {fileID: 895268871377934275, guid: 765582efd9dda46ed98564603316353f,
type: 3}
propertyPath: m_Name

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


public class WalkerAgent : Agent
{
[Header("Walk Speed")] [Range(0, 10)] public float walkingSpeed = 10; //The walking speed to try and achieve
float m_maxWalkingSpeed = 10; //The max walking speed
[Header("Walk Speed")] [Range(0.1f, 10)] public float targetWalkingSpeed = 10; //The walking speed to try and achieve
const float m_maxWalkingSpeed = 10; //The max walking speed
//Should the agent sample a new goal velocity each episode?
//If true, walkSpeed will be randomly set between zero and m_maxWalkingSpeed in OnEpisodeBegin()

}
//Set our goal walking speed
walkingSpeed =
randomizeWalkSpeedEachEpisode ? Random.Range(0.0f, m_maxWalkingSpeed) : walkingSpeed;
targetWalkingSpeed =
randomizeWalkSpeedEachEpisode ? Random.Range(0.1f, m_maxWalkingSpeed) : targetWalkingSpeed;
SetResetParameters();
}

var cubeForward = m_OrientationCube.transform.forward;
//current ragdoll velocity. normalized
sensor.AddObservation(GetMatchingVelocityInverseLerp(cubeForward * walkingSpeed, GetAvgVelocity()));
sensor.AddObservation(GetMatchingVelocityInverseLerp(cubeForward * targetWalkingSpeed, GetAvgVelocity()));
sensor.AddObservation(walkingSpeed / m_maxWalkingSpeed);
sensor.AddObservation(targetWalkingSpeed / m_maxWalkingSpeed);
//rotation deltas
sensor.AddObservation(Quaternion.FromToRotation(hips.forward, cubeForward));

// Set reward for this step according to mixture of the following elements.
// a. Match target speed
//This reward will approach 1 if it matches perfectly and approach zero as it deviates
var matchSpeedReward = GetMatchingVelocityInverseLerp(cubeForward * walkingSpeed, GetAvgVelocity());
var matchSpeedReward = GetMatchingVelocityInverseLerp(cubeForward * targetWalkingSpeed, GetAvgVelocity());
//Check for NaNs
if (float.IsNaN(matchSpeedReward))

public float GetMatchingVelocityInverseLerp(Vector3 velocityGoal, Vector3 actualVelocity)
{
//distance between our actual velocity and goal velocity
var velDeltaMagnitude = Mathf.Clamp(Vector3.Distance(actualVelocity, velocityGoal), 0, walkingSpeed);
var velDeltaMagnitude = Mathf.Clamp(Vector3.Distance(actualVelocity, velocityGoal), 0, targetWalkingSpeed);
return Mathf.Pow(1 - Mathf.Pow(velDeltaMagnitude / walkingSpeed, 2), 2);
return Mathf.Pow(1 - Mathf.Pow(velDeltaMagnitude / targetWalkingSpeed, 2), 2);
}
/// <summary>

正在加载...
取消
保存