Ejemplo n.º 1
0
    void ObservationsHumanoid()
    {
        if (ShowMonitor)
        {
        }

        var pelvis    = BodyParts["pelvis"];
        var shoulders = BodyParts["shoulders"];

        Vector3 normalizedVelocity = this.GetNormalizedVelocity(pelvis.velocity);

        AddVectorObs(normalizedVelocity);
        AddVectorObs(pelvis.transform.forward); // gyroscope
        AddVectorObs(pelvis.transform.up);

        AddVectorObs(shoulders.transform.forward); // gyroscope
        AddVectorObs(shoulders.transform.up);

        AddVectorObs(SensorIsInTouch);
        JointRotations.ForEach(x => AddVectorObs(x));
        AddVectorObs(JointVelocity);
        AddVectorObs(new [] {
            this.GetNormalizedPosition(BodyParts["left_foot_left"].transform.position).y,
            this.GetNormalizedPosition(BodyParts["left_foot_right"].transform.position).y,
            this.GetNormalizedPosition(BodyParts["right_foot_left"].transform.position).y,
            this.GetNormalizedPosition(BodyParts["right_foot_right"].transform.position).y,
        });
    }
Ejemplo n.º 2
0
    void ObservationsDefault()
    {
        var     sensor             = this;
        var     pelvis             = BodyParts["pelvis"];
        Vector3 normalizedVelocity = this.GetNormalizedVelocity(pelvis.velocity);

        sensor.AddVectorObs(normalizedVelocity);
        sensor.AddVectorObs(pelvis.transform.forward); // gyroscope
        sensor.AddVectorObs(pelvis.transform.up);

        sensor.AddVectorObs(SensorIsInTouch);
        JointRotations.ForEach(x => sensor.AddVectorObs(x));
        sensor.AddVectorObs(JointVelocity);
        // sensor.AddVectorObs(new []{
        //     this.GetNormalizedPosition(BodyParts["left_foot"].transform.position).y,
        //     this.GetNormalizedPosition(BodyParts["right_foot"].transform.position).y
        // });

        (List <float> distances, float fraction) =
            _terrainGenerator.GetDistances2d(
                pelvis.transform.position, ShowMonitor);

        sensor.AddVectorObs(distances);
        sensor.AddVectorObs(fraction);
    }
Ejemplo n.º 3
0
    void ObservationsDefault()
    {
        // var pelvis = BodyParts["pelvis"];
        // AddVectorObs(pelvis.velocity);
        // AddVectorObs(pelvis.transform.forward); // gyroscope
        // AddVectorObs(pelvis.transform.up);

        // AddVectorObs(SensorIsInTouch);
        // JointRotations.ForEach(x=>AddVectorObs(x));
        // AddVectorObs(JointVelocity);
        // var foot = BodyParts["foot"];
        // AddVectorObs(foot.transform.position.y);

        var     pelvis             = BodyParts["pelvis"];
        Vector3 normalizedVelocity = this.GetNormalizedVelocity(pelvis.velocity);

        AddVectorObs(normalizedVelocity);
        AddVectorObs(pelvis.transform.forward); // gyroscope
        AddVectorObs(pelvis.transform.up);

        AddVectorObs(SensorIsInTouch);
        JointRotations.ForEach(x => AddVectorObs(x));
        AddVectorObs(JointVelocity);
        var     foot = BodyParts["foot"];
        Vector3 normalizedFootPosition = this.GetNormalizedPosition(foot.transform.position);

        AddVectorObs(normalizedFootPosition.y);

        (List <float> distances, float fraction) =
            _terrainGenerator.GetDistances2d(
                pelvis.transform.position, ShowMonitor);

        AddVectorObs(distances);
        AddVectorObs(fraction);
    }
    void ObservationsDefault()
    {
        if (ShowMonitor)
        {
        }
        var pelvis = BodyParts["pelvis"];

        AddVectorObs(pelvis.velocity);
        AddVectorObs(pelvis.transform.forward); // gyroscope
        AddVectorObs(pelvis.transform.up);

        AddVectorObs(SensorIsInTouch);
        JointRotations.ForEach(x => AddVectorObs(x));
        AddVectorObs(JointVelocity);
        var foot = BodyParts["foot"];

        AddVectorObs(foot.transform.position.y);

        var xpos = foot.transform.position.x;

        xpos -= 2f;
        float        fraction  = (xpos - (Mathf.Floor(xpos * 5) / 5)) * 5;
        float        ypos      = foot.transform.position.y;
        List <Ray>   rays      = Enumerable.Range(0, 5 * 5).Select(x => new Ray(new Vector3(xpos + (x * .2f), 5f, 0f), Vector3.down)).ToList();
        List <float> distances = rays.Select
                                     (x =>
                                     ypos - (5f -
                                             Physics.RaycastAll(x, 10f)
                                             .OrderBy(y => y.distance)
                                             .First()
                                             .distance)
                                     ).ToList();

        if (Application.isEditor && ShowMonitor)
        {
            var view = distances.Skip(10).Take(20).Select(x => x).ToList();
            Monitor.Log("distances", view.ToArray());
            var time = Time.deltaTime;
            time *= agentParameters.numberOfActionsBetweenDecisions;
            for (int i = 0; i < rays.Count; i++)
            {
                var distance  = distances[i];
                var origin    = new Vector3(rays[i].origin.x, ypos, 0f);
                var direction = distance > 0 ? Vector3.down : Vector3.up;
                var color     = distance > 0 ? Color.yellow : Color.red;
                Debug.DrawRay(origin, direction * Mathf.Abs(distance), color, time, false);
            }
        }
        AddVectorObs(distances);
        AddVectorObs(fraction);
    }
