Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cog/striker #111

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9911ce2
Added first tools for curiculum learning
TheImus Jan 5, 2022
79b1f72
Merge branch 'master' into feature/Curriculum
Kabumba Jan 5, 2022
329e5d2
lessons und difficulties definiert
Kabumba Jan 5, 2022
438d798
updated speed of ball in goalkeeper scenario
TheImus Jan 9, 2022
9fc37b4
Update build.yml
TheImus Jan 9, 2022
7a92f14
Update build.yml
TheImus Jan 9, 2022
25c8716
Merge branch 'master' into feature/Curriculum
Kabumba Jan 28, 2022
562f665
random Speed difficulty angepasst
Kabumba Jan 28, 2022
a1cbf39
update reward
TheImus Feb 1, 2022
b38eafe
Sichereres environment getten
Kabumba Feb 7, 2022
b00a025
Time in frames statt in seconds
Kabumba Feb 7, 2022
cfabc3c
Merge branch 'feature/environment' into feature/Curriculum
Kabumba Feb 7, 2022
1fddbdf
s
Kabumba Feb 7, 2022
d756cb9
Merge branch 'master' into feature/Curriculum
Kabumba Feb 7, 2022
0d7a459
Checks und Normalize verallgemeinert
Kabumba Feb 7, 2022
741de29
GoalkeeperAgent an PGAngent angepasst
Kabumba Feb 7, 2022
2f46b76
shootball applies the velocity directly now and doesn't call ShootTar…
MarcoMeter Feb 17, 2022
67d5877
added relative position to the observation space
MarcoMeter Feb 17, 2022
109ff02
++
MarcoMeter Feb 17, 2022
77a84c3
(WIP) added the goalie reset parameters to the striker agent
MarcoMeter Feb 17, 2022
e495a7d
fixed seed is working now
MarcoMeter Feb 17, 2022
f201834
removed rewards except the goal scored one, difficulty is set to 2
MarcoMeter Feb 17, 2022
b7dded8
set difficulty to 3
MarcoMeter Feb 18, 2022
cfca777
max steps terminates the episode automatically, adjusted difficulty 3
MarcoMeter Feb 18, 2022
0d7227f
fixed boostAmount and its reset parameter, reduced max steps, work on…
MarcoMeter Feb 19, 2022
501e6d4
++
MarcoMeter Feb 19, 2022
578dfae
difficulty 2 and default are mixed and slightly adjusted now
MarcoMeter Feb 19, 2022
5a87595
reduced max episode length, diffuclty 2 is more varied, added seed te…
MarcoMeter Feb 20, 2022
456ee31
current state with easy and hard shots
MarcoMeter Feb 24, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ jobs:
buildMethod: BuildScript.PerformBuild
- uses: actions/upload-artifact@v2
with:
name: ${{ matrix.targetPlatform }}
name: Build-${{ steps.date.outputs.date }}
path: builds

