Beispiel #1
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;
            }

            UnityEngine.Joint unityJoint = linkObject.GetComponent<UnityEngine.Joint>();
            unityJoint.connectedBody = linkObject.transform.parent.gameObject.GetComponent<Rigidbody>();
            unityJoint.autoConfigureConnectedAnchor = true;

            return urdfJoint;
        }
Beispiel #2
0
        private void ImportLinkData(Link link, Joint joint)
        {
            if (link.inertial == null && joint == null)
            {
                isBaseLink = true;
            }

            gameObject.name = link.name;

            if (joint?.origin != null)
            {
                UrdfOrigin.ImportOriginData(transform, joint.origin);
            }

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

                if (joint != null)
                {
                    UrdfJoint.Create(gameObject, UrdfJoint.GetJointType(joint.type), joint);
                }
            }
            else if (joint != null)
            {
                Debug.LogWarning("No Joint Component will be created in GameObject \"" + gameObject.name + "\" as it has no Rigidbody Component.\n"
                                 + "Please define an Inertial for Link \"" + link.name + "\" in the URDF file to create a Rigidbody Component.\n", gameObject);
            }

            foreach (Joint childJoint in link.joints)
            {
                Link child = childJoint.ChildLink;
                UrdfLink.Create(transform, child, childJoint);
            }
        }
Beispiel #3
0
        public static void Create(GameObject linkObject, JointTypes jointType, Joint joint = null)
        {
            Rigidbody parentRigidbody = linkObject.transform.parent.gameObject.GetComponent<Rigidbody>();
            if (parentRigidbody == null) return;

            UrdfJoint urdfJoint = AddCorrectJointType(linkObject, jointType);

            if (joint != null)
            {
                urdfJoint.JointName = joint.name;
                urdfJoint.ImportJointData(joint);
            }
        }
Beispiel #4
0
        public static void Create(GameObject linkObject, JointTypes jointType, Joint joint = null)
        {
            #if UNITY_2020_1_OR_NEWER
            //ArticulationBody parentRigidbody = linkObject.transform.parent.gameObject.GetComponent<ArticulationBody>();
#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);
            }
        }
Beispiel #5
0
        private Robot ExportRobotData()
        {
            Robot robot = new Robot(filePath, gameObject.name);

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

            foreach (UrdfLink urdfLink in gameObject.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   = GetComponentInChildren <UrdfPlugins>().ExportPluginsData();

            return(robot);
        }
Beispiel #6
0
        private static UrdfJoint AddCorrectJointType(GameObject linkObject, JointTypes jointType)
        {
            UrdfJoint urdfJoint = null;

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

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

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

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

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

            case JointTypes.Planar:
                urdfJoint = UrdfJointPlanar.Synchronize(linkObject);
                break;
            }
            //SynchTodo: This assignment probably does not break stuff, but is not necessary.
            UnityEngine.Joint unityJoint = linkObject.GetComponent <UnityEngine.Joint>();
            unityJoint.connectedBody = linkObject.transform.parent.gameObject.GetComponent <Rigidbody>();
            unityJoint.autoConfigureConnectedAnchor = true;

            return(urdfJoint);
        }