Skip to content

Chenxi summer changes #122

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion org.janelia.easy-ml-agents/Editor/EasyMLSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ private static void Create(Type arenaType, Type agentType)
}

EasyMLSetupHelper helper = new EasyMLSetupHelper();
arena.Setup(helper);
agent.Setup(helper);
arena.Setup(helper);

arena.PlaceRandomly();

Expand Down
7 changes: 6 additions & 1 deletion org.janelia.easy-ml-agents/Editor/EasyMLSetupHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ public void CreatePhysicsMaterial(Collider collider, float staticFriction, float

public bool UsingURP()
{
return (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset.GetType().Name == "UniversalRenderPipelineAsset");
UnityEngine.Rendering.RenderPipelineAsset pipeline = UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset;
if (pipeline != null)
{
return (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset.GetType().Name == "UniversalRenderPipelineAsset");
}
return false;
}
}
}
10 changes: 7 additions & 3 deletions org.janelia.easy-ml-agents/Runtime/EasyMLAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ public abstract class EasyMLAgent : Agent
public abstract int VectorObservationSize { get; protected set; }

/// <summary>
/// The number of observations added in <see cref="CollectObservations(VectorSensor)"/>
/// (and remember that one <see cref="Vector3"/> counts as 3 observations).
/// The number of continous actions.
/// </summary>
public abstract int VectorActionSize { get; protected set; }

/// <summary>
/// The number of discrete actions.
/// </summary>
public abstract int[] DiscreteBranchSize { get; protected set; }

/// <summary>
/// The size of the BoxCollider given to the agent by default. Note that a value S in
/// any of the dimensions means the box covers [-S/2, S/2] in that dimension.
Expand Down Expand Up @@ -167,7 +171,7 @@ public virtual void Setup(IEasyMLSetupHelper helper)
{
behavior.BehaviorName = BehaviorName;
behavior.BrainParameters.VectorObservationSize = VectorObservationSize;
behavior.BrainParameters.ActionSpec = new ActionSpec(VectorActionSize);
behavior.BrainParameters.ActionSpec = new ActionSpec(VectorActionSize, DiscreteBranchSize);

const string SENSOR_OBJECT_NAME = "RaysForward";

Expand Down
18 changes: 12 additions & 6 deletions org.janelia.easy-ml-agents/Runtime/EasyMLAgentGrounded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public override Vector3 ChildSensorSourceOffset
}
private Vector3 _groundedChildSensorSourceOffset = new Vector3(0, 0.05f, 0);

public virtual string BodyName
{
get { return _groundedBodyName; }
protected set { _groundedBodyName = value; }
}
private string _groundedBodyName = "Body";

/// <summary>
/// Called after the Setup function for the arena (the class derived from <see cref="EasyMLArena"/>).
Expand All @@ -122,13 +128,13 @@ public override void Setup(Janelia.IEasyMLSetupHelper helper)
base.Setup(helper);
gameObject.name = "AgentGrounded";

const string BODY_NAME = "Body";
Transform bodyTransform = transform.Find(BODY_NAME);

Transform bodyTransform = transform.Find(BodyName);
GameObject body;
if (bodyTransform == null)
{
body = new GameObject();
body.name = BODY_NAME;
body.name = BodyName;
body.transform.parent = transform;
}
else
Expand Down Expand Up @@ -221,9 +227,9 @@ public override void Heuristic(in ActionBuffers actionsOut)

Debug.Assert(VectorActionSize == 2, "Incorrect vector action size");

ActionSegment<float> continuouActions = actionsOut.ContinuousActions;
continuouActions[0] = moveChange;
continuouActions[1] = yawChange;
ActionSegment<float> continuousActions = actionsOut.ContinuousActions;
continuousActions[0] = moveChange;
continuousActions[1] = yawChange;
}
}
}