Skip to content

Commit c28b343

Browse files
committed
♻️ refactor: change json format structure
1 parent f0da5d9 commit c28b343

Some content is hidden

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

44 files changed

+904
-809
lines changed

Diff for: convert.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,8 @@ def create_markdown_table(joints: List[Joint]) -> str:
4444
force_limits = "N/A"
4545

4646
if joint.limits:
47-
if "angle_lower" in joint.limits and "angle_upper" in joint.limits:
48-
position_limits = (
49-
f"{joint.limits['angle_lower']} to {joint.limits['angle_upper']}"
50-
)
51-
if "force_lower" in joint.limits and "force_upper" in joint.limits:
52-
force_limits = (
53-
f"{joint.limits['force_lower']} to {joint.limits['force_upper']}"
54-
)
47+
position_limits = f"{joint.limits['angle']}"
48+
force_limits = f"{joint.limits['force']}"
5549

5650
row = [
5751
str(joint.index),

Diff for: engineai/sa01/leg/desc/zq_sa01_xml_config.json

+1-132
Original file line numberDiff line numberDiff line change
@@ -1,132 +1 @@
1-
{
2-
"format": "mjcf",
3-
"joints": {
4-
"root": {
5-
"joint_type": "free",
6-
"index": 0,
7-
"limits": {},
8-
"parent": null,
9-
"child": null
10-
},
11-
"leg_l1_joint": {
12-
"joint_type": "hinge",
13-
"index": 1,
14-
"limits": {
15-
"angle_lower": -0.523,
16-
"angle_upper": 0.523
17-
},
18-
"parent": null,
19-
"child": null
20-
},
21-
"leg_l2_joint": {
22-
"joint_type": "hinge",
23-
"index": 2,
24-
"limits": {
25-
"angle_lower": -0.3,
26-
"angle_upper": 0.3
27-
},
28-
"parent": null,
29-
"child": null
30-
},
31-
"leg_l3_joint": {
32-
"joint_type": "hinge",
33-
"index": 3,
34-
"limits": {
35-
"angle_lower": -1.204,
36-
"angle_upper": 1.204
37-
},
38-
"parent": null,
39-
"child": null
40-
},
41-
"leg_l4_joint": {
42-
"joint_type": "hinge",
43-
"index": 4,
44-
"limits": {
45-
"angle_lower": -0.15,
46-
"angle_upper": 2.268
47-
},
48-
"parent": null,
49-
"child": null
50-
},
51-
"leg_l5_joint": {
52-
"joint_type": "hinge",
53-
"index": 5,
54-
"limits": {
55-
"angle_lower": -1.0,
56-
"angle_upper": 0.6
57-
},
58-
"parent": null,
59-
"child": null
60-
},
61-
"leg_l6_joint": {
62-
"joint_type": "hinge",
63-
"index": 6,
64-
"limits": {
65-
"angle_lower": -0.6,
66-
"angle_upper": 0.6
67-
},
68-
"parent": null,
69-
"child": null
70-
},
71-
"leg_r1_joint": {
72-
"joint_type": "hinge",
73-
"index": 7,
74-
"limits": {
75-
"angle_lower": -0.523,
76-
"angle_upper": 0.523
77-
},
78-
"parent": null,
79-
"child": null
80-
},
81-
"leg_r2_joint": {
82-
"joint_type": "hinge",
83-
"index": 8,
84-
"limits": {
85-
"angle_lower": -0.3,
86-
"angle_upper": 0.3
87-
},
88-
"parent": null,
89-
"child": null
90-
},
91-
"leg_r3_joint": {
92-
"joint_type": "hinge",
93-
"index": 9,
94-
"limits": {
95-
"angle_lower": -1.204,
96-
"angle_upper": 1.204
97-
},
98-
"parent": null,
99-
"child": null
100-
},
101-
"leg_r4_joint": {
102-
"joint_type": "hinge",
103-
"index": 10,
104-
"limits": {
105-
"angle_lower": -0.15,
106-
"angle_upper": 2.268
107-
},
108-
"parent": null,
109-
"child": null
110-
},
111-
"leg_r5_joint": {
112-
"joint_type": "hinge",
113-
"index": 11,
114-
"limits": {
115-
"angle_lower": -1.0,
116-
"angle_upper": 0.6
117-
},
118-
"parent": null,
119-
"child": null
120-
},
121-
"leg_r6_joint": {
122-
"joint_type": "hinge",
123-
"index": 12,
124-
"limits": {
125-
"angle_lower": -0.6,
126-
"angle_upper": 0.6
127-
},
128-
"parent": null,
129-
"child": null
130-
}
131-
}
132-
}
1+
{"format": "mjcf", "joints": {"root": {"joint_type": "free", "index": 0, "limits": {"angle": [], "force": []}, "parent": null, "child": null}, "leg_l1_joint": {"joint_type": "hinge", "index": 1, "limits": {"angle": [-0.523, 0.523], "force": []}, "parent": null, "child": null}, "leg_l2_joint": {"joint_type": "hinge", "index": 2, "limits": {"angle": [-0.3, 0.3], "force": []}, "parent": null, "child": null}, "leg_l3_joint": {"joint_type": "hinge", "index": 3, "limits": {"angle": [-1.204, 1.204], "force": []}, "parent": null, "child": null}, "leg_l4_joint": {"joint_type": "hinge", "index": 4, "limits": {"angle": [-0.15, 2.268], "force": []}, "parent": null, "child": null}, "leg_l5_joint": {"joint_type": "hinge", "index": 5, "limits": {"angle": [-1.0, 0.6], "force": []}, "parent": null, "child": null}, "leg_l6_joint": {"joint_type": "hinge", "index": 6, "limits": {"angle": [-0.6, 0.6], "force": []}, "parent": null, "child": null}, "leg_r1_joint": {"joint_type": "hinge", "index": 7, "limits": {"angle": [-0.523, 0.523], "force": []}, "parent": null, "child": null}, "leg_r2_joint": {"joint_type": "hinge", "index": 8, "limits": {"angle": [-0.3, 0.3], "force": []}, "parent": null, "child": null}, "leg_r3_joint": {"joint_type": "hinge", "index": 9, "limits": {"angle": [-1.204, 1.204], "force": []}, "parent": null, "child": null}, "leg_r4_joint": {"joint_type": "hinge", "index": 10, "limits": {"angle": [-0.15, 2.268], "force": []}, "parent": null, "child": null}, "leg_r5_joint": {"joint_type": "hinge", "index": 11, "limits": {"angle": [-1.0, 0.6], "force": []}, "parent": null, "child": null}, "leg_r6_joint": {"joint_type": "hinge", "index": 12, "limits": {"angle": [-0.6, 0.6], "force": []}, "parent": null, "child": null}}}

Diff for: engineai/sa01/leg/desc/zq_sa01_xml_config.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
| Index | Name | Type | Parent | Child | Angle Limits | Force Limits |
66
|---|---|---|---|---|---|---|
77
| 0 | root | free | N/A | N/A | N/A | N/A |
8-
| 1 | leg_l1_joint | hinge | N/A | N/A | -0.523 to 0.523 | N/A |
9-
| 2 | leg_l2_joint | hinge | N/A | N/A | -0.3 to 0.3 | N/A |
10-
| 3 | leg_l3_joint | hinge | N/A | N/A | -1.204 to 1.204 | N/A |
11-
| 4 | leg_l4_joint | hinge | N/A | N/A | -0.15 to 2.268 | N/A |
12-
| 5 | leg_l5_joint | hinge | N/A | N/A | -1.0 to 0.6 | N/A |
13-
| 6 | leg_l6_joint | hinge | N/A | N/A | -0.6 to 0.6 | N/A |
14-
| 7 | leg_r1_joint | hinge | N/A | N/A | -0.523 to 0.523 | N/A |
15-
| 8 | leg_r2_joint | hinge | N/A | N/A | -0.3 to 0.3 | N/A |
16-
| 9 | leg_r3_joint | hinge | N/A | N/A | -1.204 to 1.204 | N/A |
17-
| 10 | leg_r4_joint | hinge | N/A | N/A | -0.15 to 2.268 | N/A |
18-
| 11 | leg_r5_joint | hinge | N/A | N/A | -1.0 to 0.6 | N/A |
19-
| 12 | leg_r6_joint | hinge | N/A | N/A | -0.6 to 0.6 | N/A |
8+
| 1 | leg_l1_joint | hinge | N/A | N/A | N/A | N/A |
9+
| 2 | leg_l2_joint | hinge | N/A | N/A | N/A | N/A |
10+
| 3 | leg_l3_joint | hinge | N/A | N/A | N/A | N/A |
11+
| 4 | leg_l4_joint | hinge | N/A | N/A | N/A | N/A |
12+
| 5 | leg_l5_joint | hinge | N/A | N/A | N/A | N/A |
13+
| 6 | leg_l6_joint | hinge | N/A | N/A | N/A | N/A |
14+
| 7 | leg_r1_joint | hinge | N/A | N/A | N/A | N/A |
15+
| 8 | leg_r2_joint | hinge | N/A | N/A | N/A | N/A |
16+
| 9 | leg_r3_joint | hinge | N/A | N/A | N/A | N/A |
17+
| 10 | leg_r4_joint | hinge | N/A | N/A | N/A | N/A |
18+
| 11 | leg_r5_joint | hinge | N/A | N/A | N/A | N/A |
19+
| 12 | leg_r6_joint | hinge | N/A | N/A | N/A | N/A |

Diff for: parser.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,25 @@ def parse_joints(self) -> List[Joint]:
4545

4646
if self.format == "urdf":
4747
for idx, joint in enumerate(self.root.findall(".//joint")):
48-
limits = {}
48+
limits = {
49+
"angle": [],
50+
"force": [],
51+
}
4952
limit_elem = joint.find("limit")
5053
if limit_elem is not None:
5154
for attr in ["lower", "upper", "effort"]:
5255
if attr in limit_elem.attrib:
5356
if attr == "lower":
54-
limits["angle_lower"] = float(limit_elem.attrib[attr])
57+
limits["angle"].append(float(limit_elem.attrib[attr]))
5558

5659
if attr == "upper":
57-
limits["angle_upper"] = float(limit_elem.attrib[attr])
60+
limits["angle"].append(float(limit_elem.attrib[attr]))
5861

5962
if attr == "effort":
60-
limits["force_lower"] = -float(limit_elem.attrib[attr])
61-
limits["force_upper"] = float(limit_elem.attrib[attr])
63+
limits["force"] = [
64+
-float(limit_elem.attrib[attr]),
65+
float(limit_elem.attrib[attr]),
66+
]
6267

6368
parent = joint.find("parent").attrib["link"]
6469
child = joint.find("child").attrib["link"]
@@ -76,18 +81,17 @@ def parse_joints(self) -> List[Joint]:
7681

7782
elif self.format == "mjcf":
7883
for idx, joint in enumerate(self.root.findall(".//joint")):
79-
limits = {}
84+
limits = {
85+
"angle": [],
86+
"force": [],
87+
}
8088
if "range" in joint.attrib:
81-
range_values = [float(x) for x in joint.attrib["range"].split()]
82-
limits["angle_lower"] = range_values[0]
83-
limits["angle_upper"] = range_values[1]
89+
limits["angle"] = [float(x) for x in joint.attrib["range"].split()]
8490

8591
if "actuatorfrcrange" in joint.attrib:
86-
range_values = [
92+
limits["force"] = [
8793
float(x) for x in joint.attrib["actuatorfrcrange"].split()
8894
]
89-
limits["force_lower"] = range_values[0]
90-
limits["force_upper"] = range_values[1]
9195

9296
joints.append(
9397
Joint(

0 commit comments

Comments
 (0)