Skip to content

Commit 2472377

Browse files
author
nuofan
committed
Add support for urdf_plus
1 parent 91ca98b commit 2472377

File tree

8 files changed

+741
-2
lines changed

8 files changed

+741
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.DS_Store
2+
.vscode

Add-IN/ACDC4Robot/commands/ACDC4Robot/acdc4robot.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from . import constants
1212
from ...core import write
1313
from ...core import utils
14+
from ...core.robot import Robot
15+
from ...core.urdf_plus import URDF_PLUS
1416
import time
1517

1618
def get_link_joint_list(design: adsk.fusion.Design):
@@ -244,6 +246,16 @@ def run():
244246
time.sleep(0.1)
245247
ui.messageBox("Finished exporting MJCF for MuJoCo.", msg_box_title)
246248

249+
elif rdf == "URDF+":
250+
robot = Robot(design)
251+
urdf_plus = URDF_PLUS(robot)
252+
urdf_plus_path = save_folder + "/{}.urdf".format(robot.get_robot_name())
253+
urdf_plus.write_file(urdf_plus_path)
254+
stl_list: list[Link] = robot.get_links()
255+
export_stl(design, save_folder, stl_list)
256+
time.sleep(0.1)
257+
ui.messageBox("Finished exporting URDF+.", msg_box_title)
258+
247259
except:
248260
if ui:
249261
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Add-IN/ACDC4Robot/commands/ACDC4Robot/entry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def command_created(args: adsk.core.CommandCreatedEventArgs):
8787
rdf_items.add("URDF", False)
8888
rdf_items.add("SDFormat", False)
8989
rdf_items.add("MJCF", False)
90+
rdf_items.add("URDF+", False)
9091

9192
# create a drop down command input to choose simulation environment
9293
sim_env_input = inputs.addDropDownCommandInput("simulation_env", "Simulation Environment", adsk.core.DropDownStyles.LabeledIconDropDownStyle)

Add-IN/ACDC4Robot/core/link.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def get_parent_joint(self) -> adsk.fusion.Joint:
6565
6666
Return:
6767
j: parent_joints
68-
6968
"""
7069
# TODO: in closed loop mechanism, there exits one assembly method that
7170
# make one link have two parent joint, write a instruction or fix this bug

Add-IN/ACDC4Robot/core/robot.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# -*- coding: utf-8 -*-
2+
from typing import List, Tuple
3+
import adsk, adsk.fusion, adsk.core
4+
from .link import Link
5+
from .joint import Joint
6+
7+
class Robot():
8+
"""
9+
Store robot link joint information into a bigraph structure
10+
"""
11+
12+
def __init__(self, robot: adsk.fusion.Design):
13+
self.robot = robot
14+
self.rootComp = robot.rootComponent
15+
self.name = self.get_robot_name()
16+
self.nodes = self.get_links()
17+
self.edges = self.get_joints()
18+
self.loop_joints, self.tree_joints = self.seperate_joints(self.edges)
19+
20+
def get_robot_name(self, ) -> str:
21+
"""
22+
Robot name is the root component name
23+
"""
24+
robot_name = self.rootComp.name.split()[0]
25+
return robot_name
26+
27+
def get_links(self, ) -> List[Link]:
28+
link_list = []
29+
occs: adsk.fusion.OccurrenceList = self.rootComp.allOccurrences
30+
31+
# try to solve the nested components problem
32+
# but still not fully tested
33+
for occ in occs:
34+
# TODO: it seems use occ.joints.count will make it usable with occurrences? Test it
35+
if occ.component.joints.count > 0:
36+
# textPalette.writeText(str(occ.fullPathName))
37+
continue
38+
else:
39+
# Only occurrence contains zero joint and has zero childOccurrences
40+
# can be seen as a link
41+
if occ.childOccurrences.count > 0:
42+
# textPalette.writeText(str(occ.fullPathName))
43+
# textPalette.writeText(str(occ.childOccurrences.count))
44+
continue
45+
else:
46+
# textPalette.writeText(str(occ.fullPathName))
47+
# textPalette.writeText(str(occ.childOccurrences.count))
48+
if occ.isLightBulbOn:
49+
# only the occurrence light bulb on that the occurrence will be exported
50+
link_list.append(Link(occ)) # add link objects into link_list
51+
52+
return link_list
53+
54+
def get_joints(self, ) -> List[Joint]:
55+
joint_list = []
56+
57+
for joint in self.rootComp.allJoints:
58+
joint_list.append(Joint(joint)) # add joint objects into joint_list
59+
60+
return joint_list
61+
62+
def get_loop_joints(self,) -> List[Joint]:
63+
return self.loop_joints
64+
65+
def get_tree_joints(self, ) -> List[Joint]:
66+
return self.tree_joints
67+
68+
69+
def get_graph(self, ):
70+
pass
71+
72+
def seperate_joints(self, joint_list: List[Joint]) -> Tuple[List[Joint], List[Joint]]:
73+
"""
74+
Seperate robot joints into two parts: loop joints, tree joints
75+
76+
Returns:
77+
loop_joints: List[Joint]
78+
joints construct closed loop
79+
it should be noted by user explicitly by name it with prefix "loop"
80+
tree_joints: List[Joint]
81+
edges connects nodes(links) like a spanning tree
82+
"""
83+
loop_joints = []
84+
tree_joints = []
85+
for joint in joint_list:
86+
if joint.name.startswith("loop"):
87+
loop_joints.append(joint)
88+
else:
89+
tree_joints.append(joint)
90+
return loop_joints, tree_joints
91+
92+
def is_connected_graph(self, ):
93+
pass

0 commit comments

Comments
 (0)