Ejemplo n.º 1
0
        public void SetSubscribeJointStates(bool subscribe)
        {
            if (subscribe)
            {
                JointStateSubscriber jointStateSubscriber = transform.AddComponentIfNotExists <JointStateSubscriber>();
                jointStateSubscriber.JointStateWriters = new List <JointStateWriter>();
                jointStateSubscriber.JointNames        = new List <string>();

                foreach (UrdfJoint urdfJoint in UrdfRobot.GetComponentsInChildren <UrdfJoint>())
                {
                    if (urdfJoint.JointType != UrdfJoint.JointTypes.Fixed)
                    {
                        jointStateSubscriber.JointStateWriters.Add(urdfJoint.transform.AddComponentIfNotExists <JointStateWriter>());
                        jointStateSubscriber.JointNames.Add(urdfJoint.JointName);
                    }
                }
            }
            else
            {
                GetComponent <JointStateSubscriber>()?.JointStateWriters.Clear();
                GetComponent <JointStateSubscriber>()?.JointNames.Clear();

                foreach (JointStateWriter writer in UrdfRobot.GetComponentsInChildren <JointStateWriter>())
                {
                    writer.transform.DestroyImmediateIfExists <JointStateWriter>();
                }
            }
        }
Ejemplo n.º 2
0
        public void Patch()
        {
            RemoveExistingComponents();

            PatchRigidbodies(EnableRigidbodiesGravity, SetRigidbodiesKinematic);
            PatchMeshColliders(SetMeshCollidersConvex);

            if (AddJointStateReaders)
            {
                JointStatePublisher jointStatePublisher = AddComponentIfNotExists <JointStatePublisher>();
                jointStatePublisher.JointStateReaders = AddJointStateReaderComponents();
            }

            if (AddJointStateWriters)
            {
                JointStateSubscriber jointStateSubscriber = AddComponentIfNotExists <JointStateSubscriber>();
                AddJointStateWriterComponents(out jointStateSubscriber.JointNames, out jointStateSubscriber.JointStateWriters);
            }
        }