Merge old actionmask with new system
This commit is contained in:
parent
2677bb6fd2
commit
d75c202b8d
@ -31,8 +31,12 @@ namespace Cozmo
|
|||||||
public Camera renderCamera;
|
public Camera renderCamera;
|
||||||
[Tooltip("Reference to the CozmoMovement script")]
|
[Tooltip("Reference to the CozmoMovement script")]
|
||||||
public CozmoMovementController movementController;
|
public CozmoMovementController movementController;
|
||||||
|
[Tooltip("The time between decisions at inference")]
|
||||||
public float timeBetweenDecisionsAtInference;
|
public float timeBetweenDecisionsAtInference;
|
||||||
|
[Tooltip("The amout of actions that should be remembered by the agent.")]
|
||||||
public int maxStoredMovementStates = 1;
|
public int maxStoredMovementStates = 1;
|
||||||
|
[Tooltip("If activated the maxStoredMovementStates has no impact on the training.")]
|
||||||
|
public bool useOriginalActionMasking = true;
|
||||||
|
|
||||||
private Academy academy; // CozmoAcademy
|
private Academy academy; // CozmoAcademy
|
||||||
private float timeSinceDecision; // time since last decision
|
private float timeSinceDecision; // time since last decision
|
||||||
@ -40,13 +44,13 @@ namespace Cozmo
|
|||||||
private int nearAreaLimit = 0; // X coordinate limit for the near to the imagecenter area
|
private int nearAreaLimit = 0; // X coordinate limit for the near to the imagecenter area
|
||||||
private int centerOfImageX = 0; // Middle of the image in x direction
|
private int centerOfImageX = 0; // Middle of the image in x direction
|
||||||
private MovementState lastChosenMovement = MovementState.Stop; // The last action/movement that was executed
|
private MovementState lastChosenMovement = MovementState.Stop; // The last action/movement that was executed
|
||||||
|
private Queue<MovementState> lastActions = new Queue<MovementState>(); // Queue to store the last chosen Actions
|
||||||
|
|
||||||
private Queue<MovementState> lastActions = new Queue<MovementState>();
|
private double startTime = 0;
|
||||||
|
|
||||||
private double startTime = Time.time;
|
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
startTime = Time.time;
|
||||||
academy = FindObjectOfType(typeof(CozmoAcademy)) as CozmoAcademy;
|
academy = FindObjectOfType(typeof(CozmoAcademy)) as CozmoAcademy;
|
||||||
imageProcessor = renderCamera.GetComponent<ImageProcessor>();
|
imageProcessor = renderCamera.GetComponent<ImageProcessor>();
|
||||||
nearAreaLimit = (int)(renderCamera.targetTexture.width / 2 * NEAR_AREA_PERCENTAGE_OFFSET);
|
nearAreaLimit = (int)(renderCamera.targetTexture.width / 2 * NEAR_AREA_PERCENTAGE_OFFSET);
|
||||||
@ -66,50 +70,56 @@ namespace Cozmo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set ActionMask for training
|
// Set ActionMask for training
|
||||||
|
// Needs to be called from CollectObservations()
|
||||||
private void SetMask()
|
private void SetMask()
|
||||||
{
|
{
|
||||||
// Do not allow stop decision after a stop
|
if (useOriginalActionMasking)
|
||||||
if (lastChosenMovement == MovementState.Stop)
|
|
||||||
{
|
{
|
||||||
SetActionMask(STOP);
|
// Stop is never allowed
|
||||||
|
switch (lastChosenMovement)
|
||||||
|
{
|
||||||
|
// Do not allow stop decision after a stop
|
||||||
|
case (MovementState.Stop):
|
||||||
|
SetActionMask(STOP);
|
||||||
|
break;
|
||||||
|
// Do not allow stop after forward
|
||||||
|
case (MovementState.Forward):
|
||||||
|
SetActionMask(STOP);
|
||||||
|
break;
|
||||||
|
// Do not allow stop & left after right
|
||||||
|
case (MovementState.Right):
|
||||||
|
SetActionMask(STOP);
|
||||||
|
SetActionMask(LEFT);
|
||||||
|
break;
|
||||||
|
// Do not allow stop & right after left
|
||||||
|
case (MovementState.Left):
|
||||||
|
SetActionMask(STOP);
|
||||||
|
SetActionMask(RIGHT);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("Invalid MovementState.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Do not allow left decision if right was in the last actions
|
|
||||||
if (lastActions.Contains(MovementState.Right))
|
|
||||||
{
|
{
|
||||||
SetActionMask(LEFT);
|
// Do not allow stop decision after a stop
|
||||||
}
|
if (lastChosenMovement == MovementState.Stop)
|
||||||
|
{
|
||||||
|
SetActionMask(STOP);
|
||||||
|
}
|
||||||
|
|
||||||
// Do not allow right decision if left was in the last actions
|
// Do not allow left decision if right was in the last actions
|
||||||
if (lastActions.Contains(MovementState.Left))
|
if (lastActions.Contains(MovementState.Right))
|
||||||
{
|
{
|
||||||
SetActionMask(RIGHT);
|
SetActionMask(LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//switch (lastChosenMovement)
|
// Do not allow right decision if left was in the last actions
|
||||||
//{
|
if (lastActions.Contains(MovementState.Left))
|
||||||
// // Do not allow stop decision after a stop
|
{
|
||||||
// case (MovementState.Stop):
|
SetActionMask(RIGHT);
|
||||||
// SetActionMask(STOP);
|
}
|
||||||
// break;
|
}
|
||||||
// // Do not allow stop after forward
|
|
||||||
// case (MovementState.Forward):
|
|
||||||
// //SetActionMask(STOP);
|
|
||||||
// break;
|
|
||||||
// // Do not allow stop & left after right
|
|
||||||
// case (MovementState.Right):
|
|
||||||
// //SetActionMask(STOP);
|
|
||||||
// if (lastActions.Contains(MovementState.))
|
|
||||||
// SetActionMask(LEFT);
|
|
||||||
// break;
|
|
||||||
// // Do not allow stop & right after left
|
|
||||||
// case (MovementState.Left):
|
|
||||||
// //SetActionMask(STOP);
|
|
||||||
// SetActionMask(RIGHT);
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// throw new ArgumentException("Invalid MovementState.");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// to be implemented by the developer
|
// to be implemented by the developer
|
||||||
@ -129,25 +139,21 @@ namespace Cozmo
|
|||||||
case STOP:
|
case STOP:
|
||||||
movementController.currentMovementState = MovementState.Stop;
|
movementController.currentMovementState = MovementState.Stop;
|
||||||
lastChosenMovement = MovementState.Stop;
|
lastChosenMovement = MovementState.Stop;
|
||||||
//Test
|
|
||||||
SetReward(-0.02f);
|
SetReward(-0.02f);
|
||||||
break;
|
break;
|
||||||
case FORWARD:
|
case FORWARD:
|
||||||
movementController.currentMovementState = MovementState.Forward;
|
movementController.currentMovementState = MovementState.Forward;
|
||||||
lastChosenMovement = MovementState.Forward;
|
lastChosenMovement = MovementState.Forward;
|
||||||
//Test
|
|
||||||
SetReward(0.02f);
|
SetReward(0.02f);
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
movementController.currentMovementState = MovementState.Right;
|
movementController.currentMovementState = MovementState.Right;
|
||||||
lastChosenMovement = MovementState.Right;
|
lastChosenMovement = MovementState.Right;
|
||||||
//Test
|
|
||||||
SetReward(0.01f);
|
SetReward(0.01f);
|
||||||
break;
|
break;
|
||||||
case LEFT:
|
case LEFT:
|
||||||
movementController.currentMovementState = MovementState.Left;
|
movementController.currentMovementState = MovementState.Left;
|
||||||
lastChosenMovement = MovementState.Left;
|
lastChosenMovement = MovementState.Left;
|
||||||
//Test
|
|
||||||
SetReward(0.01f);
|
SetReward(0.01f);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -155,7 +161,8 @@ namespace Cozmo
|
|||||||
throw new ArgumentException("Invalid action value. Stop movement.");
|
throw new ArgumentException("Invalid action value. Stop movement.");
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectLastMovementStates(lastChosenMovement);
|
if (!useOriginalActionMasking)
|
||||||
|
CollectLastMovementStates(lastChosenMovement);
|
||||||
|
|
||||||
// Render new image after movement in order to update the centerOfGravity
|
// Render new image after movement in order to update the centerOfGravity
|
||||||
if (renderCamera != null)
|
if (renderCamera != null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user