/// <summary> /// Reading required element "inertia" from parent "inertial". /// If <paramref name="element"/> != null, required attributes /// "ixx", "ixy", "ixz", "iyy", "iyz" and "izz" are read. /// </summary> /// <param name="element">Required element "inertia".</param> /// <returns>Read "inertia" if <paramref name="element"/> != null, otherwise zero.</returns> public static Inertia Read(XElement element) { float xx = (float)element.Attribute("ixx"); float xy = (float)element.Attribute("ixy"); float xz = (float)element.Attribute("ixz"); float yy = (float)element.Attribute("iyy"); float yz = (float)element.Attribute("iyz"); float zz = (float)element.Attribute("izz"); var inertia = new Inertia(); inertia[0, 0] = xx; inertia[1, 1] = yy; inertia[2, 2] = zz; inertia[0, 1] = xy; inertia[0, 2] = xz; inertia[1, 2] = yz; return(inertia); }
/// <summary> /// Reads optional element "inertial". /// </summary> /// <param name="element">Optional element "inertial" under "link".</param> /// <param name="optional">Unused.</param> public override void Read(XElement element, bool optional = true) { // <origin> is optional. base.Read(element, true); if (element == null) { return; } // <mass> and <inertia> is required if <inertial> exists. Mass = Utils.ReadFloat(element.Element("mass"), "value", false); var inertiaElement = element.Element("inertia"); if (inertiaElement == null) { throw new UrdfIOException($"{Utils.GetLineInfo( element )}: Required element 'inertia' is missing from <inertial>."); } Inertia = Inertia.Read(inertiaElement); }