Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ BoxCollider:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1500989011945850}
m_Material: {fileID: 0}
m_Material: {fileID: 13400000, guid: f440cd475293044139739aff331224fb, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
Expand Down Expand Up @@ -905,6 +905,7 @@ MonoBehaviour:
brain: {fileID: 11400000, guid: e8b2d719f6a324b1abb68d8cf2859f5c, type: 2}
agentParameters:
agentCameras: []
agentRenderTextures: []
maxStep: 5000
resetOnDone: 1
onDemandDecision: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ BoxCollider:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1132847330634378}
m_Material: {fileID: 0}
m_Material: {fileID: 13400000, guid: f440cd475293044139739aff331224fb, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
Expand Down Expand Up @@ -905,6 +905,7 @@ MonoBehaviour:
brain: {fileID: 11400000, guid: e8b2d719f6a324b1abb68d8cf2859f5c, type: 2}
agentParameters:
agentCameras: []
agentRenderTextures: []
maxStep: 5000
resetOnDone: 1
onDemandDecision: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ BoxCollider:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1492788814869846}
m_Material: {fileID: 0}
m_Material: {fileID: 13400000, guid: f440cd475293044139739aff331224fb, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
Expand Down Expand Up @@ -919,6 +919,7 @@ MonoBehaviour:
brain: {fileID: 11400000, guid: dd07b1953eac4411b81fba032f394726, type: 2}
agentParameters:
agentCameras: []
agentRenderTextures: []
maxStep: 5000
resetOnDone: 1
onDemandDecision: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ BoxCollider:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1553741088268304}
m_Material: {fileID: 0}
m_Material: {fileID: 13400000, guid: f440cd475293044139739aff331224fb, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
Expand Down Expand Up @@ -970,6 +970,7 @@ MonoBehaviour:
agentParameters:
agentCameras:
- {fileID: 20223756300728806}
agentRenderTextures: []
maxStep: 5000
resetOnDone: 1
onDemandDecision: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,15 @@ MonoBehaviour:
timeScale: 1
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: dynamic_friction
value: 0
- key: static_friction
value: 0
- key: block_drag
value: 0.5
- key: block_scale
value: 2
agentRunSpeed: 2
agentRotationSpeed: 15
spawnAreaMarginMultiplier: 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ Prefab:
propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
- target: {fileID: 65880592586321730, guid: bed6005cc2a1a47edafba27cde6b5538,
type: 2}
propertyPath: m_Material
value:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: bed6005cc2a1a47edafba27cde6b5538, type: 2}
m_IsPrefabParent: 0
Expand Down Expand Up @@ -552,7 +557,15 @@ MonoBehaviour:
timeScale: 1
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: dynamic_friction
value: 0
- key: static_friction
value: 0
- key: block_drag
value: 0.5
- key: block_scale
value: 2
agentRunSpeed: 2
agentRotationSpeed: 15
spawnAreaMarginMultiplier: 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,15 @@ MonoBehaviour:
timeScale: 1
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: dynamic_friction
value: 0
- key: static_friction
value: 0
- key: block_drag
value: 0.5
- key: block_scale
value: 2
agentRunSpeed: 2
agentRotationSpeed: 15
spawnAreaMarginMultiplier: 0.5
Expand Down
31 changes: 31 additions & 0 deletions UnitySDK/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public override void InitializeAgent()
groundRenderer = ground.GetComponent<Renderer>();
// Starting material
groundMaterial = groundRenderer.material;

SetResetParameters();
}

public override void CollectObservations()
Expand Down Expand Up @@ -217,5 +219,34 @@ public override void AgentReset()
transform.position = GetRandomSpawnPos();
agentRB.velocity = Vector3.zero;
agentRB.angularVelocity = Vector3.zero;

SetResetParameters();
}

public void SetGroundMaterialFriction()
{
var resetParams = academy.resetParameters;

var groundCollider = ground.GetComponent<Collider>() as Collider;

groundCollider.material.dynamicFriction = resetParams["dynamic_friction"];
groundCollider.material.staticFriction = resetParams["static_friction"];
}

public void SetBlockProperties()
{
var resetParams = academy.resetParameters;

//Set the scale of the block
blockRB.transform.localScale = new Vector3(resetParams["block_scale"], 0.75f, resetParams["block_scale"]);

// Set the drag of the block
blockRB.drag = resetParams["block_drag"];
}