371 changes: 232 additions & 139 deletions Assets/ML-Agents/Goalkeeper/GoalKeeperAgent.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ public class GoalkeeperEnvironmentParameters
{
public GoalkeeperEnvironmentParameters()
{
difficulty = 1;
seed = -1;
difficulty = 0;
initialBoost = 32;
canBoost = 1;
canDoubleJump = 1;
canDrift = 1;
canDoubleJump = 1;
useBulletImpulse = 1;
usePsyonixImpulse = 1;
useSuspension = 1;
useCustomBounce = 1;
useWallStabilization = 1;
useGroundStabilization = 1;
}
}
public float seed;
public float difficulty;
public float initialBoost;
public float canDoubleJump;
Expand Down
16 changes: 16 additions & 0 deletions Assets/ML-Agents/Goalkeeper/GoalkeeperEvironmentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ namespace ML_Agents.Goalkeeper
[Serializable]
public class GoalkeeperEvironmentHandler: EnvironmentHandler<GoalkeeperEnvironmentParameters>
{
public int activeSeed = -1;
public float boost_amount = 32.0f;
public GoalkeeperEvironmentHandler(GameObject env, GoalkeeperEnvironmentParameters defaultParameter) : base(env, defaultParameter)
{
}

public override void ResetParameter()
{
UpdateEnvironmentParameters();
if (currentParameter.seed >= 0)
{
activeSeed = (int)currentParameter.seed;
UnityEngine.Random.InitState((int)currentParameter.seed);
}
else
{
System.Random rand = new System.Random();
// Sample a seed from the range 0 to 999
activeSeed = rand.Next(1000);
UnityEngine.Random.InitState(activeSeed);
}
//TODO after merge with difficulty, add difficulty parameter
//environment.GetComponentInChildren<GoalKeeperAgent>().difficulty = currentParameter.difficulty;
if (currentParameter.canDoubleJump == 0)
{
environment.GetComponentInChildren<CubeJumping>().disableDoubleJump = true;
Expand All @@ -27,6 +42,7 @@ public override void ResetParameter()
else
{
environment.GetComponentInChildren<CubeBoosting>().boostAmount = currentParameter.initialBoost;
boost_amount = currentParameter.initialBoost;
}
if (currentParameter.canDrift == 0)
{
Expand Down
4 changes: 4 additions & 0 deletions Assets/ML-Agents/Goalkeeper/SaveTraining_single.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,10 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 1469899324}
m_Modifications:
- target: {fileID: 883974180034025411, guid: 0a3f86ef81cf99f46b33e7f9e661ee20, type: 3}
propertyPath: defaultParameter.difficulty
value: 0
objectReference: {fileID: 0}
- target: {fileID: 883974180034025414, guid: 0a3f86ef81cf99f46b33e7f9e661ee20, type: 3}
propertyPath: m_Name
value: GoalKeeperAgent
Expand Down
118 changes: 99 additions & 19 deletions Assets/ML-Agents/PGBaseAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ protected virtual void Start()
mapData = transform.parent.Find("World").Find("Rocket_Map").GetComponent<MapData>();
}

protected Vector3 NormalizePosition(Transform objTransform)
{
var vec = new Vector3(objTransform.localPosition.x, objTransform.localPosition.y, objTransform.localPosition.z);

vec.x = (vec.x + 60f) / 120f;
vec.y = vec.y / 20f;
vec.z = (vec.z + 41f) / 82f;
return vec;
}

protected void AddRelativePositionNormalized(VectorSensor sensor, Transform otherTransform)
{
sensor.AddObservation((transform.localPosition - otherTransform.localPosition) / mapData.diag);
Expand Down Expand Up @@ -232,26 +222,98 @@ private ActionSpaceType DetermineActionSpaceType(ActionSpec actionSpec)
return ActionSpaceType.Mixed;
}
}
protected Vector3 NormalizeVec(Rigidbody rb, VectorType vecType, EntityType entity)
{
switch (vecType)
{
case VectorType.Position:
return NormalizePosition(rb.transform);
case VectorType.Velocity:
return NormalizeVelocity(rb, entity);
case VectorType.AngularVelocity:
return NormalizeAngularVelocity(rb, entity);
default:
return Vector3.zero;
}
}

protected bool checkVec(Vector3 vec, string name, float defaultValue)
protected Vector3 NormalizePosition(Transform objTransform)
{
var vec = new Vector3(objTransform.localPosition.x, objTransform.localPosition.y, objTransform.localPosition.z);

vec.x = (vec.x + 60f) / 120f;
vec.y = vec.y / 20f;
vec.z = (vec.z + 41f) / 82f;
return vec;
}


protected Vector3 NormalizeVelocity(Rigidbody rb, EntityType entity)
{
switch (entity)
{
case EntityType.Ball:
return rb.velocity.normalized * (rb.velocity.magnitude / 60f);
case EntityType.Car:
return rb.velocity.normalized * (rb.velocity.magnitude / 23f);
default:
return Vector3.zero;
}
}

protected Vector3 NormalizeAngularVelocity(Rigidbody rb, EntityType entity)
{
switch (entity)
{
case EntityType.Ball:
return rb.angularVelocity.normalized * (rb.angularVelocity.magnitude / 6f);
case EntityType.Car:
return rb.angularVelocity.normalized * (rb.angularVelocity.magnitude / 5.5f);
default:
return Vector3.zero;
}
}

protected bool checkNormalizedVec(Vector3 vec, string name, VectorType type)
{
switch (type)
{
case VectorType.Position:
return checkVec(vec, name, -1f, true, false, 0f, 1f);
case VectorType.Velocity:
return checkVec(vec, name, -1f, false, true, -1f, 1f, 0f, 1f);
case VectorType.AngularVelocity:
return checkVec(vec, name, -1f, false, true, -1f, 1f, 0f, 1f);
default:
return true;
}
}


protected bool checkVec(Vector3 vec, string name, float defaultValue, bool legalValueInterval=true, bool legalMagnitudeInterval = true, float minLegalValue=-5f, float maxLegalValue=5f, float minLegalMagnitude=-1f, float maxLegalMagnitude=5f)
{
bool reset = false;
for (int i = 0; i < 3; i++)
{
if (float.IsNaN(vec[i]) || float.IsInfinity(vec[i]))
if (float.IsNaN(vec[i]))
{
Debug.Log($"{name}[{i}] is NaN or Infinity");
Debug.Log($"{name}[{i}] is NaN");
vec[i] = defaultValue;
}
if (vec[i] < -5f || vec[i] > 5f)
if (float.IsInfinity(vec[i]))
{
Debug.LogWarning($"{name}[{i}] is {vec[i]}, was expected to be in interval [-5, 5]");
Debug.Log($"{name}[{i}] is Infinity");
vec[i] = defaultValue;
}
if (legalValueInterval && (vec[i] < minLegalValue || vec[i] > maxLegalValue))
{
Debug.LogWarning($"{name}[{i}] is {vec[i]}, was expected to be in interval [{minLegalValue}, {maxLegalValue}]");
reset = true;
}
}
if (vec.magnitude < -1f || vec.magnitude > 5f)
if (legalMagnitudeInterval && (vec.magnitude < minLegalMagnitude || vec.magnitude > maxLegalMagnitude))
{
Debug.LogWarning($"{name}.magnitude is {vec.magnitude}, was expected to be in interval [-1, 5]");
Debug.LogWarning($"{name}.magnitude is {vec.magnitude}, was expected to be in interval [{minLegalMagnitude}, {maxLegalMagnitude}]");
reset = true;
}
return reset;
Expand All @@ -261,9 +323,14 @@ protected void checkQuaternion(Quaternion quat, string name, float defaultValue)
{
for (int i = 0; i < 4; i++)
{
if (float.IsNaN(quat[i]) || float.IsInfinity(quat[i]))
if (float.IsNaN(quat[i]))
{
Debug.Log(name + "[" + i + "] is NaN");
quat[i] = defaultValue;
}
if (float.IsInfinity(quat[i]))
{
Debug.Log(name + "[" + i + "] is NaN or Infinity");
Debug.Log(name + "[" + i + "] is Infinity");
quat[i] = defaultValue;
}
}
Expand All @@ -278,4 +345,17 @@ public enum ActionSpaceType
MultiDiscrete,
Mixed
}

public enum VectorType
{
Position,
Velocity,
AngularVelocity
}

public enum EntityType
{
Ball,
Car
}
}
2 changes: 1 addition & 1 deletion Assets/ML-Agents/Timers/SaveTraining_single_timers.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"count":1,"self":16.2871648,"total":16.389739,"children":{"InitializeActuators":{"count":2,"self":0.0024779,"total":0.0024779,"children":null},"InitializeSensors":{"count":2,"self":0.0019811,"total":0.0019811,"children":null},"AgentSendState":{"count":1415,"self":0.012920899999999999,"total":0.0689809,"children":{"CollectObservations":{"count":142,"self":0.0536002,"total":0.0536002,"children":null},"WriteActionMask":{"count":142,"self":0.00096749999999999994,"total":0.00096749999999999994,"children":null},"RequestDecision":{"count":142,"self":0.0014923,"total":0.0014923,"children":null}}},"DecideAction":{"count":1415,"self":0.014373499999999999,"total":0.014373499999999999,"children":null},"AgentAct":{"count":1415,"self":0.013272299999999999,"total":0.013272299999999999,"children":null}},"gauges":{"GoalKeeping.CumulativeReward":{"count":1,"max":10.4072571,"min":10.4072571,"runningAverage":10.4072571,"value":10.4072571,"weightedAverage":10.4072571}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1625214513","unity_version":"2020.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2020.3.11f1\\Editor\\Unity.exe -projectpath D:\/Projects\/Unity\/PG\/RoboLeague -useHub -hubIPC -cloudEnvironment production -hubSessionId fb033b90-db03-11eb-b410-0f1c5ce3a503","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.0-pre.3","scene_name":"SaveTraining_single","end_time_seconds":"1625214529"}}
{"count":1,"self":87.5792448,"total":87.656313099999991,"children":{"InitializeActuators":{"count":1,"self":0.001001,"total":0.001001,"children":null},"InitializeSensors":{"count":1,"self":0.0010008,"total":0.0010008,"children":null},"AgentSendState":{"count":10009,"self":0.023017299999999997,"total":0.029021599999999998,"children":{"CollectObservations":{"count":1001,"self":0.0040028,"total":0.0040028,"children":null},"WriteActionMask":{"count":1001,"self":0,"total":0,"children":null},"RequestDecision":{"count":1001,"self":0.0020015,"total":0.0020015,"children":null}}},"DecideAction":{"count":10009,"self":0.0320318,"total":0.0320318,"children":null},"AgentAct":{"count":10009,"self":0.013011199999999999,"total":0.013011199999999999,"children":null}},"gauges":{"GoalKeeping.CumulativeReward":{"count":36,"max":1.8299998,"min":-1.28499973,"runningAverage":-0.35316667,"value":1.74299991,"weightedAverage":0.5062059}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1643387710","unity_version":"2020.3.8f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2020.3.8f1\\Editor\\Unity.exe -projectpath C:\/Users\/Frederik\/RoboLeague -useHub -hubIPC -cloudEnvironment production -hubSessionId 932f6770-804c-11ec-a6f3-efad69b2e458 -accessToken JSfic1JN0fwpxKg1_eM0MmrDIy4FOox5wKmTCZGd9aI008f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.0-pre.3","scene_name":"SaveTraining_single","end_time_seconds":"1643387797"}}
78 changes: 49 additions & 29 deletions Assets/ML-Agents/Topscorer/Environment.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,6 @@ AudioListener:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6750119729059262998}
m_Enabled: 0
--- !u!114 &3243343760869561856
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6750119729296308303}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d2fcec0097665e74fbec36bfc73d7dc7, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &6750119729343506587
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -508,20 +496,6 @@ MonoBehaviour:
m_Calls: []
m_LegacyBlendHint: 0
m_ComponentOwner: {fileID: 6750119729343506586}
--- !u!114 &6750119729572142156
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9118461746507665664}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 88304332db05f5e4b80c2152484c2fa3, type: 3}
m_Name:
m_EditorClassIdentifier:
ShootAt: {fileID: 6750119728131920436}
speed: {x: 5, y: 5}
--- !u!1001 &4127686330414560867
PrefabInstance:
m_ObjectHideFlags: 0
Expand All @@ -532,10 +506,30 @@ PrefabInstance:
- target: {fileID: 7270290807663857190, guid: bfdff73714e4393468e3c7968d554ba5, type: 3}
propertyPath: m_Model
value:
objectReference: {fileID: 5022602860645237092, guid: b56addff173f3da41b4fa25dc61fed23, type: 3}
- target: {fileID: 7270290807663857190, guid: bfdff73714e4393468e3c7968d554ba5, type: 3}
propertyPath: m_BrainParameters.VectorObservationSize
value: 23
objectReference: {fileID: 0}
- target: {fileID: 7270290807663857192, guid: bfdff73714e4393468e3c7968d554ba5, type: 3}
propertyPath: DecisionPeriod
value: 5
objectReference: {fileID: 0}
- target: {fileID: 7270290807663857193, guid: bfdff73714e4393468e3c7968d554ba5, type: 3}
propertyPath: MaxStep
value: 650
objectReference: {fileID: 0}
- target: {fileID: 7270290807663857193, guid: bfdff73714e4393468e3c7968d554ba5, type: 3}
propertyPath: Difficulty
value: 0
value: 2
objectReference: {fileID: 0}
- target: {fileID: 7270290807663857193, guid: bfdff73714e4393468e3c7968d554ba5, type: 3}
propertyPath: defaultParameter.difficulty
value: 2
objectReference: {fileID: 0}
- target: {fileID: 7270290807663857193, guid: bfdff73714e4393468e3c7968d554ba5, type: 3}
propertyPath: defaultParameter.initialBoost
value: 100
objectReference: {fileID: 0}
- target: {fileID: 7270290807663857196, guid: bfdff73714e4393468e3c7968d554ba5, type: 3}
propertyPath: m_Name
Expand Down Expand Up @@ -597,6 +591,18 @@ Transform:
m_CorrespondingSourceObject: {fileID: 7270290807663857197, guid: bfdff73714e4393468e3c7968d554ba5, type: 3}
m_PrefabInstance: {fileID: 4127686330414560867}
m_PrefabAsset: {fileID: 0}
--- !u!114 &3243343760869561856
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6750119729296308303}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d2fcec0097665e74fbec36bfc73d7dc7, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &6750119728108799112
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -724,7 +730,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4104392332257108266, guid: 548a302a7fc95254a999ba2811266cf8, type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 548a302a7fc95254a999ba2811266cf8, type: 3}
Expand Down Expand Up @@ -868,7 +874,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2532842153811578196, guid: 2946bfcea95aa1d40872741310581650, type: 3}
propertyPath: m_LocalPosition.x
value: 44.27
value: -5.6
objectReference: {fileID: 0}
- target: {fileID: 2532842153811578196, guid: 2946bfcea95aa1d40872741310581650, type: 3}
propertyPath: m_LocalPosition.y
Expand Down Expand Up @@ -919,3 +925,17 @@ Transform:
m_CorrespondingSourceObject: {fileID: 2532842153811578196, guid: 2946bfcea95aa1d40872741310581650, type: 3}
m_PrefabInstance: {fileID: 6750119729572142163}
m_PrefabAsset: {fileID: 0}
--- !u!114 &6750119729572142156
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9118461746507665664}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 88304332db05f5e4b80c2152484c2fa3, type: 3}
m_Name:
m_EditorClassIdentifier:
ShootAt: {fileID: 6750119728131920436}
speed: {x: 5, y: 8}
Loading