Example #1
0
    // [Tooltip("Lock the top most element")]
    // /**< \brief Lock the top most element*/
    // public bool FreezeTop = false;
    // bool _lastFreezeTop;

    public override float[] Decide(
        List <float> vectorObs,
        List <Texture2D> visualObs,
        float reward,
        bool done,
        List <float> memory)
    {
        // lazy init
        if (_controller == null)
        {
            _controller = FindObjectOfType <MarathonTestBedController>();
            // _brain = GetComponent<Brain>();
            // Actions = Enumerable.Repeat(0f, _brain.brainParameters.vectorActionSize[0]).ToArray();
            // Actions = Enumerable.Repeat(0f, 100).ToArray();
        }
        if (_controller.ApplyRandomActions)
        {
            for (int i = 0; i < _controller.Actions.Length; i++)
            {
                _controller.Actions[i] = Random.value * 2 - 1;
            }
        }

        return(_controller.Actions);
    }
Example #2
0
    void Start()
    {
        _body            = GetComponent <ArticulationBody>();
        _parentBody      = _body.transform.parent.GetComponentInParent <ArticulationBody>();
        _debugController = FindObjectOfType <MarathonTestBedController>();
        _spawnableEnv    = GetComponentInParent <MLAgents.SpawnableEnv>();
        _mocapController = _spawnableEnv.GetComponentInChildren <MocapController>();
        var mocapBodyParts = _mocapController.GetComponentsInChildren <Rigidbody>().ToList();

        _target = mocapBodyParts.First(x => x.name == _body.name);
    }
Example #3
0
    public override void AgentReset()
    {
        if (!_hasLazyInitialized)
        {
            _decisionRequester  = GetComponent <DecisionRequester>();
            _debugController    = FindObjectOfType <MarathonTestBedController>();
            Time.fixedDeltaTime = FixedDeltaTime;
            _spawnableEnv       = GetComponentInParent <SpawnableEnv>();
            _mocapController    = _spawnableEnv.GetComponentInChildren <MocapController>();
            _mocapBodyParts     = _mocapController.GetComponentsInChildren <Rigidbody>().ToList();
            _bodyParts          = GetComponentsInChildren <ArticulationBody>().ToList();
            _dReConObservations = GetComponent <DReConObservations>();
            _dReConRewards      = GetComponent <DReConRewards>();
            var mocapController = _spawnableEnv.GetComponentInChildren <MocapController>();
            _trackBodyStatesInWorldSpace = mocapController.GetComponent <TrackBodyStatesInWorldSpace>();
            _ragDollSettings             = GetComponent <RagDoll003>();
            _inputController             = _spawnableEnv.GetComponentInChildren <InputController>();
            _sensorObservations          = GetComponent <SensorObservations>();

            foreach (var body in GetComponentsInChildren <ArticulationBody>())
            {
                body.solverIterations         = 255;
                body.solverVelocityIterations = 255;
            }

            _motors = GetComponentsInChildren <ArticulationBody>()
                      .Where(x => x.jointType == ArticulationJointType.SphericalJoint)
                      .Where(x => !x.isRoot)
                      .Distinct()
                      .ToList();
            var individualMotors = new List <float>();
            foreach (var m in _motors)
            {
                if (m.twistLock == ArticulationDofLock.LimitedMotion)
                {
                    individualMotors.Add(0f);
                }
                if (m.swingYLock == ArticulationDofLock.LimitedMotion)
                {
                    individualMotors.Add(0f);
                }
                if (m.swingZLock == ArticulationDofLock.LimitedMotion)
                {
                    individualMotors.Add(0f);
                }
            }
            _dReConObservations.PreviousActions = individualMotors.ToArray();
            _hasLazyInitialized = true;
        }
        _smoothedActions = null;
        debugCopyMocap   = false;
        _inputController.OnReset();
        _mocapController.GetComponentInChildren <MocapAnimatorController>().OnReset();
        var angle    = Vector3.SignedAngle(Vector3.forward, _inputController.HorizontalDirection, Vector3.up);
        var rotation = Quaternion.Euler(0f, angle, 0f);

        _mocapController.OnReset(rotation);
        _mocapController.CopyStatesTo(this.gameObject);
        // _trackBodyStatesInWorldSpace.CopyStatesTo(this.gameObject);
        float timeDelta = float.MinValue;

        _dReConObservations.OnReset();
        _dReConRewards.OnReset();
        _dReConObservations.OnStep(timeDelta);
        _dReConRewards.OnStep(timeDelta);
        _skipRewardAfterTeleport = false;
#if UNITY_EDITOR
        if (DebugPauseOnReset)
        {
            UnityEditor.EditorApplication.isPaused = true;
        }
#endif
    }