public void SetResetParameters()
{
SetGroundMaterialFriction();
SetBlockProperties();
}
}
10 changes: 7 additions & 3 deletions UnitySDK/Assets/ML-Agents/Examples/Reacher/Scenes/Reacher.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 762086411}
m_IndirectSpecularColor: {r: 0.4465934, g: 0.49642956, b: 0.5748249, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.49641287, b: 0.5748173, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1122,8 +1122,12 @@ MonoBehaviour:
value: 5
- key: goal_speed
value: 1
goalSize: 5
goalSpeed: 1
- key: gravity
value: 9.81
- key: deviation
value: 0
- key: deviation_freq
value: 0
--- !u!4 &1574236049
Transform:
m_ObjectHideFlags: 0
Expand Down
9 changes: 3 additions & 6 deletions UnitySDK/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAcademy.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
using UnityEngine;
using MLAgents;

public class ReacherAcademy : Academy {

public float goalSize;
public float goalSpeed;
public class ReacherAcademy : Academy
{


public override void AcademyReset()
{
goalSize = (float)resetParameters["goal_size"];
goalSpeed = (float)resetParameters["goal_speed"];
Physics.gravity = new Vector3(0, -resetParameters["gravity"], 0);
}

public override void AcademyStep()
Expand Down
40 changes: 30 additions & 10 deletions UnitySDK/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAgent.cs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using UnityEngine;
using MLAgents;

public class ReacherAgent : Agent {
public class ReacherAgent : Agent
{

public GameObject pendulumA;
public GameObject pendulumB;
Expand All @@ -11,18 +12,26 @@ public class ReacherAgent : Agent {
float goalDegree;
private Rigidbody rbA;
private Rigidbody rbB;
// speed of the goal zone around the arm (in radians)
private float goalSpeed;
// radius of the goal zone
private float goalSize;
// Magnitude of sinusoidal (cosine) deviation of the goal along the vertical dimension
private float deviation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment here and there to define what those parameters do

// Frequency of the cosine deviation of the goal along the vertical dimension
private float deviationFreq;

/// <summary>
/// Collect the rigidbodies of the reacher in order to resue them for
/// Collect the rigidbodies of the reacher in order to resue them for
/// observations and actions.
/// </summary>
public override void InitializeAgent()
{
rbA = pendulumA.GetComponent<Rigidbody>();
rbB = pendulumB.GetComponent<Rigidbody>();
myAcademy = GameObject.Find("Academy").GetComponent<ReacherAcademy>();

SetResetParameters();
}

/// <summary>
Expand All @@ -43,15 +52,15 @@ public override void CollectObservations()

AddVectorObs(goal.transform.localPosition);
AddVectorObs(hand.transform.localPosition);

AddVectorObs(goalSpeed);
}
}

/// <summary>
/// The agent's four actions correspond to torques on each of the two joints.
/// </summary>
public override void AgentAction(float[] vectorAction, string textAction)
{
{
goalDegree += goalSpeed;
UpdateGoalPosition();

Expand All @@ -62,17 +71,18 @@ public override void AgentAction(float[] vectorAction, string textAction)
torqueX = Mathf.Clamp(vectorAction[2], -1f, 1f) * 150f;
torqueZ = Mathf.Clamp(vectorAction[3], -1f, 1f) * 150f;
rbB.AddTorque(new Vector3(torqueX, 0f, torqueZ));
}
}

/// <summary>
/// Used to move the position of the target goal around the agent.
/// </summary>
void UpdateGoalPosition()
void UpdateGoalPosition()
{
var radians = goalDegree * Mathf.PI / 180f;
var goalX = 8f * Mathf.Cos(radians);
var goalY = 8f * Mathf.Sin(radians);
goal.transform.position = new Vector3(goalY, -1f, goalX) + transform.position;
var goalZ = deviation * Mathf.Cos(deviationFreq * radians);
goal.transform.position = new Vector3(goalY, goalZ, goalX) + transform.position;
}

/// <summary>
Expand All @@ -93,9 +103,19 @@ public override void AgentReset()
goalDegree = Random.Range(0, 360);
UpdateGoalPosition();

goalSize = myAcademy.goalSize;
goalSpeed = Random.Range(-1f, 1f) * myAcademy.goalSpeed;
SetResetParameters();


goal.transform.localScale = new Vector3(goalSize, goalSize, goalSize);
}


public void SetResetParameters()
{
goalSize = myAcademy.resetParameters["goal_size"];
goalSpeed = Random.Range(-1f, 1f) * myAcademy.resetParameters["goal_speed"];
deviation = myAcademy.resetParameters["deviation"];
deviationFreq = myAcademy.resetParameters["deviation_freq"];

}
}
10 changes: 9 additions & 1 deletion UnitySDK/Assets/ML-Agents/Examples/Walker/Scenes/Walker.unity
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,15 @@ MonoBehaviour:
timeScale: 1
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: gravity
value: 9.81
- key: hip_mass
value: 15
- key: chest_mass
value: 8
- key: spine_mass
value: 10
--- !u!4 &1409355322
Transform:
m_ObjectHideFlags: 0
Expand Down
1 change: 1 addition & 0 deletions UnitySDK/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAcademy.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public override void InitializeAcademy()

public override void AcademyReset()
{
Physics.gravity = new Vector3(0, -resetParameters["gravity"], 0);
}

public override void AcademyStep()
Expand Down
28 changes: 28 additions & 0 deletions UnitySDK/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class WalkerAgent : Agent
bool isNewDecisionStep;
int currentDecisionStep;

private Rigidbody hipsRb;
private Rigidbody chestRb;
private Rigidbody spineRb;

private ResetParameters resetParams;

public override void InitializeAgent()
{
jdController = GetComponent<JointDriveController>();
Expand All @@ -48,6 +54,15 @@ public override void InitializeAgent()
jdController.SetupBodyPart(armR);
jdController.SetupBodyPart(forearmR);
jdController.SetupBodyPart(handR);

hipsRb = hips.GetComponent<Rigidbody>();
chestRb = chest.GetComponent<Rigidbody>();
spineRb = spine.GetComponent<Rigidbody>();

var academy = FindObjectOfType<WalkerAcademy>() as WalkerAcademy;
resetParams = academy.resetParameters;

SetResetParameters();
}

/// <summary>
Expand Down Expand Up @@ -184,5 +199,18 @@ public override void AgentReset()

isNewDecisionStep = true;
currentDecisionStep = 1;
SetResetParameters();
}

public void SetTorsoMass()
{
chestRb.mass = resetParams["chest_mass"];
spineRb.mass = resetParams["spine_mass"];
hipsRb.mass = resetParams["hip_mass"];
}

public void SetResetParameters()
{
SetTorsoMass();
}
}
Loading