Ejemplo n.º 5
0
    void ObservationsDefault()
    {
        if (ShowMonitor)
        {
        }
        var pelvis = BodyParts["pelvis"];

        AddVectorObs(pelvis.velocity);
        AddVectorObs(pelvis.transform.forward); // gyroscope
        AddVectorObs(pelvis.transform.up);

        AddVectorObs(SensorIsInTouch);
        JointRotations.ForEach(x => AddVectorObs(x));
        AddVectorObs(JointVelocity);
    }
Ejemplo n.º 6
0
    void ObservationsDefault()
    {
        if (ShowMonitor)
        {
        }

        var     pelvis             = BodyParts["pelvis"];
        Vector3 normalizedVelocity = GetNormalizedVelocity(pelvis.velocity);

        AddVectorObs(normalizedVelocity);
        AddVectorObs(pelvis.transform.forward); // gyroscope
        AddVectorObs(pelvis.transform.up);

        AddVectorObs(SensorIsInTouch);
        JointRotations.ForEach(x => AddVectorObs(x));
        AddVectorObs(JointVelocity);
        Vector3 normalizedFootPosition = this.GetNormalizedPosition(pelvis.transform.position);

        AddVectorObs(normalizedFootPosition.y);
    }
    void ObservationsDefault()
    {
        TargetVelocityX = controllerAgent.AxisX;
        if (ShowMonitor)
        {
        }
        var pelvis = BodyParts["pelvis"];

        AddVectorObs(pelvis.velocity);
        AddVectorObs(pelvis.transform.forward); // gyroscope
        AddVectorObs(pelvis.transform.up);

        AddVectorObs(SensorIsInTouch);
        JointRotations.ForEach(x => AddVectorObs(x));
        AddVectorObs(JointVelocity);
        var foot = BodyParts["foot"];

        AddVectorObs(foot.transform.position.y);

        AddVectorObs(TargetVelocityX);
        AddVectorObs(CurrentVelocityX);
    }
Ejemplo n.º 8
0
    void ObservationsDefault()
    {
        var sensor = this;

        if (ShowMonitor)
        {
        }

        var     pelvis             = BodyParts["pelvis"];
        Vector3 normalizedVelocity = this.GetNormalizedVelocity(pelvis.velocity);

        sensor.AddVectorObs(normalizedVelocity);
        sensor.AddVectorObs(pelvis.transform.forward); // gyroscope
        sensor.AddVectorObs(pelvis.transform.up);

        sensor.AddVectorObs(SensorIsInTouch);
        JointRotations.ForEach(x => sensor.AddVectorObs(x));
        sensor.AddVectorObs(JointVelocity);
        sensor.AddVectorObs(new [] {
            this.GetNormalizedPosition(BodyParts["left_foot"].transform.position).y,
            this.GetNormalizedPosition(BodyParts["right_foot"].transform.position).y
        });
    }
Ejemplo n.º 9
0
    void ObservationsDefault()
    {
        var pelvis = BodyParts["pelvis"];

        #region origin
        AddVectorObs(pelvis.velocity);          //3
        AddVectorObs(pelvis.transform.forward); // gyroscope //3
        AddVectorObs(pelvis.transform.up);      //3

        //AddVectorObs(SensorIsInTouch); //xml 센서 수

        for (int i = 0; i < collisionSensors.Count; i++)
        {
            AddVectorObs(collisionSensors[i].isCollision);
        }

        JointRotations.ForEach(x => AddVectorObs(x)); //xml actuator 수 * 4
        AddVectorObs(JointVelocity);                  //xml actuator 수
        #endregion

        #region pybullet
        //if (collectStateList.Count <= 0)
        //{
        //    //more //8
        //    float torso_height = Mathf.Abs(pelvis.transform.position.y - init_y);
        //    AddVectorObs(torso_height);

        //    float self_walk_target_theta = Mathf.Atan2(target.z - pelvis.transform.position.z, target.x - pelvis.transform.position.x);
        //    float yaw = GetAngle(pelvis.transform.localEulerAngles.y) * Mathf.Deg2Rad;
        //    float angle_to_target = self_walk_target_theta - yaw;
        //    //print(self_walk_target_theta + ", " + yaw);
        //    float sin = Mathf.Sin(angle_to_target);
        //    float cos = Mathf.Cos(angle_to_target);
        //    //print(sin + ", " + cos);
        //    AddVectorObs(sin);
        //    AddVectorObs(cos);

        //    AddVectorObs(pelvis.velocity * 0.3f);

        //    float pitch = GetAngle(pelvis.transform.localEulerAngles.x) * Mathf.Deg2Rad;
        //    float roll = GetAngle(pelvis.transform.localEulerAngles.z) * Mathf.Deg2Rad;

        //    float clampedAngleX = Mathf.Clamp(pitch, -5f, 5f);
        //    //float clampedAngleY = Mathf.Clamp(yaw, -5f, 5f);
        //    float clampedAngleZ = Mathf.Clamp(roll, -5f, 5f);

        //    AddVectorObs(clampedAngleX);
        //    //AddVectorObs(clampedAngleY);
        //    AddVectorObs(clampedAngleZ);

        //    CollectJointAngle(0); //joint 각도
        //    CollectJointAngularVelocity(0); //joint 각속도
        //    CollectJointCollisionSensors(0); //feet_contact, 지면 접촉 여부
        //}
        #endregion

        #region CSONG
        foreach (var item in collectStateList)
        {
            item.collectState(item.index);
        }

        //print(info.vectorObservation.Count);

        int remain = brain.brainParameters.vectorObservationSize - info.vectorObservation.Count;
        for (int i = 0; i < remain; i++)
        {
            AddVectorObs(0f);
        }
        #endregion
    }