Пример #1
0
        /// <summary>
        /// Compares the current devices in the scene with the urdf file and performs adjustments
        /// </summary>
        /// <param name="urdf"></param>
        public void SynchUrdf(string urdf)
        {
            ReportSynch();

            Robot robot = Robot.FromContent(urdf);

            foreach (var c in robot.attachedComponents)
            {
                if (c.component is AttachedDataValue av && String.IsNullOrEmpty(av.topic))
                {
                    av.topic = "/img/joint_position";
                }
            }


            if (!hasUrdfAssetsImported)
            {
                ImportInitialUrdfModel(robot);
                return;
            }

            //we do not return here since we want to apply any possible changes that were passed in the last urdf update.

            RobotBuilder builder = new RobotBuilder();

            builder.Synchronize(robot, RobotRootObject);

            synchronizationCounterWithoutFullRegeneration++;
        }
Пример #2
0
        /// <summary>
        /// Imports the URDF Model initially to download all textures, assets and store them correctly etc.
        /// </summary>
        /// <param name="robot"></param>
        private void ImportInitialUrdfModel(Robot robot)
        {
            hasUrdfAssetsImported = false;

            if (RobotRootObject == null)
            {
                RobotRootObject      = GameObject.Instantiate(RobotPrefab);
                RobotRootObject.name = RobotName;
            }

            RobotBuilder builder = new RobotBuilder();

            builder.Synchronize(robot, RobotRootObject);

            if (!useUnityPhysics)
            {
                foreach (Rigidbody rb in RobotRootObject.GetComponentsInChildren <Rigidbody>())
                {
                    rb.isKinematic = true;
                }
            }

            //Attach a joint state subscriber that subscribes all joints to the state published by Gazebo or another source
            RosConnector.gameObject.AddComponentIfNotExists <JointStateSubscriber>(out var jointStateSubscriber);

            jointStateSubscriber.Topic             = @"/joint_states";
            jointStateSubscriber.JointStateWriters = new List <JointStateWriter>();
            jointStateSubscriber.JointNames        = new List <string>();
            foreach (UrdfJoint urdfJoint in RobotRootObject.GetComponentsInChildren <UrdfJoint>())
            {
                if (urdfJoint.JointType != UrdfJoint.JointTypes.Fixed)
                {
                    urdfJoint.gameObject.AddComponentIfNotExists <JointStateWriter>(out var writer);
                    jointStateSubscriber.JointStateWriters.Add(writer);
                    jointStateSubscriber.JointNames.Add(urdfJoint.JointName);
                }
            }

            if (SceneContainerGameObject != null)
            {
                RobotRootObject.transform.SetParent(SceneContainerGameObject.transform);
            }

            hasUrdfAssetsImported = true;
        }