Skip to content

Feature dev action04 removed decision requester #12

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: devAction04
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
1 change: 1 addition & 0 deletions Assets/ML-Agents/packerhand/Scenes/Test_30.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,7 @@ PrefabInstance:
objectReference: {fileID: 2100000, guid: 1644c0cb0c67e314194579be857f87da, type: 2}
m_RemovedComponents:
- {fileID: 2674329426616174709, guid: 2f2c1469c0f2c8453ab01d6d68f6526f, type: 3}
- {fileID: 6303212369219772044, guid: 2f2c1469c0f2c8453ab01d6d68f6526f, type: 3}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
Expand Down
4 changes: 1 addition & 3 deletions Assets/ML-Agents/packerhand/Scenes/Test_412.unity
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
agent: {fileID: 0}
parent_mf: {fileID: 0}
isCollidedGreen: 0
isCollidedBlue: 0
isCollidedRed: 0
Expand Down Expand Up @@ -748,7 +747,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
agent: {fileID: 0}
parent_mf: {fileID: 0}
isCollidedGreen: 0
isCollidedBlue: 0
isCollidedRed: 0
Expand Down Expand Up @@ -1291,6 +1289,7 @@ PrefabInstance:
objectReference: {fileID: 2100000, guid: 1644c0cb0c67e314194579be857f87da, type: 2}
m_RemovedComponents:
- {fileID: 2674329426616174709, guid: 2f2c1469c0f2c8453ab01d6d68f6526f, type: 3}
- {fileID: 6303212369219772044, guid: 2f2c1469c0f2c8453ab01d6d68f6526f, type: 3}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
Expand Down Expand Up @@ -1447,7 +1446,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
agent: {fileID: 0}
parent_mf: {fileID: 0}
isCollidedGreen: 0
isCollidedBlue: 0
isCollidedRed: 0
Expand Down
78 changes: 40 additions & 38 deletions Assets/ML-Agents/packerhand/Scripts/PackerHand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PackerHand : Agent
public Vector3 [] verticesArray; // space: 2n + 1 Vector3 vertices where n = num boxes
[HideInInspector] public int selectedVertexIdx = -1;
[HideInInspector] private List<Box> boxPool; // space: num boxes
[HideInInspector] private List<int> vertexIndices;
[HideInInspector] private List<int> maskedVertexIndices;
[HideInInspector] public List<int> organizedBoxes; // list of organzed box indices
[HideInInspector] public List<Vector3> historicalVerticesLog;
[HideInInspector] public int VertexCount = 0;
Expand All @@ -66,7 +66,7 @@ public class PackerHand : Agent
[HideInInspector] public bool isEpisodeStart;
[HideInInspector] public bool isAfterOriginVertexSelected;
//[HideInInspector] public bool isBlackboxUpdated;
public bool isVertexSelected;
// public bool isVertexSelected;
public bool isBoxSelected;
public bool isRotationSelected;
public bool isPickedup;
Expand Down Expand Up @@ -174,7 +174,7 @@ public override void OnEpisodeBegin()
boxSpawner.SetUpBoxes(m_ResetParams.GetWithDefault("regular_box", 0));

selectedVertex = origin; // refactor to select first vertex
isVertexSelected = true;
// isVertexSelected = true;

//SetResetParameters();

Expand Down Expand Up @@ -214,7 +214,7 @@ public override void CollectObservations(VectorSensor sensor)

