private static void ImportLinkData(this UrdfLink urdfLink, Link link, Joint joint)
        {
            if (link.inertial == null && joint == null)
            {
                urdfLink.IsBaseLink = true;
            }
            urdfLink.gameObject.name = link.name;
            if (joint?.origin != null)
            {
                UrdfOrigin.ImportOriginData(urdfLink.transform, joint.origin);
            }

            if (link.inertial != null)
            {
                UrdfInertial.Create(urdfLink.gameObject, link.inertial);

                if (joint != null)
                {
                    UrdfJoint.Create(urdfLink.gameObject, UrdfJoint.GetJointType(joint.type), joint);
                }
            }
            else if (joint != null)
            {
                UrdfJoint.Create(urdfLink.gameObject, UrdfJoint.GetJointType(joint.type), joint);
            }
        }
        private static Robot ExportRobotData(this UrdfRobot urdfRobot)
        {
#if UNITY_EDITOR
            Robot robot = new Robot(urdfRobot.FilePath, urdfRobot.gameObject.name);

            List <string> linkNames = new List <string>();

            foreach (UrdfLink urdfLink in urdfRobot.GetComponentsInChildren <UrdfLink>())
            {
                //Link export
                if (linkNames.Contains(urdfLink.name))
                {
                    EditorUtility.DisplayDialog("URDF Export Error",
                                                "URDF export failed. There are several links with the name " +
                                                urdfLink.name + ". Make sure all link names are unique before exporting this robot.",
                                                "Ok");
                    return(null);
                }
                robot.links.Add(urdfLink.ExportLinkData());
                linkNames.Add(urdfLink.name);

                //Joint export
                UrdfJoint urdfJoint = urdfLink.gameObject.GetComponent <UrdfJoint>();
                if (urdfJoint != null)
                {
                    robot.joints.Add(urdfJoint.ExportJointData());
                }
                else if (!urdfLink.IsBaseLink)
                {
                    //Make sure that links with no rigidbodies are still connected to the robot by a default joint
                    robot.joints.Add(UrdfJoint.ExportDefaultJoint(urdfLink.transform));
                }
            }

            robot.materials = UrdfMaterial.Materials.Values.ToList();
            robot.plugins   = urdfRobot.GetComponentInChildren <UrdfPlugins>().ExportPluginsData();

            return(robot);
#else
            Debug.LogError("URDF Export is only available in Editor.");
            return(null);
#endif
        }
Ejemplo n.º 3
0
        public static UrdfJoint Create(GameObject linkObject, JointTypes jointType, Joint joint = null)
        {
#if UNITY_2020_1_OR_NEWER
#else
            Rigidbody parentRigidbody = linkObject.transform.parent.gameObject.GetComponent <Rigidbody>();
            if (parentRigidbody == null)
            {
                return;
            }
#endif
            UrdfJoint urdfJoint = AddCorrectJointType(linkObject, jointType);

            if (joint != null)
            {
                urdfJoint.jointName = joint.name;
                urdfJoint.ImportJointData(joint);
            }
            return(urdfJoint);
        }
Ejemplo n.º 4
0
        private static UrdfJoint AddCorrectJointType(GameObject linkObject, JointTypes jointType)
        {
            UrdfJoint urdfJoint = null;

            switch (jointType)
            {
            case JointTypes.Fixed:
                urdfJoint = UrdfJointFixed.Create(linkObject);
                break;

            case JointTypes.Continuous:
                urdfJoint = UrdfJointContinuous.Create(linkObject);
                break;

            case JointTypes.Revolute:
                urdfJoint = UrdfJointRevolute.Create(linkObject);
                break;

            case JointTypes.Floating:
                urdfJoint = UrdfJointFloating.Create(linkObject);
                break;

            case JointTypes.Prismatic:
                urdfJoint = UrdfJointPrismatic.Create(linkObject);
                break;

            case JointTypes.Planar:
                urdfJoint = UrdfJointPlanar.Create(linkObject);
                break;
            }


#if UNITY_2020_1_OR_NEWER
#else
            UnityEngine.Joint unityJoint = linkObject.GetComponent <UnityEngine.Joint>();
            unityJoint.connectedBody = linkObject.transform.parent.gameObject.GetComponent <Rigidbody>();
            unityJoint.autoConfigureConnectedAnchor = true;
#endif

            return(urdfJoint);
        }