Пример #1
0
        /// <summary>
        ///  Construct a new PhysicsBodySensor
        /// </summary>
        /// <param name="rootBody"></param>
        /// <param name="settings"></param>
        /// <param name="sensorName"></param>
        public PhysicsBodySensor(Rigidbody rootBody, GameObject rootGameObject, PhysicsSensorSettings settings, string sensorName = null)
        {
            var poseExtractor = new RigidBodyPoseExtractor(rootBody, rootGameObject);

            m_PoseExtractor = poseExtractor;
            m_SensorName    = string.IsNullOrEmpty(sensorName) ? $"PhysicsBodySensor:{rootBody?.name}" : sensorName;
            m_Settings      = settings;

            var numJointExtractorObservations = 0;
            var rigidBodies = poseExtractor.Bodies;

            if (rigidBodies != null)
            {
                m_JointExtractors = new IJointExtractor[rigidBodies.Length - 1]; // skip the root
                for (var i = 1; i < rigidBodies.Length; i++)
                {
                    var jointExtractor = new RigidBodyJointExtractor(rigidBodies[i]);
                    numJointExtractorObservations += jointExtractor.NumObservations(settings);
                    m_JointExtractors[i - 1]       = jointExtractor;
                }
            }
            else
            {
                m_JointExtractors = new IJointExtractor[0];
            }

            var numTransformObservations = m_PoseExtractor.GetNumPoseObservations(settings);

            m_Shape = new[] { numTransformObservations + numJointExtractorObservations };
        }
        /// <inheritdoc/>
        public override int[] GetObservationShape()
        {
            if (RootBody == null)
            {
                return new[] { 0 };
            }

            var poseExtractor = GetPoseExtractor();
            var numPoseObservations = poseExtractor.GetNumPoseObservations(Settings);

            var numJointObservations = 0;
            foreach(var rb in poseExtractor.GetEnabledRigidbodies())
            {
                var joint = rb.GetComponent<Joint>();
                numJointObservations += RigidBodyJointExtractor.NumObservations(rb, joint, Settings);
            }
            return new[] { numPoseObservations + numJointObservations };
        }
        /// <inheritdoc/>
        public override int[] GetObservationShape()
        {
            if (RootBody == null)
            {
                return(new[] { 0 });
            }

            // TODO static method in PhysicsBodySensor?
            // TODO only update PoseExtractor when body changes?
            var poseExtractor       = new RigidBodyPoseExtractor(RootBody, gameObject, VirtualRoot);
            var numPoseObservations = poseExtractor.GetNumPoseObservations(Settings);

            var numJointObservations = 0;

            // Start from i=1 to ignore the root
            for (var i = 1; i < poseExtractor.Bodies.Length; i++)
            {
                var body  = poseExtractor.Bodies[i];
                var joint = body?.GetComponent <Joint>();
                numJointObservations += RigidBodyJointExtractor.NumObservations(body, joint, Settings);
            }
            return(new[] { numPoseObservations + numJointObservations });
        }
Пример #4
0
        /// <summary>
        /// Construct a new PhysicsBodySensor
        /// </summary>
        /// <param name="poseExtractor"></param>
        /// <param name="settings"></param>
        /// <param name="sensorName"></param>
        public PhysicsBodySensor(
            RigidBodyPoseExtractor poseExtractor,
            PhysicsSensorSettings settings,
            string sensorName
            )
        {
            m_PoseExtractor = poseExtractor;
            m_SensorName    = sensorName;
            m_Settings      = settings;

            var numJointExtractorObservations = 0;

            m_JointExtractors = new List <IJointExtractor>(poseExtractor.NumEnabledPoses);
            foreach (var rb in poseExtractor.GetEnabledRigidbodies())
            {
                var jointExtractor = new RigidBodyJointExtractor(rb);
                numJointExtractorObservations += jointExtractor.NumObservations(settings);
                m_JointExtractors.Add(jointExtractor);
            }

            var numTransformObservations = m_PoseExtractor.GetNumPoseObservations(settings);

            m_Shape = new[] { numTransformObservations + numJointExtractorObservations };
        }