Skip to content

Commit 8a94d95

Browse files
committed
refactor(assets): restructure assets folder
- restructure assets: clearer structure and only contain absolute minimum for RCS examples - updated actuators in so101 - reset ur5e, fr3 and panda to original menagerie xml - added gravcomp script that can add and remove gravity compensation - removed gravity compensation of all xmls as this will be done in the composer
1 parent 66d4988 commit 8a94d95

593 files changed

Lines changed: 1044 additions & 3331027 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assets/add_gravcomp.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
5+
import argparse
6+
import xml.etree.ElementTree as ET
7+
from pathlib import Path
8+
9+
10+
def local_name(tag: object) -> str | None:
11+
if not isinstance(tag, str):
12+
return None
13+
if "}" in tag:
14+
return tag.rsplit("}", 1)[1]
15+
return tag
16+
17+
18+
def update_mjcf(root: ET.Element, force: bool, remove: bool) -> tuple[int, int]:
19+
body_count = 0
20+
joint_count = 0
21+
22+
for elem in root.iter():
23+
tag = local_name(elem.tag)
24+
if tag is None:
25+
continue
26+
27+
if remove:
28+
if tag == "body" and "gravcomp" in elem.attrib:
29+
del elem.attrib["gravcomp"]
30+
body_count += 1
31+
32+
if tag == "joint" and "actuatorgravcomp" in elem.attrib:
33+
del elem.attrib["actuatorgravcomp"]
34+
joint_count += 1
35+
continue
36+
37+
if tag == "body" and (force or "gravcomp" not in elem.attrib):
38+
elem.set("gravcomp", "1")
39+
body_count += 1
40+
41+
if tag == "joint" and (force or "actuatorgravcomp" not in elem.attrib):
42+
elem.set("actuatorgravcomp", "true")
43+
joint_count += 1
44+
45+
return body_count, joint_count
46+
47+
48+
def main() -> None:
49+
parser = argparse.ArgumentParser(
50+
description="Add gravcomp attributes to all MJCF <body> and <joint> tags."
51+
)
52+
parser.add_argument("input_xml", type=Path, help="Path to the input MJCF XML file.")
53+
parser.add_argument(
54+
"-o",
55+
"--output",
56+
type=Path,
57+
help="Optional output path. If omitted, the input file is updated in place.",
58+
)
59+
parser.add_argument(
60+
"--force",
61+
action="store_true",
62+
help="Overwrite existing gravcomp / actuatorgravcomp attributes.",
63+
)
64+
parser.add_argument(
65+
"--remove",
66+
action="store_true",
67+
help="Remove existing gravcomp / actuatorgravcomp attributes instead of adding them.",
68+
)
69+
args = parser.parse_args()
70+
71+
parser = ET.XMLParser(target=ET.TreeBuilder(insert_comments=True))
72+
tree = ET.parse(args.input_xml, parser=parser)
73+
root = tree.getroot()
74+
75+
body_count, joint_count = update_mjcf(
76+
root,
77+
force=args.force,
78+
remove=args.remove,
79+
)
80+
ET.indent(tree, space=" ")
81+
82+
output_path = args.output or args.input_xml
83+
tree.write(output_path, encoding="utf-8", xml_declaration=False)
84+
85+
action = "Removed" if args.remove else "Updated"
86+
print(f"{action} {body_count} body tag(s) and {joint_count} joint tag(s) in {output_path}")
87+
88+
89+
if __name__ == "__main__":
90+
main()

assets/cameras/real_sense/mjcf/d435i.xml

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)