-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added convenience function to export a robot class straight from an O…
…nshape URL. Added RoboType enum to split execution flow: MJCF and URDF exports.
- Loading branch information
1 parent
6841599
commit df05b59
Showing
10 changed files
with
253 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,45 @@ | ||
import onshape_api as osa | ||
from onshape_api.connect import Client | ||
from onshape_api.graph import create_graph, plot_graph | ||
from onshape_api.models.robot import Robot | ||
from onshape_api.log import LOGGER, LogLevel | ||
from onshape_api.models.document import Document | ||
from onshape_api.parse import ( | ||
get_instances, | ||
get_mates_and_relations, | ||
get_occurrences, | ||
get_parts, | ||
get_subassemblies, | ||
) | ||
from onshape_api.robot import Robot | ||
from onshape_api.urdf import get_urdf_components | ||
|
||
# Initialize the client with the constructed path | ||
client = osa.Client() | ||
doc = osa.Document.from_url( | ||
url="https://cad.onshape.com/documents/a1c1addf75444f54b504f25c/w/0d17b8ebb2a4c76be9fff3c7/e/a86aaf34d2f4353288df8812" | ||
) | ||
if __name__ == "__main__": | ||
LOGGER.set_file_name("edit.log") | ||
LOGGER.set_stream_level(LogLevel.INFO) | ||
|
||
elements = client.get_elements(doc.did, doc.wtype, doc.wid) | ||
variables = client.get_variables(doc.did, doc.wid, elements["variables"].id) | ||
|
||
variables["wheelDiameter"].expression = "180 mm" | ||
variables["wheelThickness"].expression = "71 mm" | ||
variables["forkAngle"].expression = "20 deg" | ||
|
||
client.set_variables(doc.did, doc.wid, elements["variables"].id, variables) | ||
assembly, _ = client.get_assembly(doc.did, doc.wtype, doc.wid, elements["assembly"].id) | ||
|
||
instances, id_to_name_map = get_instances(assembly) | ||
occurrences = get_occurrences(assembly, id_to_name_map) | ||
parts = get_parts(assembly, client, instances) | ||
subassemblies, rigid_subassemblies = get_subassemblies(assembly, client, instances) | ||
mates, relations = get_mates_and_relations( | ||
assembly=assembly, | ||
subassembly_map=subassemblies, | ||
rigid_subassembly_map=rigid_subassemblies, | ||
id_to_name_map=id_to_name_map, | ||
parts=parts, | ||
) | ||
client = Client() | ||
doc = Document.from_url( | ||
url="https://cad.onshape.com/documents/a1c1addf75444f54b504f25c/w/0d17b8ebb2a4c76be9fff3c7/e/a86aaf34d2f4353288df8812" | ||
) | ||
|
||
elements = client.get_elements(doc.did, doc.wtype, doc.wid) | ||
variables = client.get_variables(doc.did, doc.wid, elements["variables"].id) | ||
|
||
variables["wheelDiameter"].expression = "180 mm" | ||
variables["wheelThickness"].expression = "71 mm" | ||
variables["forkAngle"].expression = "20 deg" | ||
|
||
client.set_variables(doc.did, doc.wid, elements["variables"].id, variables) | ||
assembly = client.get_assembly(doc.did, doc.wtype, doc.wid, elements["assembly"].id) | ||
|
||
instances, occurrences, id_to_name_map = get_instances(assembly) | ||
|
||
subassemblies, rigid_subassemblies = get_subassemblies(assembly, client, instances) | ||
parts = get_parts(assembly, rigid_subassemblies, client, instances) | ||
|
||
mates, relations = get_mates_and_relations(assembly, subassemblies, rigid_subassemblies, id_to_name_map, parts) | ||
|
||
graph, root_node = create_graph(occurrences=occurrences, instances=instances, parts=parts, mates=mates) | ||
plot_graph(graph, "bike.png") | ||
graph, root_node = create_graph(occurrences=occurrences, instances=instances, parts=parts, mates=mates) | ||
plot_graph(graph, "bike.png") | ||
|
||
links, joints = get_urdf_components(assembly, graph, root_node, parts, mates, relations, client) | ||
robot = Robot(name="bike", links=links, joints=joints) | ||
robot.save("bike.urdf") | ||
links, joints, assets = get_urdf_components(assembly, graph, root_node, parts, mates, relations, client) | ||
robot = Robot(name="bike", links=links, joints=joints, assets=assets) | ||
robot.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.