// Add array of vertices (selected vertices are 0s)
int i = 0;
vertexIndices = new List<int>();
maskedVertexIndices = new List<int>();
foreach (Vector3 vertex in verticesArray)
{
Vector3 scaled_continuous_vertex = new Vector3(((vertex.x - origin.x)/binscale_x), ((vertex.y - origin.y)/binscale_y), ((vertex.z - origin.z)/binscale_z));
Expand All @@ -227,7 +227,7 @@ public override void CollectObservations(VectorSensor sensor)
if (vertex == Vector3.zero)
{
//Debug.Log($"MASK VERTEX LOOP INDEX:{i}");
vertexIndices.Add(i);
maskedVertexIndices.Add(i);
}
i++;
}
Expand All @@ -251,7 +251,7 @@ public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
{
// vertices action mask
if (isAfterOriginVertexSelected) {
foreach (int vertexIdx in vertexIndices)
foreach (int vertexIdx in maskedVertexIndices)
{
//Debug.Log($"MASK VERTEX {vertexIdx}");
actionMask.SetActionEnabled(0, vertexIdx, false);
Expand Down Expand Up @@ -652,7 +652,7 @@ public void SelectVertex(int action_SelectedVertex)
selectedVertex = new Vector3(((unscaled_selectedVertex.x* binscale_x) + origin.x), ((unscaled_selectedVertex.y* binscale_y) + origin.y), ((unscaled_selectedVertex.z* binscale_z) + origin.z));
Debug.Log($"SVX Selected VerteX: {selectedVertex}");

isVertexSelected = true;
// isVertexSelected = true;
//AddReward(1f);
// Debug.Log($"RWD {GetCumulativeReward()} total reward | +1 reward from isVertexSelected: {isVertexSelected}");
}
Expand Down Expand Up @@ -1136,36 +1136,38 @@ public void ReverseSideNames(int id)
}


public void BoxReset(string cause)
{
if (cause == "failedPhysicsCheck")
{
Debug.Log($"SCS BOX {selectedBoxIdx} RESET LOOP, BOX POOL COUNT IS {boxPool.Count}");
// detach box from agent
targetBox.parent = null;
// add back rigidbody and collider
Rigidbody rb = boxPool[selectedBoxIdx].rb;
BoxCollider bc = boxPool[selectedBoxIdx].rb.gameObject.AddComponent<BoxCollider>();
// not be affected by forces or collisions, position and rotation will be controlled directly through script
rb.isKinematic = true;
// reset to starting position
rb.transform.localScale = boxPool[selectedBoxIdx].startingSize;
rb.transform.rotation = boxPool[selectedBoxIdx].startingRot;
rb.transform.position = boxPool[selectedBoxIdx].startingPos;
ReverseSideNames(selectedBoxIdx);
// remove from organized list to be picked again
organizedBoxes.Remove(selectedBoxIdx);
// reset states
StateReset();
// REQUEST DECISION FOR THE NEXT ROUND OF PICKING
GetComponent<Agent>().RequestDecision();
Academy.Instance.EnvironmentStep();
// settting isBlackboxUpdated to true allows another vertex to be selected
//isBlackboxUpdated = true;
// setting isVertexSelected to true keeps the current vertex and allows another box to be selected
// isVertexSelected = true;
}
}
// public void BoxReset(string cause)
// {
// if (cause == "failedPhysicsCheck")
// {
// Debug.Log($"SCS BOX {selectedBoxIdx} RESET LOOP, BOX POOL COUNT IS {boxPool.Count}");
// // detach box from agent
// targetBox.parent = null;
// // add back rigidbody and collider
// Rigidbody rb = boxPool[selectedBoxIdx].rb;
// BoxCollider bc = boxPool[selectedBoxIdx].rb.gameObject.AddComponent<BoxCollider>();
// // not be affected by forces or collisions, position and rotation will be controlled directly through script
// rb.isKinematic = true;
// // reset to starting position
// rb.transform.localScale = boxPool[selectedBoxIdx].startingSize;
// rb.transform.rotation = boxPool[selectedBoxIdx].startingRot;
// rb.transform.position = boxPool[selectedBoxIdx].startingPos;
// ReverseSideNames(selectedBoxIdx);
// // remove from organized list to be picked again
// // to "be picked again" means to be added back to the boxPool??
// organizedBoxes.Remove(selectedBoxIdx);
// // reset states
// StateReset();
// // REQUEST DECISION FOR THE NEXT ROUND OF PICKING
// // Why is the DecisionRequester() still active in the Hand gameObject?
// GetComponent<Agent>().RequestDecision();
// Academy.Instance.EnvironmentStep();
// // settting isBlackboxUpdated to true allows another vertex to be selected
// //isBlackboxUpdated = true;
// // setting isVertexSelected to true keeps the current vertex and allows another box to be selected
// // isVertexSelected = true;
// }
// }


public void AgentReset()
Expand Down Expand Up @@ -1200,7 +1202,7 @@ public void StateReset()
boxPool[selectedBoxIdx].boxRot = default_rotation;
}
//isBlackboxUpdated = false;
isVertexSelected = false;
// isVertexSelected = false;
isBoxSelected = false;
isRotationSelected = false;
isPickedup = false;
Expand Down