cameras added & endepisode altered for actuations and waitime

This commit is contained in:
2024-03-22 15:44:30 +00:00
parent 4765189c21
commit 5a566fb98a
34 changed files with 4539 additions and 171 deletions

View File

@@ -9,6 +9,7 @@ using ManyWorlds;
using UnityEngine.Assertions;
using System;
using Unity.Mathematics;
public class RagDollAgent : Agent
{
@@ -55,6 +56,13 @@ public class RagDollAgent : Agent
bool _hasAwake = false;
MocapControllerArtanim _mocapControllerArtanim;
private float timer = 0f;
private float waitTime = 3f;
private bool waitStarted;
private float x = 0;
private float y = 100;
void Awake()
{
if (RequestCamera && CameraTarget != null)
@@ -157,6 +165,12 @@ public class RagDollAgent : Agent
if (ignorActions)
vectorAction = vectorAction.Select(x=>0f).ToArray();
int i = 0;
var scale = 1f;
x += Time.fixedDeltaTime * scale;
y += Time.fixedDeltaTime * scale;
foreach (var m in _motors)
{
if (m.isRoot)
@@ -165,12 +179,36 @@ public class RagDollAgent : Agent
continue;
Vector3 targetNormalizedRotation = Vector3.zero;
if (m.twistLock == ArticulationDofLock.LimitedMotion)
targetNormalizedRotation.x = vectorAction[i++];
if (m.swingYLock == ArticulationDofLock.LimitedMotion)
targetNormalizedRotation.y = vectorAction[i++];
if (m.swingZLock == ArticulationDofLock.LimitedMotion)
targetNormalizedRotation.z = vectorAction[i++];
if (m.twistLock == ArticulationDofLock.LimitedMotion && !waitStarted)
{
targetNormalizedRotation.x = vectorAction[i++];
}
else
{
var offset = 7.5f;
targetNormalizedRotation.x = (Mathf.PerlinNoise(x + offset, y + offset) * 2) - 1; ;
}
if (m.swingYLock == ArticulationDofLock.LimitedMotion && !waitStarted)
{
targetNormalizedRotation.y = vectorAction[i++];
}
else
{
var offset = 5f;
targetNormalizedRotation.y = (Mathf.PerlinNoise(x + offset, y + offset) * 2) - 1; ;
}
if (m.swingZLock == ArticulationDofLock.LimitedMotion && !waitStarted)
{
targetNormalizedRotation.z = vectorAction[i++];
}
else
{
var offset = 22.3f;
targetNormalizedRotation.z = (Mathf.PerlinNoise(x + offset, y + offset) * 2) - 1; ;
}
UpdateMotor(m, targetNormalizedRotation);
}
_dReConObservations.PreviousActions = vectorAction;
@@ -182,7 +220,23 @@ public class RagDollAgent : Agent
{
if (!dontResetOnZeroReward)
EndEpisode();
{
if (!waitStarted)
{
waitStarted = true;
}
timer += Time.fixedDeltaTime;
if (timer >= waitTime)
{
timer = 0;
waitStarted = false;
EndEpisode();
}
}
}
// else if (_dReConRewards.HeadDistance > 1.5f)
else if (_dReConRewards.Reward <= 0.1f && !dontSnapMocapToRagdoll)
@@ -194,6 +248,8 @@ public class RagDollAgent : Agent
AddReward(-.5f);
}
}
float[] GetDebugActions(float[] vectorAction)
{
var debugActions = new List<float>();