rofunc.utils.robolab.formatter.mjcf_parser.base#
Base class for all MJCF elements in the object model.
1. Module Contents#
1.1. Classes#
Abstract base class for an MJCF element. |
1.2. API#
- class rofunc.utils.robolab.formatter.mjcf_parser.base.Element[source]#
Abstract base class for an MJCF element.
This class is provided so that isinstance(foo, Element) is True for all Element-like objects. We do not implement the actual element here because the actual object returned from traversing the object hierarchy is a weakproxy-like proxy to an actual element. This is because we do not allow orphaned non-root elements, so when a particular element is removed from the tree, all references held automatically become invalid.
- abstract get_last_modified_stacks_for_all_attributes()[source]#
Gets a dict of stack traces where each attribute was last modified.
- abstract is_same_as(other)[source]#
Checks whether another element is semantically equivalent to this one.
Two elements are considered equivalent if they have the same specification (i.e. same tag appearing in the same context), the same attribute values, and all of their children are equivalent. The ordering of non-repeated children is not important for this comparison, while the ordering of repeated children are important only amongst the same type* of children. In other words, for two bodies to be considered equivalent, their child sites must appear in the same order, and their child geoms must appear in the same order, but permutations between sites and geoms are disregarded. (The only exception is in tendon definition, where strict ordering of all children is necessary for equivalence.)
*Note that the notion of “same type” in this function is very loose: for example different actuator element subtypes are treated as separate types when children ordering is considered. Therefore, two <actuator> elements might be considered equivalent even though they result in different orderings of mjData.ctrl when compiled. As it stands, this function is designed primarily as a testing aid and should not be used to guarantee that models are actually identical.
- Args:
other: An mjcf.Element
- Returns:
True if other element is semantically equivalent to this one.
- abstract property tag#
- abstract property spec#
- abstract property parent#
- abstract property namescope#
- abstract property root#
- abstract property full_identifier#
Fully-qualified identifier used for this element in the generated XML.
- abstract find(namespace, identifier)[source]#
Finds an element with a particular identifier.
This function allows the direct access to an arbitrarily deeply nested child element by name, without the need to manually traverse through the object tree. The namespace argument specifies the kind of element to find. In most cases, this corresponds to the element’s XML tag name. However, if an element has multiple specialized tags, then the namespace corresponds to the tag name of the most general element of that kind. For example, namespace=’joint’ would search for <joint> and <freejoint>, while namespace=’actuator’ would search for <general>, <motor>, <position>, <velocity>, and <cylinder>.
- Args:
- namespace: A string specifying the namespace being searched. See the
docstring above for explanation.
identifier: The identifier string of the desired element.
- Returns:
An mjcf.Element object, or None if an element with the specified identifier is not found.
- Raises:
- ValueError: if either namespace or identifier is not a string, or if
namespace is not a valid namespace.
- abstract find_all(namespace, immediate_children_only=False, exclude_attachments=False)[source]#
Finds all elements of a particular kind.
The namespace argument specifies the kind of element to find. In most cases, this corresponds to the element’s XML tag name. However, if an element has multiple specialized tags, then the namespace corresponds to the tag name of the most general element of that kind. For example, namespace=’joint’ would search for <joint> and <freejoint>, while namespace=’actuator’ would search for <general>, <motor>, <position>, <velocity>, and <cylinder>.
- Args:
- namespace: A string specifying the namespace being searched. See the
docstring above for explanation.
- immediate_children_only: (optional) A boolean, if True then only
the immediate children of this element are returned.
- exclude_attachments: (optional) A boolean, if True then elements
belonging to attached models are excluded.
- Returns:
A list of mjcf.Element.
- Raises:
ValueError: if namespace is not a valid namespace.
- abstract enter_scope(scope_identifier)[source]#
Finds the root element of the given scope and returns it.
This function allows the access to a nested scope that is a child of this element. The scope_identifier argument specifies the path to the child scope element.
- Args:
scope_identifier: The path of the desired scope element.
- Returns:
An mjcf.Element object, or None if a scope element with the specified path is not found.
- abstract add(element_name, **kwargs)[source]#
Add a new child element to this element.
- Args:
element_name: The tag of the element to add. **kwargs: Attributes of the new element being created.
- Raises:
- ValueError: If the ‘element_name’ is not a valid child, or if an invalid
attribute is specified in kwargs.
- Returns:
An mjcf.Element corresponding to the newly created child element.
- abstract property is_removed#
- abstract to_xml(prefix_root=None, debug_context=None, *, precision=constants.XML_DEFAULT_PRECISION, zero_threshold=0)[source]#
Generates an etree._Element corresponding to this MJCF element.
- Args:
- prefix_root: (optional) A NameScope object to be treated as root
for the purpose of calculating the prefix. If None then no prefix is included.
- debug_context: (optional) A debugging.DebugContext object to which
the debugging information associated with the generated XML is written. This is intended for internal use within PyMJCF; users should never need manually pass this argument.
- precision: (optional) Number of digits to output for floating point
quantities.
- zero_threshold: (optional) When outputting XML, floating point quantities
whose absolute value falls below this threshold will be treated as zero.
- Returns:
An etree._Element object.
- abstract to_xml_string(prefix_root=None, self_only=False, pretty_print=True, debug_context=None, *, precision=constants.XML_DEFAULT_PRECISION, zero_threshold=0)[source]#
Generates an XML string corresponding to this MJCF element.
- Args:
- prefix_root: (optional) A NameScope object to be treated as root
for the purpose of calculating the prefix. If None then no prefix is included.
- self_only: (optional) A boolean, whether to generate an XML corresponding
only to this element without any children.
- pretty_print: (optional) A boolean, whether to the XML string should be
properly indented.
- debug_context: (optional) A debugging.DebugContext object to which
the debugging information associated with the generated XML is written. This is intended for internal use within PyMJCF; users should never need manually pass this argument.
- precision: (optional) Number of digits to output for floating point
quantities.
- zero_threshold: (optional) When outputting XML, floating point quantities
whose absolute value falls below this threshold will be treated as zero.
- Returns:
A string.