Example #1
0
        /// <summary>
        /// Reads element "joint" with required attributes "name" and "type".
        /// </summary>
        /// <param name="element">Optional element "joint".</param>
        /// <param name="optional">Unused.</param>
        public override void Read(XElement element, bool optional = true)
        {
            if (element == null)
            {
                return;
            }

            base.Read(element, false);
            var type = Utils.ReadString(element, "type", false);

            Type = type == "revolute" ?
                   JointType.Revolute :
                   type == "continuous" ?
                   JointType.Continuous :
                   type == "prismatic" ?
                   JointType.Prismatic :
                   type == "fixed" ?
                   JointType.Fixed:
                   type == "planar" ?
                   JointType.Planar :
                   JointType.Unknown;
            if (Type == JointType.Unknown)
            {
                throw new UrdfIOException($"{Utils.GetLineInfo( element )}: Unknown joint type '{type}'.");
            }

            Parent = Utils.ReadString(element.Element("parent"), "link", false);
            Child  = Utils.ReadString(element.Element("child"), "link", false);

            if (element.Element("axis") != null)
            {
                Axis = Utils.ReadVector3(element.Element("axis"), "xyz", false);
            }

            Calibration      = CalibrationData.ReadOptional(element);
            Dynamics         = DynamicsData.ReadOptional(element);
            Limit            = LimitData.Read(element, type != "revolute" && type != "prismatic");
            Mimic            = MimicData.ReadOptional(element);
            SafetyController = SafetyControllerData.ReadOptional(element);
        }